mirror of https://github.com/nirenjan/dotfiles.git
Add VimBundler script and bundles file
parent
95c8ad2490
commit
bb19d19a58
|
@ -0,0 +1,156 @@
|
|||
#!/usr/bin/env ruby
|
||||
# Script to automatically install Vim bundles to ~/.vim/bundle/
|
||||
#
|
||||
# See vim/bundles for a sample file
|
||||
|
||||
require 'getoptlong'
|
||||
|
||||
# Shut up about warnings
|
||||
BUNDLE_ROOT = '/.vim/bundle/'
|
||||
|
||||
def vim_bundle(bundle, tag=nil)
|
||||
if $transport == 'ssh'
|
||||
url = 'git@github.com:'
|
||||
elsif $transport == 'https'
|
||||
url = 'https://github.com/'
|
||||
elsif $transport == 'git'
|
||||
url = 'git://github.com/'
|
||||
else
|
||||
$stderr.puts "#{$an}: Unrecognized transport layer '#{transport}' (try --help)"
|
||||
exit 1
|
||||
end
|
||||
|
||||
if bundle =~ /^[A-Za-z0-9-]+\/[A-Za-z0-9._-]+$/
|
||||
url += bundle + '.git'
|
||||
elsif bundle =~ /^[A-Za-z0-9._-]+$/
|
||||
url += 'vim-scripts/' + bundle + '.git'
|
||||
else
|
||||
# We are using a service other than GitHub. Specifying the URL directly
|
||||
url = bundle
|
||||
end
|
||||
|
||||
bundle_name = bundle.sub(/^.*\//, '').sub(/\.git$/, '')
|
||||
|
||||
if $dry_run
|
||||
puts "URL #{url} Bundle #{bundle_name} Tag #{tag.to_s}"
|
||||
return
|
||||
else
|
||||
dir = ENV['HOME'] + BUNDLE_ROOT + bundle_name
|
||||
pwd = Dir.pwd
|
||||
$VERBOSE = nil
|
||||
if File.directory?(dir)
|
||||
if $update # Don't update if the no-update option was passed
|
||||
if File.directory?(dir + '/.git')
|
||||
puts "Updating bundle #{bundle_name}..."
|
||||
Dir.chdir(dir)
|
||||
`git fetch`
|
||||
Dir.chdir(pwd)
|
||||
puts
|
||||
else
|
||||
$stderr.puts "#{$an}: #{bundle_name} is not a Git repository."
|
||||
return
|
||||
end
|
||||
else
|
||||
$stderr.puts "#{$an}: Skipping update for #{bundle_name}"
|
||||
return
|
||||
end
|
||||
|
||||
else
|
||||
# Directory doesn't exist, need to pull
|
||||
puts "Installing bundle #{bundle_name}..."
|
||||
Dir.chdir(ENV['HOME'] + BUNDLE_ROOT)
|
||||
`git clone #{url} #{bundle_name}`
|
||||
Dir.chdir(pwd)
|
||||
puts
|
||||
end
|
||||
|
||||
tag ||= 'origin/HEAD'
|
||||
Dir.chdir(dir)
|
||||
`git stash`
|
||||
`git checkout #{tag}`
|
||||
`git stash pop`
|
||||
Dir.chdir(pwd)
|
||||
$VERBOSE = false
|
||||
end
|
||||
end
|
||||
|
||||
opts = GetoptLong.new(
|
||||
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
|
||||
[ '--transport', '-t', GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ '--no-update', GetoptLong::NO_ARGUMENT ],
|
||||
[ '--dry-run', '-n', GetoptLong::NO_ARGUMENT ]
|
||||
)
|
||||
|
||||
$an = $0.sub(/^.*\//, '')
|
||||
file = nil
|
||||
$transport = 'ssh'
|
||||
$update = true
|
||||
$dry_run = false
|
||||
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts <<-EOF
|
||||
#{$an} manages vim bundles in ~/.vim/bundles
|
||||
Usage: #{$an} [OPTIONS] FILE
|
||||
|
||||
Options:
|
||||
--transport, Use the specified transport layer to download git bundles.
|
||||
-t <option> Transport layer can be one of git, ssh or https.
|
||||
|
||||
--no-update Do not update existing bundles, only download new ones.
|
||||
|
||||
--dry-run, -n Just print what would be done, do not execute anything.
|
||||
|
||||
--help, -h Display this help message
|
||||
|
||||
The specified file must have the path to the bundle's repository on GitHub.
|
||||
If you are using any other service, you must specify the full URL, and the
|
||||
transport option will not be applied. You may optionally specify a tag or SHA
|
||||
to checkout, otherwise, it will checkout the HEAD version.
|
||||
|
||||
EOF
|
||||
exit 0
|
||||
|
||||
when '--transport'
|
||||
unless arg == 'ssh' or arg == 'https' or arg == 'git'
|
||||
$stderr.puts "#{$an}: Transport option must be one of git, https or ssh"
|
||||
exit 1
|
||||
end
|
||||
|
||||
$transport = arg
|
||||
|
||||
when '--no-update'
|
||||
$update = false
|
||||
|
||||
when '--dry-run'
|
||||
$dry_run = true
|
||||
end
|
||||
end
|
||||
|
||||
if ARGV.length != 1
|
||||
$stderr.puts "#{$an}: Missing FILE argument (try --help)"
|
||||
exit 1
|
||||
end
|
||||
|
||||
file = ARGV.shift
|
||||
|
||||
# Read the file contents
|
||||
unless File.file?(file) and File.readable?(file)
|
||||
$stderr.puts "#{$an}: Unable to read file #{file}"
|
||||
exit 1
|
||||
end
|
||||
|
||||
File.open(file).each do |line|
|
||||
# Chop off comments
|
||||
line.sub!(/#.*$/, '')
|
||||
# Strip leading and trailing spaces
|
||||
line.sub!(/^\s*/, '')
|
||||
line.sub!(/\s*$/, '')
|
||||
|
||||
args = line.split
|
||||
bname = args[0]
|
||||
tag = args[1]
|
||||
|
||||
vim_bundle(bname, tag) if (bname)
|
||||
end
|
75
install
75
install
|
@ -94,72 +94,6 @@ lnfile()
|
|||
fi
|
||||
}
|
||||
|
||||
# Install/update vim bundles
|
||||
vim_update_bundle()
|
||||
{
|
||||
BUNDLE=$(echo $1 | sed 's:^.*/::' | sed 's:\.git$::')
|
||||
# If the bundle already exists, update it (if possible)
|
||||
if [[ -d "$HOME/.vim/bundle/$BUNDLE" ]]
|
||||
then
|
||||
# Don't update the bundle if BUNDLE_NO_UPDATE is set
|
||||
if [[ -d "$HOME/.vim/bundle/$BUNDLE/.git" ]]
|
||||
then
|
||||
if [[ -z $BUNDLE_NO_UPDATE ]]; then
|
||||
echo "Updating bundle $BUNDLE..."
|
||||
pushd "$HOME/.vim/bundle/$BUNDLE" >/dev/null
|
||||
git pull
|
||||
popd >/dev/null
|
||||
echo
|
||||
fi
|
||||
else
|
||||
echo "$BUNDLE is not a Git repository. Skipping update."
|
||||
fi
|
||||
else
|
||||
echo "Installing bundle $BUNDLE..."
|
||||
pushd "$HOME/.vim/bundle/" >/dev/null
|
||||
git clone $1
|
||||
popd >/dev/null
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
# Wrapper to vim_update_bundle
|
||||
# Let's you specify the bundle repo in a short form if it resides on GitHub
|
||||
# (and perhaps one of the repos in vim-scripts). You can still specify a full
|
||||
# URL if necessary. However, that will not allow you to dynamically choose a
|
||||
# transport layer at runtime
|
||||
Bundle()
|
||||
{
|
||||
# Get the prefix ready
|
||||
if [[ "$BUNDLE_TRANSPORT" == "ssh" ]]; then
|
||||
# If the user specifies to use ssh as the transport
|
||||
URL="git@github.com:"
|
||||
elif [[ "$BUNDLE_TRANSPORT" == "https" ]]; then
|
||||
# Use https as the transport
|
||||
URL="https://github.com/"
|
||||
elif [[ "$BUNDLE_TRANSPORT" == "git" ]]; then
|
||||
# Use git as the transport
|
||||
URL="git://github.com/"
|
||||
else
|
||||
echo "Invalid transport layer! Aborting!!!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check the bundle format
|
||||
if [[ $(echo $1 | grep "^[A-Za-z0-9-]\+\/[A-Za-z0-9._-]\+$") == $1 ]]; then
|
||||
# Username/repo combo
|
||||
URL="${URL}${1}.git"
|
||||
elif [[ $(echo $1 | grep "^[A-Za-z0-9._-]\+$") == $1 ]]; then
|
||||
# Bare repo name - must be from the vim-scripts user
|
||||
URL="${URL}vim-scripts/${1}.git"
|
||||
else
|
||||
# I don't care, I'm specifying the URL directly
|
||||
URL=$1
|
||||
fi
|
||||
|
||||
vim_update_bundle "$URL"
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
# Verify command line switches
|
||||
#######################################################################
|
||||
|
@ -290,14 +224,7 @@ lnfile vim/ftplugin/markdown.vim ~/.vim/ftplugin/
|
|||
#######################################################################
|
||||
# Install/update Vim bundles
|
||||
#######################################################################
|
||||
Bundle tpope/vim-pathogen # pathogen
|
||||
Bundle tpope/vim-fugitive # A Git wrapper so awesome, it
|
||||
# should be illegal!
|
||||
Bundle zaiste/tmux.vim # tmux config file syntax
|
||||
Bundle altercation/vim-colors-solarized # Solarized
|
||||
Bundle vimwiki # Vimwiki
|
||||
Bundle msanders/snipmate.vim # snipMate
|
||||
Bundle tomtom/tcomment_vim # tComment
|
||||
./VimBundler vim/bundles
|
||||
|
||||
#######################################################################
|
||||
# Install tmux & screen config files
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# List of Vim bundles
|
||||
# Pathogen v2.2
|
||||
tpope/vim-pathogen v2.2
|
||||
|
||||
# A Git wrapper so awesome, it should be illegal
|
||||
tpope/vim-fugitive
|
||||
|
||||
# tmux config file syntax
|
||||
zaiste/tmux.vim
|
||||
|
||||
# Solarized
|
||||
altercation/vim-colors-solarized
|
||||
|
||||
# Vimwiki
|
||||
vimwiki 2.1
|
||||
|
||||
# snipMate
|
||||
msanders/snipmate.vim
|
||||
|
||||
# tComment
|
||||
tomtom/tcomment_vim 2.08
|
||||
|
||||
# Airline
|
||||
bling/vim-airline v0.3
|
18
vimrc
18
vimrc
|
@ -43,18 +43,12 @@ set laststatus=2
|
|||
" Show tab line
|
||||
set showtabline=2
|
||||
|
||||
" Set status to show all details
|
||||
set statusline=%F " Full path to filename
|
||||
set statusline+=%m " Modified flag
|
||||
set statusline+=%h " Help buffer flag
|
||||
set statusline+=%w " Preview window flag
|
||||
set statusline+=\ %y " File type
|
||||
set statusline+=%= " Switch to right align
|
||||
set statusline+=[%03.3b " ASCII value for character under cursor
|
||||
set statusline+=/0x%02.2B] " Same, but in hex
|
||||
set statusline+=\ [%v " Virtual column number
|
||||
set statusline+=,%l/%L] " Current line number, total lines
|
||||
set statusline+=\ [%p%%] " Percentage through file
|
||||
" Statusline is handled by the airline plugin. Just set the ttm accordingly
|
||||
set ttm=50
|
||||
let g:airline_theme='solarized'
|
||||
let g:airline_left_sep=''
|
||||
let g:airline_right_sep=''
|
||||
"let g:airline_section_z='[%03.3b/0x%02.2B] %3.3p%% : %l/%L : %v '
|
||||
|
||||
" Set the cursorline option
|
||||
" This (by default shows up as underlining)
|
||||
|
|
Loading…
Reference in New Issue