diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e92f57 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +tags diff --git a/README.md b/README.md index 6db1f95..faa0b78 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ -# logrotate vim plugin +# vim-logrotate -Syntax and help for logrotate config files +Syntax and help for logrotate config files in /etc/logrotate.d/* + +# Install + + mkdir -p ~/.vim/pack/gitpacks/start/ + git clone https://github.com/balki/vim-logrotate + vim +":helptags ALL" +"qa" + +# Requirements + +1. Vim installation that includes patch-8.2.4770. (Works in Ubuntu 22.10) +2. [gawk](https://www.gnu.org/software/gawk/manual/gawk.html) installed. See `g:logrotate_awk` config option to use a different awk diff --git a/doc/vim-logrotate.txt b/doc/vim-logrotate.txt new file mode 100644 index 0000000..25c7a56 --- /dev/null +++ b/doc/vim-logrotate.txt @@ -0,0 +1,52 @@ +*vim-logrotate.txt* Syntax and help plugin for logrotate files +*vim-logrotate* + +============================================================================== + +CONTENTS *vim-logrotate-contents* + + Features |vim-logrotate-features| + LogRotateHelp |:LogRotateHelp| + g:logrotate_awk |g:logrotate_awk| + + +============================================================================== + +Features *vim-logrotate-features* + +1. Detect and enable syntax-highlighting for logrotate files +2. Sets 'omnifunc' to complete logrotate directives +3. Sets 'keywordprg' to show help for logrotate directives + + +:LogRotateHelp {directive} *:LogRotateHelp* + +Shows the help for the directive in a popup window at cursor. Help text is +extracted from the logrotate manual page (man logrotate). + +`:LogRotateHelp` is only enabled if + +1. Vim installation includes patch-8.2.4770 +2. An "awk" command is available that supports ranges in regular expression. +(like "\d{1,4}"). Set |g:logrotate_awk| to use a different awk command. + +'keywordprg' is set so |K| works on directives. A different mapping can be set +as shown below > + nmap k :exe ':LogRotateHelp ' .. expand("") +< + + +g:logrotate_awk *g:logrotate_awk* + Type: |String| + Default: "gawk" + + Set a different awk command to parse man page. + E.g. "goawk" (https://github.com/benhoyt/goawk) + + Set to "disable" to disable help feature + + Example: > + let g:logrotate_awk = "goawk" +< + + vim: ft=help tw=78 et ts=2 sw=2 sts=2 norl diff --git a/ftplugin/logrotate.vim b/ftplugin/logrotate.vim index a54632d..bdb1293 100644 --- a/ftplugin/logrotate.vim +++ b/ftplugin/logrotate.vim @@ -18,10 +18,10 @@ else awkcmd = "gawk" endif -if awkcmd != "disable" && executable(awkcmd) +if has("patch-8.2.4770") && awkcmd != "disable" && executable(awkcmd) - command -nargs=1 LogRotateHelpCmd :call g:logrotate#LogrotateHelp(awkcmd, ) - setlocal keywordprg=:LogRotateHelpCmd + command -nargs=1 LogRotateHelp :call g:logrotate#LogrotateHelp(awkcmd, ) + setlocal keywordprg=:LogRotateHelp b:undo_ftplugin = b:undo_ftplugin .. " keywordprg<" endif diff --git a/syntax/logrotate.vim b/syntax/logrotate.vim index cf12f40..754452f 100644 --- a/syntax/logrotate.vim +++ b/syntax/logrotate.vim @@ -17,7 +17,7 @@ syntax region logRotateScript matchgroup=logRotateKeyword start="\s*\<\%(firstac " for comments, todo, string runtime! syntax/conf.vim -syntax keyword logRotateKeyword addextension allowhardlink compress compresscmd +syntax keyword logRotateKeyword addextension allowhardlink compress compresscmd \ compressext compressoptions copy copytruncate create createolddir \ daily dateext dateformat datehourago dateyesterday delaycompress \ endscript extension firstaction hourly ifempty include lastaction