Reorganize packages and simplify bootstrap

This commit is contained in:
Fernando Schauenburg 2021-11-18 00:21:57 +01:00
parent 8100eb287d
commit fffb78e27e
48 changed files with 96 additions and 2959 deletions

2
.gitattributes vendored
View file

@ -1,2 +1,2 @@
ssh/ssh_config filter=git-crypt diff=git-crypt ssh/.ssh/config filter=git-crypt diff=git-crypt

1
git/.local/etc/git/.keep Normal file
View file

@ -0,0 +1 @@
directory for extra git configurations

View file

@ -5,7 +5,7 @@ export DOTFILES="$(dirname "$(realpath "$0")")"
export DEFAULT_GIT_USER="Fernando Schauenburg" export DEFAULT_GIT_USER="Fernando Schauenburg"
export DEFAULT_GIT_EMAIL="fernando@schauenburg.me" export DEFAULT_GIT_EMAIL="fernando@schauenburg.me"
. "$DOTFILES/zsh/zshenv" . "$DOTFILES/zsh/.zshenv"
[ -f "$DOTFILES/config" ] && . "$DOTFILES/config" [ -f "$DOTFILES/config" ] && . "$DOTFILES/config"
main() { main() {
@ -17,19 +17,71 @@ main() {
esac done esac done
greeting greeting
deploy_alacritty deploy_packages
deploy_bin bin_extras
deploy_git git_extras
deploy_jupyter nvim_extras
deploy_mintty }
deploy_misc
deploy_nvim greeting() {
deploy_python dry_run && {
deploy_readline warn "Performing dry run (use -f to actually make changes)."
deploy_ssh warn ""
deploy_tmux }
deploy_x11
deploy_zsh git_info="${GIT_USER:-$DEFAULT_GIT_USER} <${GIT_EMAIL:-$DEFAULT_GIT_EMAIL}>"
info "Deploying with git user $cyan$git_info$rst"
[ -t 0 ] && {
info "Press ENTER to continue (CTRL-C to cancel)..."
read k
}
}
deploy_packages() {
for f in *; do
[ -d "$f" ] && {
heading "$f"
deploy "$f"
}
done
}
bin_extras() {
heading 'stale ~/.local/bin commands'
for cmd in $HOME/.local/bin/*; do prune_cmd "$cmd"; done;
}
git_extras() {
heading 'git user configuration'
temp_git="$(mktemp)"
cat >"$temp_git" <<EOF
# *************************************
# * DO NOT EDIT THIS FILE *
# *************************************
#
# This file was generated by the bootstrap script and any changes will be
# overwritten the next time it is run. For local settings, use this instead:
#
# ~/.local/etc/git/config
#
EOF
git config -f "$temp_git" user.name "${GIT_USER:-$DEFAULT_GIT_USER}"
git config -f "$temp_git" user.email "${GIT_EMAIL:-$DEFAULT_GIT_EMAIL}"
equal_content "$HOME/.local/etc/git/config.user" "$temp_git"
}
nvim_extras() {
heading 'nvim plugins'
if command -v nvim >/dev/null 2>&1; then
dry_run || {
change "installing neovim plugins..."
nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'
}
else
error "neovim is not installed; skipping plugin installation..."
fi
} }
############################################################################### ###############################################################################
@ -64,41 +116,19 @@ usage() {
} }
heading() { printf '%s\n' "${blue}===== $1 ==========${rst}"; } heading() { printf '%s\n' "${blue}===== $1 ==========${rst}"; }
info() { printf '%s ' "$@"; printf '\n'; } info() { printf '%s ' "$@"; printf '\n'; }
ok() { printf '%s ' "${green}OK:${rst}" "$@"; printf '\n'; } ok() { printf '%s ' "${green}OK:${rst}" "$@"; printf '\n'; }
warn() { printf '%s ' "${yellow}$@${rst}"; printf '\n'; } change() { printf '%s ' "${yellow}CHANGE:${rst}" "$@"; printf '\n'; }
error() { printf '%s ' "${red}$@${rst}"; printf '\n'; } warn() { printf '%s ' "${yellow}$@${rst}"; printf '\n'; }
error() { printf '%s ' "${red}$@${rst}"; printf '\n'; }
greeting() {
dry_run && info "Dry run: no changes will be made to filesytem (use -f to override)."
info "Deploying with git user $yellow${GIT_USER:-$DEFAULT_GIT_USER} <${GIT_EMAIL:-$DEFAULT_GIT_EMAIL}>$rst"
[ -t 0 ] && {
info "Press ENTER to continue (CTRL-C to cancel)..."
read k
}
}
# Make sure directory $1 exists. # Make sure directory $1 exists.
ensure_directory() { ensure_directory() {
[ -d "$1" ] && { ok "$1/"; return; } [ -d "$1" ] && return
warn "creating $1/" change "MKDIR $1/"
dry_run || mkdir -p "$1/" dry_run || mkdir -p "$1/"
} }
# Make sure file $1 does not exist.
remove_file() {
[ ! -f "$1" ] && { ok "$1"; return; }
warn "removing $1"
dry_run || rm "$1"
}
# Make sure file $1 exists (content is irrelevant).
touch_file() {
[ -f "$1" ] && { ok "$1"; return; }
warn "creating $1"
dry_run || touch "$1"
}
# Remove $1 if it's a broken link to a dotfile script. # Remove $1 if it's a broken link to a dotfile script.
prune_cmd() { prune_cmd() {
if [ -h "$1" ]; then # it's a symbolic link... if [ -h "$1" ]; then # it's a symbolic link...
@ -106,7 +136,7 @@ prune_cmd() {
case "$target" in case "$target" in
"$DOTFILES/bin/"*) # ... pointing into dotfiles bin "$DOTFILES/bin/"*) # ... pointing into dotfiles bin
if [ ! -e "$1" ]; then # target of the link missing if [ ! -e "$1" ]; then # target of the link missing
warn "removing stale link $1 -> $target" change "UNLINK (stale) $1 -> $target"
dry_run || rm -f "$1" dry_run || rm -f "$1"
fi fi
;; ;;
@ -118,145 +148,35 @@ prune_cmd() {
link() { link() {
target="$(realpath -s "$1")" target="$(realpath -s "$1")"
[ "$(readlink "$2")" = "$target" ] && { ok "$2"; return; } [ "$(readlink "$2")" = "$target" ] && { ok "$2"; return; }
warn "linking $2 -> $target" change "LINK $2 -> $target"
dry_run || ln -sf "$target" "$2" dry_run || ln -sf "$target" "$2"
} }
# Ensure $1 and $2 contents are equal, updating $1 if needed. # Ensure $1 and $2 contents are equal, updating $1 if needed.
equal_content() { equal_content() {
diff "$1" "$2" >/dev/null 2>&1 && { ok "$1"; return; } diff "$1" "$2" >/dev/null 2>&1 && { ok "$1"; return; }
warn "overwriting $1 with $2:" change "OVERWRITE $1 with $2:"
echo "$cyan"
cat "$2" cat "$2"
echo "$rst"
dry_run || cp -f "$2" "$1" dry_run || cp -f "$2" "$1"
} }
############################################################################### relative_path() {
# Configuration Deployments python -c "import os.path; print os.path.relpath('$1','${2:-$PWD}')"
###############################################################################
deploy_alacritty() {
heading 'alacritty'
ensure_directory "$XDG_CONFIG_HOME/alacritty"
link "$DOTFILES/alacritty/alacritty.yml" "$XDG_CONFIG_HOME/alacritty/alacritty.yml"
} }
deploy_bin() { deploy() {
heading 'bin' find "$1" -type f -print0 | while read -d $'\0' src; do
ensure_directory "$HOME/.local/bin" src_dir="$(dirname "$src")"
for cmd in $HOME/.local/bin/*; do prune_cmd "$cmd"; done dest_dir="$HOME${src_dir##"$1"}"
for cmd in "$DOTFILES/bin/"*; do ensure_directory "$dest_dir"
link "$cmd" "$HOME/.local/bin/$(basename "$cmd")"
filename="$(basename "$src")"
[ "$filename" = '.keep' ] && continue
link "$src" "$dest_dir/$filename"
done done
} }
deploy_git() {
heading 'git'
ensure_directory "$XDG_CONFIG_HOME/git"
ensure_directory "${HOME}/.local/etc/git"
link "$DOTFILES/git/gitconfig" "$XDG_CONFIG_HOME/git/config"
link "$DOTFILES/git/gitignore" "$XDG_CONFIG_HOME/git/ignore"
temp_git="$(mktemp)"
cat >"$temp_git" <<EOF
# *************************************
# * DO NOT EDIT THIS FILE *
# *************************************
#
# This file was generated by the bootstrap script and any changes will be
# overwritten the next time it is run. For local settings, use this instead:
#
# ~/.local/etc/git/config
#
EOF
git config -f "$temp_git" user.name "${GIT_USER:-$DEFAULT_GIT_USER}"
git config -f "$temp_git" user.email "${GIT_EMAIL:-$DEFAULT_GIT_EMAIL}"
equal_content "$HOME/.local/etc/git/config.user" "$temp_git"
}
deploy_jupyter() {
heading 'jupyter'
ensure_directory "${HOME}/.jupyter/custom"
ensure_directory "${HOME}/.jupyter/nbconfig"
link "$DOTFILES/jupyter/custom.js" "${HOME}/.jupyter/custom/custom.js"
link "$DOTFILES/jupyter/notebook.json" "${HOME}/.jupyter/nbconfig/notebook.json"
}
deploy_mintty() {
heading 'mintty'
ensure_directory "$XDG_CONFIG_HOME/mintty"
ensure_directory "$XDG_CONFIG_HOME/mintty/themes"
link "$DOTFILES/mintty/minttyrc" "$XDG_CONFIG_HOME/mintty/config"
link "$DOTFILES/mintty/solarized-dark" "$XDG_CONFIG_HOME/mintty/themes/solarized-dark"
link "$DOTFILES/mintty/solarized-light" "$XDG_CONFIG_HOME/mintty/themes/solarized-light"
}
deploy_misc() {
heading 'miscelaneous'
ensure_directory "$XDG_DATA_HOME/less" # for history
touch_file "$HOME/.hushlogin"
}
deploy_nvim() {
heading 'nvim'
remove_file "$XDG_CONFIG_HOME/nvim/init.vim"
ensure_directory "$XDG_DATA_HOME/nvim/shada"
link "$DOTFILES/nvim/init.lua" "$XDG_CONFIG_HOME/nvim/init.lua"
ensure_directory "$XDG_CONFIG_HOME/nvim/lua/fs"
for f in nvim/lua/fs/*; do link "$DOTFILES/$f" "$XDG_CONFIG_HOME/$f"; done
unset f
ensure_directory "$XDG_CONFIG_HOME/nvim/after/plugin"
for f in nvim/after/plugin/*; do link "$DOTFILES/$f" "$XDG_CONFIG_HOME/$f"; done
unset f
if command -v nvim >/dev/null 2>&1; then
warn "installing neovim plugins..."
dry_run || nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'
else
error "neovim is not installed; skipping plugin installation..."
fi
}
deploy_python() {
heading 'python'
ensure_directory "$XDG_CONFIG_HOME/python"
ensure_directory "$XDG_DATA_HOME/python" # for history
link "$DOTFILES/python/startup.py" "$XDG_CONFIG_HOME/python/startup.py"
}
deploy_readline() {
heading 'readline'
ensure_directory "$XDG_CONFIG_HOME/readline"
link "$DOTFILES/readline/inputrc" "$XDG_CONFIG_HOME/readline/inputrc"
}
deploy_ssh() {
heading 'ssh'
ensure_directory "${HOME}/.ssh"
link "$DOTFILES/ssh/ssh_config" "${HOME}/.ssh/config"
}
deploy_tmux() {
ensure_directory "$XDG_CONFIG_HOME/tmux"
link "$DOTFILES/tmux/tmux.conf" "$XDG_CONFIG_HOME/tmux/tmux.conf"
}
deploy_x11() {
heading 'X11'
link "$DOTFILES/x11/xcompose" ${HOME}/.XCompose
}
deploy_zsh() {
heading 'zsh'
ensure_directory "$ZDOTDIR"
ensure_directory "$XDG_DATA_HOME/zsh" # for history
link "$DOTFILES/zsh/zshenv" "$HOME/.zshenv"
link "$DOTFILES/zsh/zshrc" "$ZDOTDIR/.zshrc"
link "$DOTFILES/zsh/aliases" "$ZDOTDIR/aliases"
link "$DOTFILES/zsh/prompt" "$ZDOTDIR/prompt"
link "$DOTFILES/zsh/vi-mode" "$ZDOTDIR/vi-mode"
}
main "$@" main "$@"

0
misc/.hushlogin Normal file
View file

View file

@ -0,0 +1 @@
directory for less(1) history

View file

@ -0,0 +1 @@
nvim SHAred DAta directory

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1 @@
directory for python REPL history

View file

@ -0,0 +1 @@
directory for zsh history