From e0c2e50db6ad7d48407dd41fda0aa7bbd0eed646 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 22 Nov 2018 18:49:18 +1300 Subject: Add hostconf Vim filetype detection for hosts(5) --- vim/filetype.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vim/filetype.vim b/vim/filetype.vim index 541976f4..9e1773a0 100644 --- a/vim/filetype.vim +++ b/vim/filetype.vim @@ -186,6 +186,10 @@ augroup filetypedetect \ ?*.html \,?*.htm \ setfiletype html + " hosts(5) file + autocmd BufNewFile,BufRead + \ /etc/hosts + \ setfiletype hostconf " inittab(5) files autocmd BufNewFile,BufRead \ inittab -- cgit v1.2.3 From c11ba5d45da506d60cf115f72f2cedcbfe7a3279 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 22 Nov 2018 18:49:46 +1300 Subject: Add resolv.conf Vim filetype detection --- vim/filetype.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vim/filetype.vim b/vim/filetype.vim index 9e1773a0..7b4a5015 100644 --- a/vim/filetype.vim +++ b/vim/filetype.vim @@ -324,6 +324,10 @@ augroup filetypedetect \,?*.rem \,?*.remind \ setfiletype remind + " resolv.conf files + autocmd BufNewFile,BufRead + \ resolv.conf + \ setfiletype resolv " robots.txt files autocmd BufNewFile,BufRead \ robots.txt -- cgit v1.2.3 From 5c507d3e27133e3e3e7ad7a6e6d73a0be00c8cd5 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 22 Nov 2018 18:50:56 +1300 Subject: Make more of an effort with sudoedit(8) strips Handle both kinds of templated temporary files produced by sudoedit(8): * /var/tmp/foo.XXXXXXXX * /var/tmp/fooXXXXXXXX.bar This means that editing /etc/resolv.conf now highlights correctly, having also in this commit moved the sudo detection to *before* the .conf fallback. The hardcoded temporary path for finding the files probably needs to be either determined at runtime or made configurable by the user. --- vim/filetype.vim | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/vim/filetype.vim b/vim/filetype.vim index 7b4a5015..4f3839ef 100644 --- a/vim/filetype.vim +++ b/vim/filetype.vim @@ -42,6 +42,41 @@ function! s:StripRepeat() endfunction +" Helper function to run the 'filetypedetect' group on a file in a temporary +" sudoedit(8) directory, modifying it with an attempt to reverse the temporary +" filename change +function! s:SudoRepeat() + + " Check we have the fnameescape() function + if !exists('*fnameescape') + return + endif + + " Expand the match result + let l:fn = expand('') + + " myfileXXQGS16A.conf: strip eight chars before final period + if l:fn =~# '/[^./]\+\w\{8}\.[^./]\+$' + let l:fr = expand(':r') + let l:fe = expand(':e') + let l:fn = strpart(l:fr, -8, strlen(l:fr)) . '.' . l:fe + + " myfile.XXQGS16A: strip extension + elseif l:fn =~# '/[^./]\+\.\w\{8}$' + let l:fn = expand(':r') + + " Unrecognised pattern; return, don't repeat + else + return + endif + + " Re-run the group if there's anything left + if strlen(l:fn) + execute 'doautocmd filetypedetect BufRead ' . fnameescape(l:fn) + endif + +endfunction + " Check whether the first line was changed and looks like a shebang, and if " so, re-run filetype detection function! s:CheckShebang() @@ -493,6 +528,15 @@ augroup filetypedetect " Load any extra rules in ftdetect directories runtime! ftdetect/*.vim + " Clumsy attempt at typing files in `sudo -e` if a filename hasn't already + " been found + autocmd BufNewFile,BufRead + \ /var/tmp/?*????????.* + \,/var/tmp/?*.???????? + \ if !did_filetype() + \| call s:SudoRepeat() + \|endif + " Generic text, config, and log files, if no type assigned yet autocmd BufNewFile,BufRead \ ?*.text @@ -513,14 +557,6 @@ augroup filetypedetect \,?*.log \ setfiletype messages - " Clumsy attempt at typing files in `sudo -e` if a filename hasn't already - " been found; strip temporary extension and re-run - autocmd BufNewFile,BufRead - \ /var/tmp/?*.???????? - \ if !did_filetype() - \| call s:StripRepeat() - \|endif - " If we still don't have a filetype, run the scripts.vim file that performs " cleverer checks including looking at actual file contents--but only my " custom one; don't load the system one at all. -- cgit v1.2.3 From 470402b4f5dd87a9a36365eedabadad9d5fee5aa Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 22 Nov 2018 18:58:20 +1300 Subject: Bump VERSION --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 3e345d04..c68a6ccc 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v1.72.0 -Wed Nov 21 09:57:27 UTC 2018 +tejr dotfiles v1.73.0 +Thu Nov 22 05:58:20 UTC 2018 -- cgit v1.2.3