Sfoglia il codice sorgente

Rewrite setup script, Use vim-plug plugin manager

The setup script has now been cleaned of most of the bloat of spf13-vim, and the
vundle plugin manager has been swapped out for vim-plug - this new plugin
manager supports parallel downloading of plugins and defaults to shallow clones
(--depth 1) to achieve great speed.
Weiyi Lou 10 anni fa
parent
commit
818e217418
5 ha cambiato i file con 202 aggiunte e 339 eliminazioni
  1. 19 12
      README.md
  2. 83 219
      setup.sh
  3. 97 0
      vim/plugins.vim
  4. 3 4
      vim/vimrc
  5. 0 104
      vim/vimrc.bundles

+ 19 - 12
README.md

@@ -1,20 +1,21 @@
-# Configuration Files For *nix Environments
+# Configuration Files For Unix Environments
 
-#### Software
+This repository contains configurations mostly for comfortable command line
+usage. The following are of particular note:
 
-Software configs that exist (versions are minimums for correct operation):
 - vim 7.4
-- emacs 24
 - tmux 1.8
 - zsh
-- irssi & screen (for nicklist)
-- nethack
-- mongo
-- Vimperator 3.8
+- irssi
+- vimperator 3.8
 
-Installs a user `ack` binary.
+## Set up
 
-Best used with:
+Run the setup script to create links and download plugins:
+
+    ./setup.sh
+
+This setup is best used with:
 - iTerm2 (Mac OS X), or
 - ROXTerm (Linux)
 - The [Solarized colour palette][solarized].
@@ -23,11 +24,17 @@ Best used with:
 [solarized]: http://ethanschoonover.com/solarized
 [meslo]: https://github.com/Lokaltog/powerline-fonts
 
-#### Issues
+## Issues
 
-##### Prompt in git repositories is slow in OS X Mavericks.
+### Prompt in git repositories is slow in OS X Mavericks.
 
 This is because of the Apple-provided git. Install git through homebrew. Seen
 from [this stackexchange entry][stackexchange].
 
 [stackexchange]: http://apple.stackexchange.com/questions/106784/terminal-goes-slow-after-install-mavericks-os
+
+### Move away from Solarized to a 256-colour friendly scheme?
+
+Solarized, while spectacular to use, requires colour palette setup within the
+terminal emulator itself. When using an unprepared terminal emulator, results
+are often disappointing or unusable.

+ 83 - 219
setup.sh

@@ -1,248 +1,112 @@
 #!/bin/sh
-# Setup Script - Modeline and Notes {{{
+# Setup Script {{{
 # vim: set sw=2 ts=2 sts=2 et tw=78 foldmarker={{{,}}} foldlevel=0 foldmethod=marker spell:
 #
-#   Automated Setup Script - cinaeco/dotfiles
+#   Creates links to configuration files in a user's home folder and downloads
+#   extra software and plugins.
 #
-#   This script creates appropriate symlinks in the home folder and pulls
-#   extra software and plugins where available.
+#   Run from where it's located within dotfiles directory
 #
-#   Run from where it's located within dotfiles directory i.e. `./setup.sh`
+#       ./setup.sh
 #
 # }}}
 
-# Script Helper Functions {{{
-#
-#   These are mostly taken from spf13-vim. They are primarily here to setup
-#   vundle beforehand, to avoid the chicken-and-egg issue.
-#
-debug_mode='0'
+# Support Functions {{{
 
-# Backup Folder for old configuration files {{{
-#
-#   The setup script is non-destructive, and can be run repeatedly - all old
-#   config files or symlinks from previous runs can be recovered from
-#   timestamped temp folders.
-#
-BACKUP_DIR="/tmp/$(date)"
-mkdir "$BACKUP_DIR"
-# }}}
+# Folder for backing up present configuration files.
+backup_dir="/tmp/$(date)"
+mkdir "$backup_dir"
 
-# Symlink Attempt
-lnif() {
-  if [ -e "$1" ]; then
-    ln -sf "$1" "$2"
-  fi
-  ret="$?"
-  debug
-}
-
-# Backup files to backup folder
+# Backup a given file.
 backup() {
-  [ -f "$1" ] && mv "$1" "$BACKUP_DIR"
-  ret="$?"
-  debug
+  [ -e "$1" ] && mv "$1" "$backup_dir"
 }
 
