commit 9c5d746ec4c61c51b6ede4e56284ddba20f4a150 Author: Balakrishnan Balasubramanian Date: Wed Oct 26 21:57:54 2022 -0400 initial version diff --git a/README.md b/README.md new file mode 100644 index 0000000..6db1f95 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# logrotate vim plugin + +Syntax and help for logrotate config files diff --git a/ftdetect/logrotate.vim b/ftdetect/logrotate.vim new file mode 100644 index 0000000..33b9594 --- /dev/null +++ b/ftdetect/logrotate.vim @@ -0,0 +1,3 @@ + +au BufNewFile,BufRead */logrotate.d/*,logrotate.conf setfiletype logrotate + diff --git a/ftplugin/logrotate.vim b/ftplugin/logrotate.vim new file mode 100644 index 0000000..899e3a6 --- /dev/null +++ b/ftplugin/logrotate.vim @@ -0,0 +1,32 @@ +vim9script +# Vim filetype plugin file +# Language: confini +# +if exists("b:did_ftplugin") + finish +endif +b:did_ftplugin = 1 + +def LogrotateHelp(msg: string = expand("")) + const searchcmd =<< trim END + COLUMNS=80 man logrotate 2>/dev/null | + gawk '/^CONFIGURATION FILE DIRECTIVES/,/^SCRIPTS/' | gawk ' + /^ {7}%s/,/^[a-z]/ { + if(firstLineDone) { + if(/^ {7}[^ ]/ || /^[A-Z]/) + exit + } + firstLineDone = 1 + print(substr($0, 8)) + }' + END + printf(join(searchcmd, "\n"), expand("")) + ->systemlist() + ->popup_atcursor({ "padding": [0, 1, 1, 1] }) +enddef + +command -nargs=1 LogRt :call LogrotateHelp() + +b:undo_ftplugin = "setlocal commentstring< formatoptions< keywordprg<" + +setlocal commentstring=#\ %s formatoptions-=t formatoptions+=croql keywordprg=:LogRt diff --git a/syntax/logrotate.vim b/syntax/logrotate.vim new file mode 100644 index 0000000..ad2950d --- /dev/null +++ b/syntax/logrotate.vim @@ -0,0 +1,37 @@ +" Vim syntax file +" Language: logrotate + +" Quit if a syntax file was already loaded +if exists("b:current_syntax") + finish +endif + +runtime! syntax/conf.vim + +" syn keyword logRotateTodo contained TODO FIXME XXX + +syn 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 + \ mail mailfirst maillast maxage maxsize minage minsize missingok + \ monthly noallowhardlink nocompress nocopy nocopytruncate nocreate + \ nocreateolddir nodateext nodelaycompress nomail nomissingok + \ noolddir norenamecopy nosharedscripts noshred notifempty olddir + \ postrotate preremove prerotate renamecopy rotate sharedscripts + \ shred shredcycles size start su tabooext taboopat uncompresscmd + \ weekly yearly + +" String +" syn region logRotateString start=+"+ skip=+\\\\\|\\"+ end=+"+ oneline +" syn region logRotateString start=+'+ skip=+\\\\\|\\'+ end=+'+ oneline + +" syn match logRotateComment "^#.*" contains=logRotateTodo,logRotateString,@Spell +" syn match logRotateComment "\s#.*"ms=s+1 contains=logRotateTodo,logRotateString,@Spell + +hi def link logRotateKeyword Keyword +" hi def link logRotateString String +" hi def link logRotateComment Comment +" hi def link logRotateTodo Todo + +let b:current_syntax = 'logrotate'