Просмотр исходного кода

Add external file updater

Re-fetches copies of files from other repositories' master branches.
Also keeps track of static files that do not need updating but
nonetheless come from external sources.
Weiyi Lou 10 лет назад
Родитель
Сommit
dc0e1f63bc
3 измененных файлов с 97 добавлено и 17 удалено
  1. 57 0
      bin/dotfiles-upgrade
  2. 1 3
      git/globalignore
  3. 39 14
      vim/autoload/plug.vim

+ 57 - 0
bin/dotfiles-upgrade

@@ -0,0 +1,57 @@
+#!/usr/bin/env bash
+set -euo pipefail
+IFS=$'\n\t'
+
+# Update files that have been commited to dotfiles
+#
+# Many additions to these dotfiles are copied straight from external sources.
+# One might say that it would be easier to clone submodules. We do not do this:
+#
+# - That would be a lot of unnecessarily heavy submodules.
+# - The files are often small utilities, and do not really need frequent
+#   updating.
+#
+# This script keeps a track of these kinds of files, and performs re-downloading
+# of their (hopefully) latest versions.
+
+echo "Downloading files from external sources:"
+
+# No need to update. Here for reference.
+#echo "ack"
+#curl -# http://beyondgrep.com/ack-2.14-single-file \
+  #-o ~/dotfiles/bin/ack && chmod 0755 ~/dotfiles/bin/ack
+
+# No need to update. Here for reference.
+#echo "gitignore"
+#curl -# https://gist.githubusercontent.com/octocat/9257657/raw/3f9569e65df83a7b328b39a091f0ce9c6efc6429/.gitignore \
+  #-o ~/dotfiles/git/globalignore
+
+echo "tmuxinator completion for bash"
+curl -# https://raw.githubusercontent.com/tmuxinator/tmuxinator/master/completion/tmuxinator.bash \
+  -o ~/dotfiles/shell/bash/tmuxinator.bash
+
+echo "tmuxinator completion for zsh"
+curl -# https://raw.githubusercontent.com/tmuxinator/tmuxinator/master/completion/tmuxinator.zsh \
+  -o ~/dotfiles/shell/zsh/completions/_tmuxinator
+
+echo "tmux colours - solarized 256"
+curl -# https://raw.githubusercontent.com/seebi/tmux-colors-solarized/master/tmuxcolors-256.conf \
+  -o ~/dotfiles/tmux/tmuxcolors-256.conf
+
+echo "z"
+curl -# https://raw.githubusercontent.com/rupa/z/master/z.sh \
+  -o ~/dotfiles/shell/common/z.sh
+curl -# https://raw.githubusercontent.com/rupa/z/master/z.1 \
+  -o ~/dotfiles/shell/man/man1/z.1
+
+echo "v"
+curl -# https://raw.githubusercontent.com/rupa/v/master/v \
+  -o ~/dotfiles/bin/v && chmod 0755 ~/dotfiles/bin/v
+curl -# https://raw.githubusercontent.com/rupa/v/master/v.1 \
+  -o ~/dotfiles/shell/man/man1/v.1
+
+echo "vim-plug"
+vim +PlugUpgrade +quitall!
+
+echo "submodules"
+git submodule foreach git pull origin master

+ 1 - 3
git/globalignore

@@ -1,5 +1,3 @@
-# https://gist.github.com/octocat/9257657
-
 # Compiled source #
 ###################
 *.com
@@ -36,4 +34,4 @@
 .Spotlight-V100
 .Trashes
 ehthumbs.db
-Thumbs.db
+Thumbs.db

+ 39 - 14
vim/autoload/plug.vim

@@ -149,12 +149,19 @@ function! s:to_s(v)
   return type(a:v) == s:TYPE.string ? a:v : join(a:v, "\n") . "\n"
 endfunction
 
+function! s:glob(from, pattern)
+  return s:lines(globpath(a:from, a:pattern))
+endfunction
+
 function! s:source(from, ...)
+  let found = 0
   for pattern in a:000
-    for vim in s:lines(globpath(a:from, pattern))
+    for vim in s:glob(a:from, pattern)
       execute 'source' s:esc(vim)
+      let found = 1
     endfor
   endfor
+  return found
 endfunction
 
 function! s:assoc(dict, key, val)
@@ -248,7 +255,9 @@ function! plug#end()
   call s:reorg_rtp()
   filetype plugin indent on
   if has('vim_starting')
-    syntax enable
+    if has('syntax') && !exists('g:syntax_on')
+      syntax enable
+    end
   else
     call s:reload()
   endif
@@ -279,8 +288,9 @@ function! s:version_requirement(val, min)
 endfunction
 
 function! s:git_version_requirement(...)