-# Backup directories to backup folder
-backup_dir() {
-  [ -d "$1" ] && mv "$1" "$BACKUP_DIR"
-  ret="$?"
-  debug
+# Create links after backing up.
+linkup() {
+  backup "$2"
+  ln -s "$1" "$2"
 }
 
-msg() {
-  printf '%b\n' "$1" >&2
-}
-
-success() {
-  if [ "$ret" -eq '0' ]; then
-    msg "\e[32m[+]\e[0m ${1}${2}"
-  fi
-}
-
-debug() {
-  if [ "$debug_mode" -eq '1' ] && [ "$ret" -gt '1' ]; then
-    msg "An error occured in function \"${FUNCNAME[$i+1]}\" on line ${BASH_LINENO[$i+1]}"
-  fi
-}
-
-upgrade_repo() {
-  msg "trying to update $1"
-
-  if [ "$1" = "$app_name" ]; then
-    cd "$HOME/.$app_name-3" &&
-      git pull origin "$git_branch"
-  fi
-
-  if [ "$1" = "vundle" ]; then
-    cd "$HOME/.vim/bundle/vundle" &&
-      git pull origin master
-  fi
-
-  ret="$?"
-  success "$2"
-  debug
-}
-
-create_vimlinks() {
-  dotfilesvim="$HOME/dotfiles/vim"
-
-  if [ ! -d "$HOME/.tmp-vim" ]; then
-    mkdir -p "$HOME/.tmp-vim"
-  fi
-  vimfolder="$HOME/.tmp-vim"
-
-  if [ ! -d "$vimfolder/.vim/bundle" ]; then
-    mkdir -p "$vimfolder/.vim/bundle"
-  fi
-
-  lnif "$dotfilesvim/vimrc"              "$HOME/.vimrc"
-  lnif "$dotfilesvim/vimrc.bundles"      "$HOME/.vimrc.bundles"
-  lnif "$vimfolder/.vim"                    "$HOME/.vim"
-
-  ret="$?"
-  success "$1"
-  debug
-}
-
-clone_vundle() {
-  if [ ! -e "$HOME/.vim/bundle/vundle" ]; then
-    git clone https://github.com/gmarik/vundle.git "$HOME/.vim/bundle/vundle"
+# Download vim-plug, a vim plugin manager.
+#
+# Also place vim-plug where it can be auto-loaded.
+download_vim_plug() {
+  folder=~/.vim/plugged/vim-plug
+  if [ ! -e $folder ]; then
+    echo "Vim Plugin Manager cloning"
+    git clone https://github.com/junegunn/vim-plug.git $folder --depth 1
   else
-    upgrade_repo "vundle" "Successfully updated vundle"
+    echo "Vim Plugin Manager updating"
+    cd $folder && git pull
   fi
-  ret="$?"
-  success "$1"
-  debug
+  mkdir -p ~/.vim/autoload
+  linkup "$folder/plug.vim" ~/.vim/autoload/plug.vim
 }
 
-setup_vundle() {
-  system_shell="$SHELL"
-  export SHELL='/bin/sh'
-  vim -u "$HOME/.vimrc.bundles" +PluginInstall! +PluginClean! +qall
-  export SHELL="$system_shell"
-
-  success "$1"
-  debug
+# Run vim-plug's install process.
+#
+# Vim is loaded with only the registry of plugins and the `nocompatible` flag.
+install_vim_plugins() {
+  vim -u ~/dotfiles/vim/plugins.vim -N +PlugInstall +PlugClean +qall
 }
-# }}}
 
-# Make known_hosts file if none {{{
-#
-#   Otherwise, zsh throws an error for our .zshrc
-#
-if test -f ~/.ssh/known_hosts; then
-  ret="$?"
-  success "File 'known_hosts' found"
-else
-  mkdir -p ~/.ssh
-  touch ~/.ssh/known_hosts
-  ret="$?"
-  success "File 'known_hosts' created (blank)"
-fi
 # }}}
 
-# Get the ack search tool {{{
-#
-#   Requires perl 5.8.8 or higher. Curl may need to have proxy settings.
-#
-if test -f ~/bin/ack; then
-  ret="$?"
-  success "Ack found"
-else
-  mkdir -p ~/bin
-  curl http://beyondgrep.com/ack-2.04-single-file > ~/bin/ack && chmod 0755 ~/bin/ack
-  ret="$?"
-  success "Ack installed from beyondgrep.com"
-fi
-# }}}
+# Make known_hosts file if none
+mkdir -p ~/.ssh
+touch ~/.ssh/known_hosts
+echo "We touched all the known hosts."
 
-# Git: colorise output, edit with vim {{{
-#
-#   Makes status', diffs and logs much nicer to use.
-#
+# Git config
 git config --global color.ui true
 git config --global core.editor "vim"
-success "Git colour and editor setup"
-# }}}
+echo "Git config done."
 
-# Initialise and clone any submodules {{{
+# Initialise and clone any submodules
 git submodule sync
 git submodule update --init
-success "Submodules done"
-# }}}
-
-# Zsh {{{
-backup ~/.zshrc
-backup ~/.zshenv
-lnif ~/dotfiles/zsh/zshrc ~/.zshrc
-lnif ~/dotfiles/zsh/zshenv ~/.zshenv
-success "Zsh config linked"
-# }}}
-
-# Vimperator {{{
-backup_dir ~/.vimperator
-backup ~/.vimperatorrc
-lnif ~/dotfiles/vimperator ~/.vimperator
-lnif ~/dotfiles/vimperator/vimperatorrc ~/.vimperatorrc
-success "Vimperator config linked"
-# }}}
-
-# Screen {{{
-backup ~/.screenrc
-lnif ~/dotfiles/screen/screenrc ~/.screenrc
-success "Screen config linked"
-# }}}
-
-# Tmux {{{
-backup ~/.tmux.conf
-lnif ~/dotfiles/tmux/tmux.conf ~/.tmux.conf
-success "Tmux config linked"
-# }}}
-
-# Powerline {{{
-# `.config` is a shared config location, so take more care
-backup_dir ~/.config/powerline
-[ ! -d ~/.config ] && mkdir ~/.config
-lnif ~/dotfiles/powerline/config ~/.config/powerline
-success "Powerline config linked"
-# }}}
-
-# Irssi {{{
-backup_dir ~/.irssi
-lnif ~/dotfiles/irssi ~/.irssi
-success "Irssi config linked"
-# }}}
-
-# Ack {{{
-backup ~/.ackrc
-lnif ~/dotfiles/ack/ackrc ~/.ackrc
-success "Ack config linked"
-# }}}
-
-# Emacs {{{
-backup ~/.emacs
-lnif ~/dotfiles/emacs/emacs ~/.emacs
-success "Emacs config linked"
-# }}}
-
-# ZFS {{{
-backup ~/bin/destroy-zfs-auto-snaps
-lnif ~/dotfiles/zfs/destroy-zfs-auto-snaps ~/bin
-success "ZFS utilities installed"
-# }}}
-
-# Vim {{{
-backup_dir ~/.vim
-backup ~/.vimrc
-backup ~/.vimrc.bundles
-create_vimlinks "Setting up vim symlinks"
-clone_vundle    "Successfully cloned vundle"
-setup_vundle    "Now updating/installing plugins using Vundle"
-# }}}
-
-# Success {{{
-ret="$?"
-success "Setup complete!"
-# }}}
+echo "Submodules done."
+
+# Zsh
+linkup ~/dotfiles/zsh/zshrc ~/.zshrc
+linkup ~/dotfiles/zsh/zshenv ~/.zshenv
+echo "Zsh linked."
+
+# Vimperator
+linkup ~/dotfiles/vimperator ~/.vimperator
+linkup ~/dotfiles/vimperator/vimperatorrc ~/.vimperatorrc
+echo "Vimperator linked."
+
+# Screen
+linkup ~/dotfiles/screen/screenrc ~/.screenrc
+echo "Screen linked."
+
+# Tmux
+linkup ~/dotfiles/tmux/tmux.conf ~/.tmux.conf
+echo "Tmux linked."
+
+# Irssi
+linkup ~/dotfiles/irssi ~/.irssi
+echo "Irssi linked."
+
+# Ack
+linkup ~/dotfiles/ack/ackrc ~/.ackrc
+echo "Ack linked."
+
+# Powerline
+mkdir -p ~/.config
+linkup ~/dotfiles/powerline/config ~/.config/powerline
+echo "Powerline linked."
+
+# Vim (and NeoVim)
+linkup ~/dotfiles/vim/vimrc ~/.vimrc
+linkup ~/dotfiles/vim/vimrc ~/.nvimrc
+mkdir -p ~/.vim-tmp
+linkup ~/.vim-tmp ~/.vim
+linkup ~/.vim-tmp ~/.nvim
+download_vim_plug
+install_vim_plugins
+echo "Vim linked."
+
+echo "Setup complete!"

+ 97 - 0
vim/plugins.vim

@@ -0,0 +1,97 @@
+" Plugins {{{
+" vim: set sw=2 ts=2 sts=2 et tw=78 foldmarker={{{,}}} foldlevel=0 foldmethod=marker spell:
+"
+"   Vim Plugin Setup Script
+"
+"   This file is used from 2 places:
+"    - vimrc
+"    - setup.sh
+" }}}
+
+call plug#begin('~/.vim/plugged')
+
+"if executable('ack-grep')
+  "let g:ackprg="ack-grep -H --nocolor --nogroup --column"
+  "Plug 'mileszs/ack.vim'
+"elseif executable('ack')
+  "Plug 'mileszs/ack.vim'
+"elseif executable('ag')
+  "Plug 'mileszs/ack.vim'
+  "let g:ackprg = 'ag --nogroup --nocolor --column --smart-case'
+"endif
+
+Plug 'junegunn/vim-plug'
+Plug 'kien/ctrlp.vim'
+Plug 'tacahiroy/ctrlp-funky'
+Plug 'joonty/vdebug'
+Plug 'tpope/vim-repeat'
+Plug 'kshenoy/vim-signature'
+Plug 'itchyny/lightline.vim'
+Plug 'haya14busa/vim-asterisk'
+
+Plug 'nathanaelkane/vim-indent-guides'
+Plug 'altercation/vim-colors-solarized'
+Plug 'cinaeco/EasyGrep'
+Plug 'tpope/vim-surround'
+Plug 'Raimondi/delimitMate'
+Plug 'terryma/vim-multiple-cursors'
+Plug 'matchit.zip'
+Plug 'tpope/vim-abolish'
+Plug 'tpope/vim-unimpaired'
+Plug 'scrooloose/syntastic'
+Plug 'tpope/vim-fugitive'
+Plug 'scrooloose/nerdcommenter'
+Plug 'godlygeek/tabular'
+Plug 'tristen/vim-sparkup'
+"Plug 'sjl/gundo.vim'
+"Plug 'katono/rogue.vim'
+"Plug 'haya14busa/incsearch.vim' - interferes with macros
+"Plug 'deris/vim-shot-f' - interferes with macro
+
+" Text Objects {{{
+Plug 'kana/vim-textobj-user'
+Plug 'kana/vim-textobj-entire'
+Plug 'bkad/CamelCaseMotion'
+Plug 'vim-scripts/argtextobj.vim'
+" }}}
+
+" File Browser {{{
+Plug 'scrooloose/nerdtree'
+Plug 'jistr/vim-nerdtree-tabs'
+" }}}
+
+" Code Browser {{{
+if executable('ctags')
+  Plug 'majutsushi/tagbar'
+  if executable('phpctags')
+    Plug 'vim-php/tagbar-phpctags.vim'
+  endif
+endif
+" }}}
+
+" Completion and Snippets {{{
+"Plug 'ervandew/supertab'
+"Plug 'MarcWeber/vim-addon-mw-utils'
+"Plug 'tomtom/tlib_vim'
+"Plug 'garbas/vim-snipmate'
+"Plug 'honza/vim-snippets'
+"" Source support_function.vim to support vim-snippets.
+"if filereadable(expand("~/.vim/bundle/vim-snippets/snippets/support_functions.vim"))
+  "source ~/.vim/bundle/vim-snippets/snippets/support_functions.vim
+"endif
+Plug 'ajh17/VimCompletesMe'
+" }}}
+
+" Coding Language Support {{{
+Plug 'shawncplus/phpcomplete.vim'
+Plug 'tpope/vim-markdown'
+Plug 'tpope/vim-cucumber'
+Plug 'quentindecock/vim-cucumber-align-pipes'
+Plug 'kchmck/vim-coffee-script'
+Plug 'mintplant/vim-literate-coffeescript'
+Plug 'groenewege/vim-less'
+Plug 'elzr/vim-json'
+Plug 'vim-scripts/yaml.vim'
+" }}}
+
+call plug#end()

+ 3 - 4
vim/vimrc

@@ -9,11 +9,10 @@ if has("autocmd")
   autocmd!
 endif
 
-" Use bundles config {{{
-if filereadable(expand("~/.vimrc.bundles"))
-  source ~/.vimrc.bundles
+" Register plugins
+if filereadable(expand("~/dotfiles/vim/plugins.vim"))
+  source ~/dotfiles/vim/plugins.vim
 endif
-" }}}
 
 filetype plugin indent on   " Automatically detect file types.
 

+ 0 - 104
vim/vimrc.bundles

@@ -1,104 +0,0 @@
-" Bundles - Modeline and Notes {{{
-" vim: set sw=2 ts=2 sts=2 et tw=78 foldmarker={{{,}}} foldlevel=0 foldmethod=marker spell:
-"
-"   Vim Plugins are managed using Vundle.
-"
-" }}}
-
-" Setup Bundle Support {{{
-" Ensure that the ~/.vim/bundle/ system works
-set nocompatible
-filetype off
-set rtp+=~/.vim/bundle/vundle
-call vundle#rc()
-" }}}
-
-" Bundles {{{
-
-" Vundle managing itself!
-Bundle 'gmarik/vundle'
-
-"if executable('ack-grep')
-  "let g:ackprg="ack-grep -H --nocolor --nogroup --column"
-  "Bundle 'mileszs/ack.vim'
-"elseif executable('ack')
-  "Bundle 'mileszs/ack.vim'
-"elseif executable('ag')
-  "Bundle 'mileszs/ack.vim'
-  "let g:ackprg = 'ag --nogroup --nocolor --column --smart-case'
-"endif
-
-Bundle 'kien/ctrlp.vim'
-Bundle 'tacahiroy/ctrlp-funky'
-Bundle 'joonty/vdebug'
-Bundle 'tpope/vim-repeat'
-Bundle 'kshenoy/vim-signature'
-Bundle 'itchyny/lightline.vim'
-Bundle 'haya14busa/vim-asterisk'
-
-Bundle 'nathanaelkane/vim-indent-guides'
-Bundle 'altercation/vim-colors-solarized'
-Bundle 'cinaeco/EasyGrep'
-Bundle 'tpope/vim-surround'
-Bundle 'Raimondi/delimitMate'
-Bundle 'terryma/vim-multiple-cursors'
-Bundle 'matchit.zip'
-Bundle 'tpope/vim-abolish.git'
-Bundle 'tpope/vim-unimpaired.git'
-Bundle 'scrooloose/syntastic'
-Bundle 'tpope/vim-fugitive'
-Bundle 'scrooloose/nerdcommenter'
-Bundle 'godlygeek/tabular'
-Bundle 'tristen/vim-sparkup'
-"Bundle 'sjl/gundo.vim'
-"Bundle 'katono/rogue.vim'
-"Bundle 'haya14busa/incsearch.vim' - interferes with macros
-"Bundle 'deris/vim-shot-f' - interferes with macro
-
-" Text Objects {{{
-Bundle 'kana/vim-textobj-user'
-Bundle 'kana/vim-textobj-entire'
-Bundle 'bkad/CamelCaseMotion'
-Bundle 'vim-scripts/argtextobj.vim'
-" }}}
-
-" File Browser {{{
-Bundle 'scrooloose/nerdtree'
-Bundle 'jistr/vim-nerdtree-tabs'
-" }}}
-
-" Code Browser {{{
-if executable('ctags')
-  Bundle 'majutsushi/tagbar'
-  if executable('phpctags')
-    Bundle 'vim-php/tagbar-phpctags.vim'
-  endif
-endif
-" }}}
-
-" Completion and Snippets {{{
-"Bundle 'ervandew/supertab'
-"Bundle 'MarcWeber/vim-addon-mw-utils'
-"Bundle 'tomtom/tlib_vim'
-"Bundle 'garbas/vim-snipmate'
-"Bundle 'honza/vim-snippets'
-"" Source support_function.vim to support vim-snippets.
-"if filereadable(expand("~/.vim/bundle/vim-snippets/snippets/support_functions.vim"))
-  "source ~/.vim/bundle/vim-snippets/snippets/support_functions.vim
-"endif
-Bundle 'ajh17/VimCompletesMe'
-" }}}
-
-" Coding Language Support {{{
-Bundle 'shawncplus/phpcomplete.vim'
-Bundle 'tpope/vim-markdown'
-Bundle 'tpope/vim-cucumber'
-Bundle 'quentindecock/vim-cucumber-align-pipes'
-Bundle 'kchmck/vim-coffee-script'
-Bundle 'mintplant/vim-literate-coffeescript'
-Bundle 'groenewege/vim-less'
-Bundle 'elzr/vim-json'
-Bundle 'vim-scripts/yaml.vim'
-" }}}
-
-" }}}