Biggest update to setup.sh since the invention of bread
- Add a few items to skipitems that were missing - Add a matches_skip_item function that checks if a basename matches one of the skip items - Clean up files that match skipitems - Add a +v arg that disables installing Vim modules
This commit is contained in:
parent
386b88ee9e
commit
af9bc505bb
1 changed files with 62 additions and 29 deletions
91
setup.sh
91
setup.sh
|
@ -1,9 +1,9 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
dfdir=$(cd "$(dirname "$0")" && pwd)
|
||||
dotfiles_dir=$(cd "$(dirname "$0")" && pwd)
|
||||
sys=`uname -s | tr A-Z a-z`
|
||||
|
||||
skipitems=(setup.sh README.md py Colors LaunchAgents)
|
||||
skipitems=(setup.sh README.md py bin Alfred Colors Dotfiles LaunchAgents '.*\.orig' '.*~')
|
||||
|
||||
typeset -A vimbundles
|
||||
vimbundles=(Vundle.vim "https://github.com/gmarik/Vundle.vim.git")
|
||||
|
@ -29,8 +29,20 @@ function link {
|
|||
printf " %8s: %s\n" $action "$dest"
|
||||
}
|
||||
|
||||
function matches_skip_item {
|
||||
local string_to_match=$1
|
||||
|
||||
for item in $skipitems; do
|
||||
if [[ $string_to_match =~ $item ]]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
print -P " %BHome:%b $HOME"
|
||||
print -P " %BDotfiles:%b $dfdir"
|
||||
print -P " %BDotfiles:%b $dotfiles_dir"
|
||||
print -P "%BSkip Items:%b $skipitems\n"
|
||||
|
||||
print -P "%BRemoving stray dotfile symlinks from $HOME%b"
|
||||
|
@ -45,12 +57,14 @@ for file in ~/.?*; do
|
|||
fi
|
||||
|
||||
link_dirname=`dirname "$link_dest"`
|
||||
if [[ "$link_dirname" != "$dfdir" ]]; then
|
||||
if [[ "$link_dirname" != "$dotfiles_dir" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ -e "$link_dest" ]]; then
|
||||
continue
|
||||
if ! matches_skip_item `basename "$link_dest"`; then
|
||||
if [[ -e "$link_dest" ]]; then
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
printf " Removing: %s\n" "$file"
|
||||
|
@ -63,26 +77,29 @@ if [[ $did_remove_at_least_one_symlink -ne 1 ]]; then
|
|||
fi
|
||||
|
||||
print -P "%BSymlinking config files%b"
|
||||
local dotfile
|
||||
local did_link_at_least_one_dotfile=0
|
||||
for dotfile in $dfdir/*; do
|
||||
if [[ ${skipitems[(r)$dotfile]} == $dotfile ]]; then
|
||||
for dotfile in $dotfiles_dir/*; do
|
||||
local dotfile_basename=`basename "$dotfile"`
|
||||
|
||||
if matches_skip_item "$dotfile_basename"; then
|
||||
continue
|
||||
fi
|
||||
if [[ "`basename $dotfile`" == "config" ]]; then
|
||||
|
||||
if [[ "$dotfile_basename" == "config" ]]; then
|
||||
# Recurse into config and link each item individually
|
||||
mkdir -p "$HOME/.config"
|
||||
for config_dotfile in $dfdir/config/*; do
|
||||
for config_dotfile in $dotfiles_dir/config/*; do
|
||||
config_dotfile_basename=`basename "$config_dotfile"`
|
||||
link "$config_dotfile" "$HOME/.config/$config_dotfile_basename"
|
||||
done
|
||||
else
|
||||
link "$dotfile"
|
||||
fi
|
||||
|
||||
did_link_at_least_one_dotfile=1
|
||||
done
|
||||
|
||||
if [[ -f "$HOME/.hushlogin" ]]; then
|
||||
if [[ ! -f "$HOME/.hushlogin" ]]; then
|
||||
print " touch $HOME/.hushlogin"
|
||||
touch "$HOME/.hushlogin"
|
||||
did_link_at_least_one_dotfile=1
|
||||
|
@ -92,25 +109,41 @@ if [[ $did_link_at_least_one_dotfile -ne 1 ]]; then
|
|||
print " Nothing to link"
|
||||
fi
|
||||
|
||||
print -P "%BFetching Vim modules%b"
|
||||
cd "$dfdir/vim/bundle"
|
||||
for module in ${(k)vimbundles}; do
|
||||
print -n " $module"
|
||||
|
||||
if [[ ! -d $module ]]; then
|
||||
git clone ${vimbundles[$module]} $module >& -
|
||||
if [[ $? -eq 0 ]]; then
|
||||
result='done'
|
||||
else
|
||||
result='failed'
|
||||
fi
|
||||
fi
|
||||
local install_vim_modules=1
|
||||
while getopts "v" arg $@; do
|
||||
case $arg in
|
||||
"v") install_vim_modules=1 ;;
|
||||
"+v") install_vim_modules=0 ;;
|
||||
*)
|
||||
echo "Usage: setup.sh [+v|-v]"
|
||||
echo " +v|-v Install Vim modules"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
VIM=nvim
|
||||
if ! whence -cp nvim >& -; then
|
||||
VIM=vim
|
||||
print -P "%BFetching Vim modules%b"
|
||||
if (( $install_vim_modules )); then
|
||||
cd "$dotfiles_dir/vim/bundle"
|
||||
for module in ${(k)vimbundles}; do
|
||||
print -n " $module"
|
||||
|
||||
if [[ ! -d $module ]]; then
|
||||
git clone ${vimbundles[$module]} $module >& -
|
||||
if [[ $? -eq 0 ]]; then
|
||||
result='done'
|
||||
else
|
||||
result='failed'
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
VIM=nvim
|
||||
if ! whence -cp nvim >& -; then
|
||||
VIM=vim
|
||||
fi
|
||||
$VIM +PluginInstall +qall
|
||||
else
|
||||
print " Nothing to do"
|
||||
fi
|
||||
$VIM +PluginInstall +qall
|
||||
|
||||
exit 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue