Bladeren bron

Add coloured manpages to external files, Add misc.sh

We also rename `directories.sh` to `ls.sh`, change more comments, and
update vim-plug.
Weiyi Lou 9 jaren geleden
bovenliggende
commit
fa7326e782

+ 4 - 0
bin/dotfiles-upgrade

@@ -50,6 +50,10 @@ curl -# https://raw.githubusercontent.com/rupa/v/master/v \
 curl -# https://raw.githubusercontent.com/rupa/v/master/v.1 \
   -o ~/dotfiles/shell/man/man1/v.1
 
+echo "coloured manpages"
+curl -# https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/plugins/colored-man-pages/colored-man-pages.plugin.zsh \
+  -o ~/dotfiles/shell/common/coloured-man-pages.sh
+
 echo "vim-plug"
 vim +PlugUpgrade +quitall!
 

+ 0 - 3
shell/common/auto-ssh-hosts.sh

@@ -13,6 +13,3 @@ auto_ssh_hosts() {
 if [[ -f ~/.ssh/known_hosts ]]; then
   auto_ssh_hosts
 fi
-
-# Hosts file
-alias hosts='sudo vim /etc/hosts'

+ 20 - 21
shell/common/coloured-man-pages.sh

@@ -1,33 +1,32 @@
-# From oh-my-zsh
 if [[ "$OSTYPE" = solaris* ]]
 then
-  if [[ ! -x "$HOME/bin/nroff" ]]
-  then
-    mkdir -p "$HOME/bin"
-    cat > "$HOME/bin/nroff" <<EOF
+	if [[ ! -x "$HOME/bin/nroff" ]]
+	then
+		mkdir -p "$HOME/bin"
+		cat > "$HOME/bin/nroff" <<EOF
 #!/bin/sh
 if [ -n "\$_NROFF_U" -a "\$1,\$2,\$3" = "-u0,-Tlp,-man" ]; then
-  shift
-  exec /usr/bin/nroff -u\$_NROFF_U "\$@"
+	shift
+	exec /usr/bin/nroff -u\$_NROFF_U "\$@"
 fi
 #-- Some other invocation of nroff
 exec /usr/bin/nroff "\$@"
 EOF
-    chmod +x "$HOME/bin/nroff"
-  fi
+		chmod +x "$HOME/bin/nroff"
+	fi
 fi
 
 man() {
-  env \
-    LESS_TERMCAP_mb=$(printf "\e[1;31m") \
-    LESS_TERMCAP_md=$(printf "\e[1;31m") \
-    LESS_TERMCAP_me=$(printf "\e[0m") \
-    LESS_TERMCAP_se=$(printf "\e[0m") \
-    LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
-    LESS_TERMCAP_ue=$(printf "\e[0m") \
-    LESS_TERMCAP_us=$(printf "\e[1;32m") \
-    PAGER="${commands[less]:-$PAGER}" \
-    _NROFF_U=1 \
-    PATH="$HOME/bin:$PATH" \
-      man "$@"
+	env \
+		LESS_TERMCAP_mb=$(printf "\e[1;31m") \
+		LESS_TERMCAP_md=$(printf "\e[1;31m") \
+		LESS_TERMCAP_me=$(printf "\e[0m") \
+		LESS_TERMCAP_se=$(printf "\e[0m") \
+		LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
+		LESS_TERMCAP_ue=$(printf "\e[0m") \
+		LESS_TERMCAP_us=$(printf "\e[1;32m") \
+		PAGER="${commands[less]:-$PAGER}" \
+		_NROFF_U=1 \
+		PATH="$HOME/bin:$PATH" \
+			man "$@"
 }

+ 3 - 3
shell/common/git-prompt.sh

@@ -38,7 +38,7 @@ function __gitp() {
   [[ $bare = 'true' ]] && bare=${GITP_BARE:-"$cRed BARE"} || bare=''
   local location="$(__gitp_location $commit)"
   if [[ $worktree = 'true' && -z $GITP_SIMPLE ]]; then
-    # Many things only matter if in a work tree (i.e. not bare, not in gitdir).
+    # Many things only matter if in a work tree (i.e. not bare or in gitdir).
     __gitp_status
     local op="$(__gitp_op $gitdir)"
     local remote="$(__gitp_remote)"
@@ -58,7 +58,7 @@ function __gitp() {
 function __gitp_status() {
   GITP_STATUS=''
 
-  # Ignore work tree changes in submodules to speed up prompt rendering.
+  # If available, ignore submodule work tree changes to speed up prompt.
   GITP_STATUS=$(git status --porcelain --ignore-submodules=dirty 2>/dev/null) \
     || GITP_STATUS=$(git status --porcelain)
 }
@@ -170,7 +170,7 @@ function __gitp_wips() {
 # indicated by `GITP_CHANGES_MAX`. Gives a good visual of what has changed.
 #
 # Performance note: if the git prompt is slow, it is more because `git status`
-# is slow. Change-string building is near-instantaneous since it is just string
+# is slow. This function is near-instantaneous since it is just string
 # manipulation.
 function __gitp_changes() {
   [[ -z $GITP_STATUS ]] && return

+ 1 - 0
shell/common/less.sh

@@ -2,6 +2,7 @@
 # e = quit at end of file
 # i = searches ignore case, unless there are upper case characters
 # r = display raw control characters (Ctrl-A is ^A)
+# R = display raw ANSI colour escape sequences `^[[...m`
 # M = verbose `less` prompt
 # X = disable termcap init/deinit strings - sometimes these clear the screen.
 export LESS='-iRMX'

+ 0 - 3
shell/common/directories.sh → shell/common/ls.sh

@@ -11,6 +11,3 @@ alias l='ls'
 alias la='ls -A'
 alias ll='ls -lh'
 alias lal='ls -Alh'
-
-# Common places
-alias cd.='cd ~/dotfiles'

+ 5 - 0
shell/common/misc.sh

@@ -0,0 +1,5 @@
+# Common places
+alias cd.='cd ~/dotfiles'
+
+# Hosts file
+alias hosts='sudo vim /etc/hosts'

+ 34 - 21
vim/autoload/plug.vim

@@ -337,7 +337,12 @@ function! s:err(msg)
   echohl ErrorMsg
   echom '[vim-plug] '.a:msg
   echohl None
-  return 0
+endfunction
+
+function! s:warn(cmd, msg)
+  echohl WarningMsg
+  execute a:cmd 'a:msg'
+  echohl None
 endfunction
 
 function! s:esc(path)
@@ -386,6 +391,10 @@ function! s:reorg_rtp()
   endif
 endfunction
 
+function! s:doautocmd(...)
+  execute 'doautocmd' ((v:version > 703 || has('patch442')) ? '<nomodeline>' : '') join(a:000)
+endfunction
+
 function! plug#load(...)
   if a:0 == 0
     return s:err('Argument missing: plugin name(s) required')
@@ -440,7 +449,7 @@ function! s:lod(names, types, ...)
       call s:source(rtp, a:2)
     endif
     if exists('#User#'.name)
-      execute 'doautocmd User' name
+      call s:doautocmd('User', name)
     endif
   endfor
 endfunction
@@ -656,7 +665,7 @@ function! s:switch_out(...)
 endfunction
 
 function! s:finish_bindings()
-  nnoremap <silent> <buffer> R  :silent! call <SID>retry()<cr>
+  nnoremap <silent> <buffer> R  :call <SID>retry()<cr>
   nnoremap <silent> <buffer> D  :PlugDiff<cr>
   nnoremap <silent> <buffer> S  :PlugStatus<cr>
   nnoremap <silent> <buffer> U  :call <SID>status_update()<cr>
@@ -726,8 +735,8 @@ function! s:regress_bar()
   call s:progress_bar(2, bar, len(bar))
 endfunction
 
-function! s:is_updated(file, dir)
-  return !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}" '.a:file, a:dir))
+function! s:is_updated(dir)
+  return !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"', a:dir))
 endfunction
 
 function! s:do(pull, force, todo)
@@ -737,7 +746,7 @@ function! s:do(pull, force, todo)
     endif
     let installed = has_key(s:update.new, name)
     let updated = installed ? 0 :
-      \ (a:pull && index(s:update.errors, name) < 0 && s:is_updated('', spec.dir))
+      \ (a:pull && index(s:update.errors, name) < 0 && s:is_updated(spec.dir))
     if a:force || installed || updated
       execute 'cd' s:esc(spec.dir)
       call append(3, '- Post-update hook for '. name .' ... ')
@@ -808,6 +817,7 @@ function! s:retry()
   if empty(s:update.errors)
     return
   endif
+  echo
   call s:update_impl(s:update.pull, s:update.force,
         \ extend(copy(s:update.errors), [s:update.threads]))
 endfunction
@@ -820,6 +830,16 @@ function! s:names(...)
   return sort(filter(keys(g:plugs), 'stridx(v:val, a:1) == 0 && s:is_managed(v:val)'))
 endfunction
 
+function! s:check_ruby()
+  silent! ruby require 'thread'; VIM::command('let g:plug_ruby = 1')
+  if get(g:, 'plug_ruby', 0)
+    unlet g:plug_ruby
+    return 1
+  endif
+  redraw!
+  return s:warn('echom', 'Warning: Ruby interface is broken')
+endfunction
+
 function! s:update_impl(pull, force, args) abort
   let args = copy(a:args)
   let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ?
@@ -830,10 +850,7 @@ function! s:update_impl(pull, force, args) abort
                          \ filter(managed, 'index(args, v:key) >= 0')
 
   if empty(todo)
-    echohl WarningMsg
-    echo 'No plugin to '. (a:pull ? 'update' : 'install') . '.'
-    echohl None
-    return
+    return s:warn('echo', 'No plugin to '. (a:pull ? 'update' : 'install'))
   endif
 
   if !s:is_win && s:git_version_requirement(2, 3)
@@ -855,13 +872,11 @@ function! s:update_impl(pull, force, args) abort
   endif
 
   if has('nvim') && !exists('*jobwait') && threads > 1
-    echohl WarningMsg
-    echomsg 'vim-plug: update Neovim for parallel installer'
-    echohl None
+    call s:warn('echom', '[vim-plug] Update Neovim for parallel installer')
   endif
 
   let python = (has('python') || has('python3')) && (!s:nvim || has('vim_starting'))
-  let ruby = has('ruby') && !s:nvim && (v:version >= 703 || v:version == 702 && has('patch374')) && !(s:is_win && has('gui_running'))
+  let ruby = has('ruby') && !s:nvim && (v:version >= 703 || v:version == 702 && has('patch374')) && !(s:is_win && has('gui_running')) && s:check_ruby()
 
   let s:update = {
     \ 'start':   reltime(),
@@ -958,7 +973,7 @@ function! s:update_finish()
               \. (has_key(s:update.new, name) ? '' : ('&& git merge --ff-only origin/'.branch.' 2>&1')), spec.dir)
       endif
       if !v:shell_error && filereadable(spec.dir.'/.gitmodules') &&
-            \ (has_key(s:update.new, name) || s:is_updated('.gitmodules', spec.dir))
+            \ (has_key(s:update.new, name) || s:is_updated(spec.dir))
         call s:log4(name, 'Updating submodules. This may take a while.')
         let out .= s:bang('git submodule update --init --recursive 2>&1', spec.dir)
       endif
@@ -1084,7 +1099,6 @@ function! s:logpos(name)
       return i
     endif
   endfor
-  return 0
 endfunction
 
 function! s:log(bullet, name, lines)
@@ -1420,7 +1434,7 @@ class Plugin(object):
     self.write(Action.DONE, self.name, result[-1:])
 
   def repo_uri(self):
-    cmd = 'git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url'
+    cmd = 'git rev-parse --abbrev-ref HEAD 2>&1 && git config -f .git/config remote.origin.url'
     command = Command(cmd, self.args['dir'], G_TIMEOUT,)
     result = command.execute(G_RETRIES)
     return result[-1]
@@ -1721,7 +1735,7 @@ function! s:update_ruby()
           ok, result =
             if exists
               chdir = "#{cd} #{iswin ? dir : esc(dir)}"
-              ret, data = bt.call "#{chdir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url", nil, nil, nil
+              ret, data = bt.call "#{chdir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config -f .git/config remote.origin.url", nil, nil, nil
               current_uri = data.lines.to_a.last
               if !ret
                 if data =~ /^Interrupted|^Timeout/
@@ -1814,7 +1828,7 @@ endfunction
 function! s:git_validate(spec, check_branch)
   let err = ''
   if isdirectory(a:spec.dir)
-    let result = s:lines(s:system('git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url', a:spec.dir))
+    let result = s:lines(s:system('git rev-parse --abbrev-ref HEAD 2>&1 && git config -f .git/config remote.origin.url', a:spec.dir))
     let remote = result[-1]
     if v:shell_error
       let err = join([remote, 'PlugClean required.'], "\n")
@@ -2022,7 +2036,6 @@ function! s:is_preview_window_open()
     wincmd p
     return 1
   endif
-  return 0
 endfunction
 
 function! s:find_name(lnum)
@@ -2057,7 +2070,7 @@ function! s:preview_commit()
   execute 'pedit' sha
   wincmd P
   setlocal filetype=git buftype=nofile nobuflisted modifiable
-  execute 'silent read !cd' s:shellesc(g:plugs[name].dir) '&& git show --pretty=medium' sha
+  execute 'silent read !cd' s:shellesc(g:plugs[name].dir) '&& git show --no-color --pretty=medium' sha
   normal! gg"_dd
   setlocal nomodifiable
   nnoremap <silent> <buffer> q :q<cr>