#!/usr/bin/env zsh dotfiles_dir=$(cd "$(dirname "$0")" && pwd) sys=`uname -s | tr A-Z a-z` 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 \ ) function print-heading { print -P "%B==>%b $@" } # 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 fi if (( $should_install )); then print "Link $dst" install -ls "$src" "$dst" return 0 else print "Skip $dst" return 1 fi } function build_fortunes { print-heading Building fortunes file (cd Fortune && make) } print -P " %BHome:%b $HOME" print -P " %BDotfiles:%b $dotfiles_dir\n" print-heading Symlinking config files local did_link_at_least_one_dotfile=0 for (( idx = 1; idx <= $#items; idx += 2 )); do local dotfile=$items[$idx] local dest=$items[$idx+1] if link "$dotfile" "$dest"; then did_link_at_least_one_dotfile=1 fi done local configure_vim=1 local hush_login=0 while getopts "vl" arg $@; do case $arg in "v") configure_vim=1 ;; "+v") configure_vim=0 ;; "l") hush_login=1 ;; "+l") hush_login=0 ;; *) 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 ;; esac done 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 if (( $configure_vim )); then print-heading Configuring neovim and vim print-heading "Downloading vim-plug from Github" 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 # 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 fi command nvim +PlugInstall +qall fi build_fortunes