-  let s:git_version = get(s:, 'git_version',
-    \ map(split(split(s:system('git --version'))[-1], '\.'), 'str2nr(v:val)'))
+  if !exists('s:git_version')
+    let s:git_version = map(split(split(s:system('git --version'))[-1], '\.'), 'str2nr(v:val)')
+  endif
   return s:version_requirement(s:git_version, a:000)
 endfunction
 
@@ -423,9 +433,12 @@ function! s:lod(names, types, ...)
     for dir in a:types
       call s:source(rtp, dir.'/**/*.vim')
     endfor
-    for file in a:000
-      call s:source(rtp, file)
-    endfor
+    if a:0
+      if !s:source(rtp, a:1) && !empty(s:glob(rtp, a:2))
+        execute 'runtime' a:1
+      endif
+      call s:source(rtp, a:2)
+    endif
     if exists('#User#'.name)
       execute 'doautocmd User' name
     endif
@@ -554,8 +567,10 @@ function! s:syntax()
   syn match plugTag /(tag: [^)]\+)/
   syn match plugInstall /\(^+ \)\@<=[^:]*/
   syn match plugUpdate /\(^* \)\@<=[^:]*/
-  syn match plugCommit /^  [0-9a-z]\{7} .*/ contains=plugRelDate,plugSha,plugTag
-  syn match plugSha /\(^  \)\@<=[0-9a-z]\{7}/ contained
+  syn match plugCommit /^  \X*[0-9a-z]\{7} .*/ contains=plugRelDate,plugEdge,plugTag
+  syn match plugEdge /^  \X\+$/
+  syn match plugEdge /^  \X*/ contained nextgroup=plugSha
+  syn match plugSha /[0-9a-z]\{7}/ contained
   syn match plugRelDate /([^)]*)$/ contained
   syn match plugNotLoaded /(not loaded)$/
   syn match plugError /^x.*/
@@ -579,6 +594,7 @@ function! s:syntax()
 
   hi def link plugError   Error
   hi def link plugRelDate Comment
+  hi def link plugEdge    PreProc
   hi def link plugSha     Identifier
   hi def link plugTag     Constant
 
@@ -650,6 +666,10 @@ function! s:finish_bindings()
 endfunction
 
 function! s:prepare(...)
+  if empty(getcwd())
+    throw 'Invalid current working directory. Cannot proceed.'
+  endif
+
   call s:job_abort()
   if s:switch_in()
     normal q
@@ -1726,7 +1746,7 @@ function! s:shellesc(arg)
 endfunction
 
 function! s:glob_dir(path)
-  return map(filter(s:lines(globpath(a:path, '**')), 'isdirectory(v:val)'), 's:dirpath(v:val)')
+  return map(filter(s:glob(a:path, '**'), 'isdirectory(v:val)'), 's:dirpath(v:val)')
 endfunction
 
 function! s:progress_bar(line, bar, total)
@@ -2003,7 +2023,7 @@ function! s:preview_commit()
     let b:plug_preview = !s:is_preview_window_open()
   endif
 
-  let sha = matchstr(getline('.'), '\(^  \)\@<=[0-9a-z]\{7}')
+  let sha = matchstr(getline('.'), '^  \X*\zs[0-9a-z]\{7}')
   if empty(sha)
     return
   endif
@@ -2028,10 +2048,15 @@ function! s:section(flags)
 endfunction
 
 function! s:format_git_log(line)
-  let [sha, refs, subject, date] = split(a:line, nr2char(1))
+  let indent = '  '
+  let tokens = split(a:line, nr2char(1))
+  if len(tokens) != 5
+    return indent.substitute(a:line, '\s*$', '', '')
+  endif
+  let [graph, sha, refs, subject, date] = tokens
   let tag = matchstr(refs, 'tag: [^,)]\+')
   let tag = empty(tag) ? ' ' : ' ('.tag.') '
-  return printf('  %s%s%s (%s)', sha, tag, subject, date)
+  return printf('%s%s%s%s%s (%s)', indent, graph, sha, tag, subject, date)
 endfunction
 
 function! s:append_ul(lnum, text)
@@ -2053,7 +2078,7 @@ function! s:diff()
     call s:append_ul(2, origin ? 'Pending updates:' : 'Last update:')
     for [k, v] in plugs
       let range = origin ? '..origin/'.v.branch : 'HEAD@{1}..'
-      let diff = s:system_chomp('git log --pretty=format:"%h%x01%d%x01%s%x01%cr" '.s:shellesc(range), v.dir)
+      let diff = s:system_chomp('git log --graph --color=never --pretty=format:"%x01%h%x01%d%x01%s%x01%cr" '.s:shellesc(range), v.dir)
       if !empty(diff)
         let ref = has_key(v, 'tag') ? (' (tag: '.v.tag.')') : has_key(v, 'commit') ? (' '.v.commit) : ''
         call append(5, extend(['', '- '.k.':'.ref], map(s:lines(diff), 's:format_git_log(v:val)')))