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
|
|
|
|
2026-02-07 18:41:56 -08:00
|
|
|
items=( \
|
|
|
|
|
emacs .config/emacs \
|
|
|
|
|
fish .config/fish \
|
|
|
|
|
git .config/git \
|
|
|
|
|
hgrc .hgrc
|
|
|
|
|
mutt .config/mutt \
|
|
|
|
|
nethackrc .nethackrc \
|
|
|
|
|
nvim .config/nvim \
|
|
|
|
|
tmux .config/tmux \
|
|
|
|
|
vim .config/vim \
|
|
|
|
|
zsh/zprofile .zprofile \
|
|
|
|
|
zsh/zshenv .zshenv \
|
|
|
|
|
zsh/zshrc .zshrc \
|
2025-08-11 17:08:07 -07:00
|
|
|
)
|
2013-01-23 11:11:52 -08:00
|
|
|
|
2026-02-07 18:41:56 -08:00
|
|
|
function print-heading
|
|
|
|
|
{
|
|
|
|
|
print -P "%B==>%b $@"
|
|
|
|
|
}
|
2022-01-23 11:27:16 -08:00
|
|
|
|
2026-02-07 18:41:56 -08:00
|
|
|
# link --
|
|
|
|
|
#
|
|
|
|
|
# Link a source file (in the repo) to a destination path in the user's home
|
|
|
|
|
# directory. If the file already exists AND it's a symlink AND it points to the
|
|
|
|
|
# source path, it will be skipped.
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
|
|
|
|
# $1 : a "source" path to a file, relative to the dotfiles repo root
|
|
|
|
|
# $2 : a "destination" path, relative to the user's home directory
|
|
|
|
|
#
|
|
|
|
|
# Returns: 0 if the dotfile was installed, 1 otherwise
|
|
|
|
|
function link
|
|
|
|
|
{
|
|
|
|
|
local src="$dotfiles_dir/$1"
|
|
|
|
|
local dst="$HOME/$2"
|
|
|
|
|
|
|
|
|
|
local should_install=1
|
|
|
|
|
if [[ -e "$dst" ]]; then
|
|
|
|
|
if [[ -h "$dst" ]]; then
|
|
|
|
|
local link_target=$(readlink "$dst")
|
|
|
|
|
if [[ "$link_target" == "$src" ]]; then
|
|
|
|
|
should_install=0
|
|
|
|
|
fi
|
|
|
|
|
elif [[ -f "$dst" ]]; then
|
|
|
|
|
should_install=0
|
|
|
|
|
else
|
|
|
|
|
echo "$dst is not a regular file or symbolic link"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
2014-09-02 09:37:45 -07:00
|
|
|
fi
|
|
|
|
|
|
2026-02-07 18:41:56 -08:00
|
|
|
if (( $should_install )); then
|
|
|
|
|
print "Link $dst"
|
|
|
|
|
install -ls "$src" "$dst"
|
|
|
|
|
return 0
|
2014-09-02 09:37:45 -07:00
|
|
|
else
|
2026-02-07 18:41:56 -08:00
|
|
|
print "Skip $dst"
|
|
|
|
|
return 1
|
2014-09-02 09:37:45 -07:00
|
|
|
fi
|
2022-12-13 14:09:36 -08:00
|
|
|
}
|
|
|
|
|
|
2025-08-11 17:12:14 -07:00
|
|
|
function build_fortunes {
|
2026-02-07 18:41:56 -08:00
|
|
|
print-heading Building fortunes file
|
2025-08-11 17:12:14 -07:00
|
|
|
(cd Fortune && make)
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-28 23:58:47 -07:00
|
|
|
print -P " %BHome:%b $HOME"
|
2026-02-07 18:41:56 -08:00
|
|
|
print -P " %BDotfiles:%b $dotfiles_dir\n"
|
2022-01-23 11:27:16 -08:00
|
|
|
|
2026-02-07 18:41:56 -08:00
|
|
|
print-heading Symlinking config files
|
2014-09-02 09:37:45 -07:00
|
|
|
|
2022-01-23 11:27:16 -08:00
|
|
|
local did_link_at_least_one_dotfile=0
|
2026-02-07 18:41:56 -08:00
|
|
|
for (( idx = 1; idx <= $#items; idx += 2 )); do
|
|
|
|
|
local dotfile=$items[$idx]
|
|
|
|
|
local dest=$items[$idx+1]
|
2022-12-13 14:09:36 -08:00
|
|
|
|
2026-02-07 18:41:56 -08:00
|
|
|
if link "$dotfile" "$dest"; then
|
|
|
|
|
did_link_at_least_one_dotfile=1
|
2022-01-23 11:27:16 -08:00
|
|
|
fi
|
2012-04-11 09:54:43 -07:00
|
|
|
done
|
|
|
|
|
|
2023-03-20 11:58:45 -07:00
|
|
|
local configure_vim=1
|
2026-02-07 18:41:56 -08:00
|
|
|
local hush_login=0
|
|
|
|
|
while getopts "vl" arg $@; do
|
2022-12-13 14:09:36 -08:00
|
|
|
case $arg in
|
2023-03-20 11:58:45 -07:00
|
|
|
"v") configure_vim=1 ;;
|
|
|
|
|
"+v") configure_vim=0 ;;
|
2026-02-07 18:41:56 -08:00
|
|
|
"l") hush_login=1 ;;
|
|
|
|
|
"+l") hush_login=0 ;;
|
2022-12-13 14:09:36 -08:00
|
|
|
*)
|
2026-02-07 18:41:56 -08:00
|
|
|
local script_name=$(basename $0)
|
|
|
|
|
echo "Usage: $script_name [+l|-l] [+v|-v]"
|
|
|
|
|
echo " +l|-l Tell the shell not to print last login information. (default: no)"
|
|
|
|
|
echo " +v|-v Install (neo)vim plugins. (default: yes)"
|
|
|
|
|
exit 1
|
2022-12-13 14:09:36 -08:00
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
2026-02-07 18:41:56 -08:00
|
|
|
if (( $hush_login )); then
|
|
|
|
|
if [[ ! -a "$HOME/.hushlogin" ]]; then
|
|
|
|
|
print " touch $HOME/.hushlogin"
|
|
|
|
|
touch "$HOME/.hushlogin"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
local venv_path="${XDG_DATA_HOME:-$HOME/.local/share}/python-virtual-environments/eryn"
|
|
|
|
|
if [[ ! -d "$venv_path" ]]; then
|
|
|
|
|
print-heading "Creating Python virtual environment"
|
|
|
|
|
python3 -m venv --system-site-packages "$venv_path"
|
|
|
|
|
"$venv_path/bin/pip" install "$dotfiles_dir/Python/eryntools"
|
|
|
|
|
fi
|
2024-03-05 11:06:26 -08:00
|
|
|
|
2023-03-20 11:58:45 -07:00
|
|
|
if (( $configure_vim )); then
|
2026-02-07 18:41:56 -08:00
|
|
|
print-heading Configuring neovim and vim
|
2011-05-03 21:53:50 -07:00
|
|
|
|
2026-02-07 18:41:56 -08:00
|
|
|
print-heading "Downloading vim-plug from Github"
|
2023-03-20 11:58:45 -07:00
|
|
|
|
2026-02-07 18:41:56 -08:00
|
|
|
local tmp_file="/tmp/vim-plug.vim"
|
|
|
|
|
curl --create-dirs -fL \
|
|
|
|
|
-o "$tmp_file" \
|
|
|
|
|
"https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" \
|
|
|
|
|
1>/dev/null
|
2023-03-20 11:58:45 -07:00
|
|
|
|
2026-02-07 18:41:56 -08:00
|
|
|
# nvim
|
|
|
|
|
install -m 0644 "$tmp_file" "${XDG_DATA_HOME:-$HOME/.local/share}/nvim/site/autoload/plug.vim"
|
|
|
|
|
# vim
|
|
|
|
|
install -m 0644 "$tmp_file" "${XDG_CONFIG_HOME:-$HOME/.config}/vim/autoload/plug.vim"
|
|
|
|
|
|
|
|
|
|
if whence -cp python3 >/dev/null; then
|
|
|
|
|
print-heading "Installing Python modules for vim and nvim"
|
|
|
|
|
python3 -m pip install --user --upgrade pynvim pyvim
|
2023-03-20 11:58:45 -07:00
|
|
|
fi
|
|
|
|
|
|
2026-02-07 18:41:56 -08:00
|
|
|
command nvim +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
|