diff options
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | VERSION | 4 | ||||
-rw-r--r-- | bin/d2u.sh | 2 | ||||
-rw-r--r-- | bin/sd2u.awk | 6 | ||||
-rw-r--r-- | bin/su2d.awk | 6 | ||||
-rw-r--r-- | bin/u2d.sh | 3 | ||||
-rw-r--r-- | man/man1/d2u.1df | 2 | ||||
-rw-r--r-- | man/man1/sd2u.1df | 2 | ||||
-rw-r--r-- | man/man1/su2d.1df | 2 | ||||
-rw-r--r-- | man/man1/u2d.1df | 2 | ||||
-rw-r--r-- | tidy/profile.d/tidy.sh | 3 | ||||
-rw-r--r-- | tidy/tidyrc | 20 | ||||
-rw-r--r-- | vim/config/leader.vim | 5 | ||||
-rw-r--r-- | vim/config/list.vim | 2 | ||||
-rw-r--r-- | vim/config/netrw.vim | 21 | ||||
-rw-r--r-- | vim/config/number.vim | 2 | ||||
-rw-r--r-- | vim/config/search.vim | 8 | ||||
-rw-r--r-- | vim/config/spell.vim | 6 | ||||
-rw-r--r-- | vim/config/wrap.vim | 2 | ||||
-rw-r--r-- | vim/ftplugin/html.vim | 24 | ||||
-rw-r--r-- | vim/ftplugin/perl.vim | 17 | ||||
-rw-r--r-- | vim/ftplugin/sh.vim | 22 | ||||
-rw-r--r-- | vim/ftplugin/vim.vim | 5 |
24 files changed, 134 insertions, 46 deletions
@@ -34,6 +34,7 @@ install-sh \ install-subversion \ install-terminfo \ + install-tidy \ install-tmux \ install-urxvt \ install-vim \ @@ -464,6 +465,10 @@ install-terminfo: find terminfo -type f -name '*.info' \ -exec tic -- {} \; +install-tidy: install-sh + cp -p -- tidy/profile.d/* $(HOME)/.profile.d + cp -p -- tidy/tidyrc $(HOME)/.tidyrc + install-tmux: tmux/tmux.conf install-terminfo cp -p -- tmux/tmux.conf $(HOME)/.tmux.conf @@ -93,6 +93,7 @@ Configuration is included for: the rxvt terminal emulator with Unicode support * [Subversion](https://subversion.apache.org/) -- Apache Subversion, a version control system +* [tidy](http://www.html-tidy.org/) -- HTML/XHTML linter and tidier * [tmux](https://tmux.github.io/) -- Terminal multiplexer similar to GNU Screen * [Vim](http://www.vim.org/) -- Vi IMproved, a text editor @@ -342,8 +343,12 @@ The configuration is broken into subfiles in `~/.vim/config/*.vim`, included by extensively commented, mostly because I was reading through it one day and realised I'd forgotten what half of it did. -Plugins are in submodules in `~/.vim/bundle`, loaded using Tim Pope's -[pathogen.vim](https://github.com/tpope/vim-pathogen). +I define a few custom per-filetype rules for stuff I often edit in +`~/.vim/ftplugin`, including some local mappings for checking, linting, and +tidying. + +Third-party plugins are in submodules in `~/.vim/bundle`, loaded using Tim +Pope's [pathogen.vim](https://github.com/tpope/vim-pathogen). Scripts ------- @@ -1,2 +1,2 @@ -tejr dotfiles v0.4.0 -Thu Nov 2 14:31:35 NZDT 2017 +tejr dotfiles v0.6.1 +Fri Nov 3 12:46:45 UTC 2017 @@ -16,7 +16,7 @@ for fn ; do # $r within it to get a literal carriage return; the escape characters # prescribed for ed(1) by POSIX are very limited ed -s -- "$fn" <<EOF || ex=1 -g/$r\$/ s/$r\$// +,s/$r\$// w EOF done diff --git a/bin/sd2u.awk b/bin/sd2u.awk index 02584952..b6e3da89 100644 --- a/bin/sd2u.awk +++ b/bin/sd2u.awk @@ -1,3 +1,3 @@ -# Convert DOS line endings to UNIX ones -{ sub(/\r$/, "") } -{ print } +# Convert stream DOS line endings to UNIX ones +BEGIN { RS = "\r\n" } +1 diff --git a/bin/su2d.awk b/bin/su2d.awk index 34a8c5ae..5a8eabaf 100644 --- a/bin/su2d.awk +++ b/bin/su2d.awk @@ -1,3 +1,3 @@ -# Convert UNIX line endings to DOS ones -!/\r$/ { $0 = $0 "\r" } -{ print } +# Convert stream UNIX line endings to DOS ones +BEGIN { ORS = "\r\n" } +1 @@ -16,8 +16,7 @@ for fn ; do # $r within it to get a literal carriage return; the escape characters # prescribed for ed(1) by POSIX are very limited ed -s -- "$fn" <<EOF || ex=1 -g/[^$r]\$/ s/\$/$r/ -g/^\$/ s/\$/$r/ +,s/\$/$r/ w EOF done diff --git a/man/man1/d2u.1df b/man/man1/d2u.1df index 18c27829..c652434c 100644 --- a/man/man1/d2u.1df +++ b/man/man1/d2u.1df @@ -6,7 +6,7 @@ .B d2u FILE1 [FILE2 ...] .SH DESCRIPTION Applies ed(1) to change DOS \\r\\n (CRLF) line endings to UNIX \\n line -endings. Files already in UNIX format should be unchanged. +endings. .SH SEE ALSO ed(1), u2d(1df), sd2u(1df), su2d(1df) .SH AUTHOR diff --git a/man/man1/sd2u.1df b/man/man1/sd2u.1df index f07ebdb9..ee00c473 100644 --- a/man/man1/sd2u.1df +++ b/man/man1/sd2u.1df @@ -13,7 +13,7 @@ program | .B sd2u .SH DESCRIPTION Applies awk(1) to change DOS \\r\\n (CRLF) line endings to UNIX \\n line -endings. Lines already in UNIX format should be unchanged. +endings. .SH SEE ALSO awk(1), su2d(1df), d2u(1df), u2d(1df) .SH AUTHOR diff --git a/man/man1/su2d.1df b/man/man1/su2d.1df index aa6a8821..22aa80bd 100644 --- a/man/man1/su2d.1df +++ b/man/man1/su2d.1df @@ -13,7 +13,7 @@ program | .B su2d .SH DESCRIPTION Applies awk(1) to change UNIX \\n line endings to DOS \\r\\n (CRLF) line -endings. Lines already in DOS format should be unchanged. +endings. .SH SEE ALSO awk(1), sd2u(1df), d2u(1df), u2d(1df) .SH AUTHOR diff --git a/man/man1/u2d.1df b/man/man1/u2d.1df index 3bb16092..9af792bf 100644 --- a/man/man1/u2d.1df +++ b/man/man1/u2d.1df @@ -6,7 +6,7 @@ .B u2d FILE1 [FILE2 ...] .SH DESCRIPTION Applies ed(1) to change UNIX \\n line endings to DOS \\r\\n (CRLF) line -endings. Files already in DOS format should be unchanged. +endings. .SH SEE ALSO ed(1), d2u(1df), sd2u(1df), su2d(1df) .SH AUTHOR diff --git a/tidy/profile.d/tidy.sh b/tidy/profile.d/tidy.sh new file mode 100644 index 00000000..177a8124 --- /dev/null +++ b/tidy/profile.d/tidy.sh @@ -0,0 +1,3 @@ +# Set a configuration file path for tidy(1) +HTML_TIDY=$HOME/.tidyrc +export HTML_TIDY diff --git a/tidy/tidyrc b/tidy/tidyrc new file mode 100644 index 00000000..65f93112 --- /dev/null +++ b/tidy/tidyrc @@ -0,0 +1,20 @@ +# UTF-8 everywhere by default +char-encoding: utf8 +input-encoding: utf8 +output-encoding: utf8 + +# Seems reasonable +drop-empty-paras: yes + +# Indent to four spaces +indent: yes +indent-spaces: 4 + +# Shut up please +quiet: yes + +# Don't mess with my <meta> +tidy-mark: no + +# Don't wrap +wrap: 0 diff --git a/vim/config/leader.vim b/vim/config/leader.vim new file mode 100644 index 00000000..e17aed06 --- /dev/null +++ b/vim/config/leader.vim @@ -0,0 +1,5 @@ +" Use different keys for global and local leaders +if has('eval') + let g:mapleader = '\' + let g:maplocalleader = '_' +endif diff --git a/vim/config/list.vim b/vim/config/list.vim index faf5e29a..209bb4ec 100644 --- a/vim/config/list.vim +++ b/vim/config/list.vim @@ -1,7 +1,7 @@ " Don't show whitespace characters or end-of-line characters visually by " default, but make \l toggle between them set nolist -nnoremap <leader>l :setlocal list! list?<CR> +nnoremap <Leader>l :setlocal list! list?<CR> " Clearly show when the start or end of the row does not correspond to the " start and end of the line diff --git a/vim/config/netrw.vim b/vim/config/netrw.vim index 528f0ca6..b38649b9 100644 --- a/vim/config/netrw.vim +++ b/vim/config/netrw.vim @@ -1,11 +1,16 @@ -" Don't show the preamble banner -let g:netrw_banner = 0 +" netrw plugin configuration +if has('eval') -" Perform file transfers silently -let g:netrw_silent = 1 + " Don't show the preamble banner + let g:netrw_banner = 0 -" Use a tree-style file listing -let g:netrw_liststyle = 3 + " Perform file transfers silently + let g:netrw_silent = 1 -" Don't list the current directory shortcut, and don't show tags files -let g:netrw_list_hide = '^\.$,^tags$' + " Use a tree-style file listing + let g:netrw_liststyle = 3 + + " Don't list the current directory shortcut, and don't show tags files + let g:netrw_list_hide = '^\.$,^tags$' + +endif diff --git a/vim/config/number.vim b/vim/config/number.vim index 35ec7efe..d7d9919c 100644 --- a/vim/config/number.vim +++ b/vim/config/number.vim @@ -1,3 +1,3 @@ " Don't show line numbers by default, but \n toggles them set nonumber -nnoremap <leader>n :setlocal number! number?<CR> +nnoremap <Leader>n :setlocal number! number?<CR> diff --git a/vim/config/search.vim b/vim/config/search.vim index 1d1039e2..0f10eea5 100644 --- a/vim/config/search.vim +++ b/vim/config/search.vim @@ -3,11 +3,11 @@ if has('extra_search') " Searching as I enter my pattern, \i toggles this set incsearch - nnoremap <leader>i :setlocal incsearch! incsearch?<CR> + nnoremap <Leader>i :setlocal incsearch! incsearch?<CR> " Highlight search results, \h toggles this set hlsearch - nnoremap <leader>h :setlocal hlsearch! hlsearch?<CR> + nnoremap <Leader>h :setlocal hlsearch! hlsearch?<CR> " Pressing ^L will clear highlighting until the next search-related " operation; quite good because the highlighting gets distracting after @@ -19,8 +19,8 @@ if has('extra_search') if has('autocmd') augroup dotfiles_highlight autocmd! - silent! autocmd InsertEnter * setlocal nohlsearch nohlsearch? - silent! autocmd InsertLeave * setlocal hlsearch hlsearch? + silent! autocmd InsertEnter * setlocal nohlsearch + silent! autocmd InsertLeave * setlocal hlsearch augroup END endif endif diff --git a/vim/config/spell.vim b/vim/config/spell.vim index 046b50ff..6a0167d0 100644 --- a/vim/config/spell.vim +++ b/vim/config/spell.vim @@ -3,12 +3,12 @@ if has('spell') " Don't check spelling by default, but bind \s to toggle this set nospell - nnoremap <leader>s :setlocal spell! spell?<CR> + nnoremap <Leader>s :setlocal spell! spell?<CR> " Use New Zealand English for spelling by default (it's almost identical " to British English), but bind \u to switch to US English and \z to " switch back set spelllang=en_nz - nnoremap <leader>u :setlocal spelllang=en_us spelllang?<CR> - nnoremap <leader>z :setlocal spelllang=en_nz spelllang?<CR> + nnoremap <Leader>u :setlocal spelllang=en_us spelllang?<CR> + nnoremap <Leader>z :setlocal spelllang=en_nz spelllang?<CR> endif diff --git a/vim/config/wrap.vim b/vim/config/wrap.vim index 8cc1473a..5da843ce 100644 --- a/vim/config/wrap.vim +++ b/vim/config/wrap.vim @@ -1,6 +1,6 @@ " Don't wrap by default, but use \w to toggle it on or off quickly set nowrap -nnoremap <leader>w :setlocal wrap! wrap?<CR> +nnoremap <Leader>w :setlocal wrap! wrap?<CR> " When wrapping text, if a line is so long that not all of it can be shown on " the screen, show as much as possible anyway; by default Vim fills the left diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index 3f28e9ea..c756eb80 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -1,11 +1,25 @@ -" Run tidy -eq -utf8 on file for the current buffer -nnoremap <leader>v :exe "!tidy -eq -utf8 " . shellescape(expand("%"))<CR> +" Run `tidy -errors -quiet` over buffer +nnoremap <buffer> <silent> <LocalLeader>c + \ :write !tidy -errors -quiet<CR> + +" Filter buffer through `tidy` +nnoremap <buffer> <silent> <LocalLeader>t + \ :%!tidy -quiet<CR> " Make a bare URL into a link to itself function! s:UrlLink() + + " Yank this whole whitespace-separated word normal! yiW - execute "normal! i<a href=\"\<C-R>0\">\<Esc>" + " Open a link tag + normal! i<a href=""> + " Paste the URL into the quotes + normal! hP + " Move to the end of the link text URL normal! E - execute "normal! a</a>\<Esc>" + " Close the link tag + normal! a</a> + endfunction -nnoremap <silent> <leader>r :<C-U>call <SID>UrlLink()<CR> +nnoremap <buffer> <silent> <LocalLeader>r + \ :<C-U>call <SID>UrlLink()<CR> diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim index dad2ce35..2ea4676b 100644 --- a/vim/ftplugin/perl.vim +++ b/vim/ftplugin/perl.vim @@ -1,6 +1,11 @@ -" Run perl -c on file for the current buffer -nnoremap <leader>pc :exe "!perl -c " . shellescape(expand("%"))<CR> -" Run perlcritic on the file for the current buffer -nnoremap <leader>pl :exe "!perlcritic " . shellescape(expand("%"))<CR> -" Run the current buffer through perltidy -nnoremap <leader>pt :%!perltidy<CR> +" Run `perl -c` over buffer +nnoremap <buffer> <silent> <LocalLeader>c + \ :write !perl -c<CR> + +" Run `perlcritic` over buffer +nnoremap <buffer> <silent> <LocalLeader>l + \ :write !perlcritic<CR> + +" Filter buffer through `perltidy` +nnoremap <buffer> <silent> <LocalLeader>t + \ :%!perltidy<CR> diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index a6dd62eb..c09e4fe8 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -24,3 +24,25 @@ endif if exists('b:is_bash') && executable('han') setlocal keywordprg=han endif + +" Map checker based on shell family +if exists('b:is_bash') && b:is_bash + let b:check = 'bash -n' +elseif exists('b:is_ksh') && b:is_ksh + let b:check = 'ksh -n' +else + let b:check = 'sh -n' +endif +nnoremap <buffer> <silent> <LocalLeader>c + \ :<C-U>execute ':write !' . b:check<CR> + +" Map linter based on shell family +if exists('b:is_bash') && b:is_bash + let b:lint = 'shellcheck -s bash -' +elseif exists('b:is_ksh') && b:is_ksh + let b:lint = 'shellcheck -s ksh -' +else + let b:lint = 'shellcheck -s sh -' +endif +nnoremap <buffer> <silent> <LocalLeader>l + \ :<C-U>execute ':write !' . b:lint<CR> diff --git a/vim/ftplugin/vim.vim b/vim/ftplugin/vim.vim new file mode 100644 index 00000000..e023553e --- /dev/null +++ b/vim/ftplugin/vim.vim @@ -0,0 +1,5 @@ +" Run `vint` over buffer +" /dev/stdin is not optimal here; it's widely implemented, but not POSIX. +" `vint` does not seem to have another way to parse standard input. +nnoremap <buffer> <silent> <LocalLeader>l + \ :write !vint -s /dev/stdin<CR> |