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:
Eryn Wells 2022-12-13 14:09:36 -08:00
parent 386b88ee9e
commit af9bc505bb

View file

@ -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,13 +57,15 @@ for file in ~/.?*; do
fi
link_dirname=`dirname "$link_dest"`
if [[ "$link_dirname" != "$dfdir" ]]; then
if [[ "$link_dirname" != "$dotfiles_dir" ]]; then
continue
fi
if ! matches_skip_item `basename "$link_dest"`; then
if [[ -e "$link_dest" ]]; then
continue
fi
fi
printf " Removing: %s\n" "$file"
rm "$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,8 +109,21 @@ if [[ $did_link_at_least_one_dotfile -ne 1 ]]; then
print " Nothing to link"
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
print -P "%BFetching Vim modules%b"
cd "$dfdir/vim/bundle"
if (( $install_vim_modules )); then
cd "$dotfiles_dir/vim/bundle"
for module in ${(k)vimbundles}; do
print -n " $module"
@ -112,5 +142,8 @@ if ! whence -cp nvim >& -; then
VIM=vim
fi
$VIM +PluginInstall +qall
else
print " Nothing to do"
fi
exit 0