2013-09-04 14:03:45 -07:00
|
|
|
#!/usr/bin/env zsh
|
2011-05-03 21:53:50 -07:00
|
|
|
|
2022-12-13 14:09:36 -08:00
|
|
|
dotfiles_dir=$(cd "$(dirname "$0")" && pwd)
|
2012-04-23 15:02:41 -07:00
|
|
|
sys=`uname -s | tr A-Z a-z`
|
2011-05-03 21:53:50 -07:00
|
|
|
|
2025-08-11 17:08:07 -07:00
|
|
|
skipitems=( \
|
|
|
|
'.*\.orig' \
|
|
|
|
'.*~' \
|
|
|
|
Alfred \
|
|
|
|
Ansible \
|
|
|
|
bin \
|
|
|
|
Colors \
|
|
|
|
Dotfiles \
|
|
|
|
Fortune \
|
|
|
|
LaunchAgents \
|
|
|
|
py \
|
|
|
|
Python \
|
|
|
|
README.md \
|
|
|
|
setup.sh \
|
|
|
|
Web \
|
|
|
|
Xcode \
|
|
|
|
)
|
2013-01-23 11:11:52 -08:00
|
|
|
|
2022-01-23 11:27:16 -08:00
|
|
|
function link {
|
|
|
|
local action
|
2014-09-02 09:37:45 -07:00
|
|
|
local dest
|
2022-01-23 11:27:16 -08:00
|
|
|
|
|
|
|
if [[ -z $2 ]]; then
|
|
|
|
local dotfile_basename=`basename "$1"`
|
|
|
|
dest="$HOME/.$dotfile_basename"
|
2014-09-02 09:37:45 -07:00
|
|
|
else
|
|
|
|
dest="$2"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -e "$dest" ]]; then
|
|
|
|
action='Linking'
|
|
|
|
ln -fs "$1" "$dest"
|
|
|
|
else
|
|
|
|
action='Skipping'
|
|
|
|
fi
|
2022-01-23 11:27:16 -08:00
|
|
|
|
|
|
|
printf " %8s: %s\n" $action "$dest"
|
2014-09-02 09:37:45 -07:00
|
|
|
}
|
|
|
|
|
2022-12-13 14:09:36 -08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2025-08-11 17:12:14 -07:00
|
|
|
function build_fortunes {
|
|
|
|
echo "Building fortunes file"
|
|
|
|
(cd Fortune && make)
|
|
|
|
}
|
|
|
|
|
2022-05-28 23:58:47 -07:00
|
|
|
print -P " %BHome:%b $HOME"
|
2022-12-13 14:09:36 -08:00
|
|
|
print -P " %BDotfiles:%b $dotfiles_dir"
|
2022-05-28 23:58:47 -07:00
|
|
|
print -P "%BSkip Items:%b $skipitems\n"
|
2022-01-23 11:27:16 -08:00
|
|
|
|
|
|
|
print -P "%BRemoving stray dotfile symlinks from $HOME%b"
|
|
|
|
local link_dest
|
|
|
|
local link_dirname
|
|
|
|
local did_remove_at_least_one_symlink=0
|
|
|
|
for file in ~/.?*; do
|
|
|
|
link_dest=`readlink "$file"`
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
# Not a symlink.
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
link_dirname=`dirname "$link_dest"`
|
2022-12-13 14:09:36 -08:00
|
|
|
if [[ "$link_dirname" != "$dotfiles_dir" ]]; then
|
2022-01-23 11:27:16 -08:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2022-12-13 14:09:36 -08:00
|
|
|
if ! matches_skip_item `basename "$link_dest"`; then
|
|
|
|
if [[ -e "$link_dest" ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
2022-01-23 11:27:16 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
printf " Removing: %s\n" "$file"
|
|
|
|
rm "$file"
|
|
|
|
did_remove_at_least_one_symlink=1
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ $did_remove_at_least_one_symlink -ne 1 ]]; then
|
|
|
|
print " Nothing to remove"
|
|
|
|
fi
|
2014-09-02 09:37:45 -07:00
|
|
|
|
2012-04-11 09:54:43 -07:00
|
|
|
print -P "%BSymlinking config files%b"
|
2022-01-23 11:27:16 -08:00
|
|
|
local did_link_at_least_one_dotfile=0
|
2022-12-13 14:09:36 -08:00
|
|
|
for dotfile in $dotfiles_dir/*; do
|
|
|
|
local dotfile_basename=`basename "$dotfile"`
|
|
|
|
|
|
|
|
if matches_skip_item "$dotfile_basename"; then
|
2022-01-23 11:27:16 -08:00
|
|
|
continue
|
|
|
|
fi
|
2022-12-13 14:09:36 -08:00
|
|
|
|
|
|
|
if [[ "$dotfile_basename" == "config" ]]; then
|
2022-05-28 23:58:47 -07:00
|
|
|
# Recurse into config and link each item individually
|
|
|
|
mkdir -p "$HOME/.config"
|
2022-12-13 14:09:36 -08:00
|
|
|
for config_dotfile in $dotfiles_dir/config/*; do
|
2022-05-28 23:58:47 -07:00
|
|
|
config_dotfile_basename=`basename "$config_dotfile"`
|
|
|
|
link "$config_dotfile" "$HOME/.config/$config_dotfile_basename"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
link "$dotfile"
|
|
|
|
fi
|
2022-12-13 14:09:36 -08:00
|
|
|
|
2022-01-23 11:27:16 -08:00
|
|
|
did_link_at_least_one_dotfile=1
|
2012-04-11 09:54:43 -07:00
|
|
|
done
|
|
|
|
|
2022-12-13 14:09:36 -08:00
|
|
|
if [[ ! -f "$HOME/.hushlogin" ]]; then
|
2022-01-23 11:27:16 -08:00
|
|
|
print " touch $HOME/.hushlogin"
|
|
|
|
touch "$HOME/.hushlogin"
|
|
|
|
did_link_at_least_one_dotfile=1
|
|
|
|
fi
|
2014-09-02 09:37:45 -07:00
|
|
|
|
2022-01-23 11:27:16 -08:00
|
|
|
if [[ $did_link_at_least_one_dotfile -ne 1 ]]; then
|
|
|
|
print " Nothing to link"
|
|
|
|
fi
|
2011-05-03 21:53:50 -07:00
|
|
|
|
2023-03-20 11:58:45 -07:00
|
|
|
local configure_vim=1
|
2022-12-13 14:09:36 -08:00
|
|
|
while getopts "v" arg $@; do
|
|
|
|
case $arg in
|
2023-03-20 11:58:45 -07:00
|
|
|
"v") configure_vim=1 ;;
|
|
|
|
"+v") configure_vim=0 ;;
|
2022-12-13 14:09:36 -08:00
|
|
|
*)
|
|
|
|
echo "Usage: setup.sh [+v|-v]"
|
2023-03-20 11:58:45 -07:00
|
|
|
echo " +v|-v Configure (Neo)vim. Default yes; +v skips."
|
2022-12-13 14:09:36 -08:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2024-10-01 10:23:13 -07:00
|
|
|
print "Creating Python virtual environment"
|
|
|
|
local venv_path=~/.local/share/python-virtual-environments/eryn
|
|
|
|
python3 -m venv --system-site-packages "$venv_path"
|
|
|
|
"$venv_path/bin/pip" install "$dotfiles_dir/Python/eryntools"
|
2024-03-05 11:06:26 -08:00
|
|
|
|
2023-03-20 11:58:45 -07:00
|
|
|
if (( $configure_vim )); then
|
|
|
|
print -P "%BConfiguring Vim%b"
|
2011-05-03 21:53:50 -07:00
|
|
|
|
2022-12-13 14:09:36 -08:00
|
|
|
VIM=nvim
|
|
|
|
if ! whence -cp nvim >& -; then
|
|
|
|
VIM=vim
|
|
|
|
fi
|
2023-03-20 11:58:45 -07:00
|
|
|
|
|
|
|
if [[ $VIM = "nvim" ]]; then
|
|
|
|
print -P " Downloading vim-plug from Github"
|
|
|
|
curl --create-dirs -fL \
|
|
|
|
-o "${XDG_DATA_HOME:-$HOME/.local/share}/nvim/site/autoload/plug.vim" \
|
|
|
|
"https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" \
|
|
|
|
1>/dev/null
|
|
|
|
|
|
|
|
if whence -cp python3 >& -; then
|
|
|
|
print -P " Installing pynvim"
|
|
|
|
python3 -m pip install --user --upgrade pynvim 1>/dev/null
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-03-20 08:40:57 -07:00
|
|
|
$VIM +PlugInstall +qall
|
2022-05-28 23:58:47 -07:00
|
|
|
fi
|
2018-04-15 19:14:41 -07:00
|
|
|
|
2025-08-11 17:12:14 -07:00
|
|
|
build_fortunes
|
|
|
|
|
2011-05-03 21:53:50 -07:00
|
|
|
exit 0
|