install: convert to tabstop = 2

This commit is contained in:
Fernando Schauenburg 2022-02-07 20:14:24 +01:00
parent 85dd0a4838
commit 56865870ec

View file

@ -9,59 +9,59 @@ GIT_USER="${GIT_USER:-Fernando Schauenburg}"
GIT_EMAIL="${GIT_EMAIL:-fernando@schauenburg.me}" GIT_EMAIL="${GIT_EMAIL:-fernando@schauenburg.me}"
main() { main() {
IS_DRY_RUN=yes IS_DRY_RUN=yes
while getopts 'fht:' opt; do case "$opt" in while getopts 'fht:' opt; do case "$opt" in
f) unset IS_DRY_RUN;; f) unset IS_DRY_RUN;;
t) TARGET="$OPTARG";; t) TARGET="$OPTARG";;
h) usage; exit 0;; h) usage; exit 0;;
*) usage; exit 1;; *) usage; exit 1;;
esac done esac done
check_dependencies check_dependencies
greeting greeting
make_dirs make_dirs
stow_home stow_home
link_config link_config
git_user_config git_user_config
nvim_plugins nvim_plugins
} }
check_dependencies() { check_dependencies() {
for cmd in stow readlink; do for cmd in stow readlink; do
if ! command -v "$cmd" >/dev/null 2>&1; then if ! command -v "$cmd" >/dev/null 2>&1; then
error "Dependency \`$cmd\` not found." error "Dependency \`$cmd\` not found."
exit 1 exit 1
fi fi
done done
} }
greeting() { greeting() {
dry_run && { dry_run && {
warn "Performing dry run (use -f to actually make changes)." warn "Performing dry run (use -f to actually make changes)."
warn warn
} }
info "Deploying dotfiles:" info "Deploying dotfiles:"
info " Source: $cyan$DOTFILES$rst" info " Source: $cyan$DOTFILES$rst"
info " Target: $cyan$TARGET$rst" info " Target: $cyan$TARGET$rst"
info " Git user: $yellow$GIT_USER <$GIT_EMAIL>$rst" info " Git user: $yellow$GIT_USER <$GIT_EMAIL>$rst"
if [ -t 0 -a -t 1 ]; then if [ -t 0 -a -t 1 ]; then
info info
info "Press ENTER to continue (CTRL-C to cancel)..." info "Press ENTER to continue (CTRL-C to cancel)..."
read k read k
fi fi
} }
make_dirs() { make_dirs() {
heading 'create auxiliary directories' heading 'create auxiliary directories'
while read item; do while read item; do
dir="$TARGET/$item" dir="$TARGET/$item"
if [ ! -d "$dir" ]; then if [ ! -d "$dir" ]; then
echo "${yellow}MKDIR:$rst $dir" echo "${yellow}MKDIR:$rst $dir"
dry_run || mkdir -p "$dir" dry_run || mkdir -p "$dir"
fi fi
done <<EOF done <<EOF
.local/share/less/ .local/share/less/
.local/share/python/ .local/share/python/
.local/share/nvim/shada/ .local/share/nvim/shada/
@ -71,34 +71,34 @@ EOF
} }
link_config() { link_config() {
heading 'link .config directory' heading 'link .config directory'
link="$TARGET/.config" link="$TARGET/.config"
dotfiles_config="$DOTFILES/config" dotfiles_config="$DOTFILES/config"
backup="$TARGET/old_dot_config" backup="$TARGET/old_dot_config"
if [ "$(readlink "$link")" != "$dotfiles_config" ]; then if [ "$(readlink "$link")" != "$dotfiles_config" ]; then
if [ -d "$link" ]; then if [ -d "$link" ]; then
echo "${red}WARNING:$rst moving existing '$link' to '$backup'" echo "${red}WARNING:$rst moving existing '$link' to '$backup'"
dry_run || mv "$link" "$backup" dry_run || mv "$link" "$backup"
fi
echo "${yellow}LINK:$rst $link $blue=>$rst $dotfiles_config"
dry_run || ln -s "$dotfiles_config" "$link"
fi fi
echo "${yellow}LINK:$rst $link $blue=>$rst $dotfiles_config"
dry_run || ln -s "$dotfiles_config" "$link"
fi
} }
stow_home() { stow_home() {
heading 'stow home directory' heading 'stow home directory'
stow -v${IS_DRY_RUN:+n} --no-folding -d "$DOTFILES" -t "$TARGET" home 2>&1 \ stow -v${IS_DRY_RUN:+n} --no-folding -d "$DOTFILES" -t "$TARGET" home 2>&1 \
| sed -E -e "s/^([^:]+:)/$yellow\1$rst/" -e "s/=>/$blue=>$rst/" | sed -E -e "s/^([^:]+:)/$yellow\1$rst/" -e "s/=>/$blue=>$rst/"
} }
git_user_config() { git_user_config() {
heading 'git user configuration' heading 'git user configuration'
config_file="$TARGET/.local/etc/git/config.user" config_file="$TARGET/.local/etc/git/config.user"
temp_git="$(mktemp)" temp_git="$(mktemp)"
cat >"$temp_git" <<EOF cat >"$temp_git" <<EOF
# ************************************* # *************************************
# * DO NOT EDIT THIS FILE * # * DO NOT EDIT THIS FILE *
# ************************************* # *************************************
@ -109,33 +109,29 @@ git_user_config() {
# ~/.local/etc/git/config # ~/.local/etc/git/config
# #
EOF EOF
git config -f "$temp_git" user.name "${GIT_USER}" git config -f "$temp_git" user.name "${GIT_USER}"
git config -f "$temp_git" user.email "${GIT_EMAIL}" git config -f "$temp_git" user.email "${GIT_EMAIL}"
if ! diff "$config_file" "$temp_git" >/dev/null 2>&1; then if ! diff "$config_file" "$temp_git" >/dev/null 2>&1; then
if [ -f "$config_file" ]; then if [ -f "$config_file" ]; then action=OVERWRITE; else action=CREATE; fi
action=OVERWRITE echo "$yellow$action:$rst $config_file with contents of $temp_git:"
else echo "$cyan"
action=CREATE cat "$temp_git"
fi echo "$rst"
echo "$yellow$action:$rst $config_file with contents of $temp_git:" dry_run || cp -f "$temp_git" "$config_file"
echo "$cyan" fi
cat "$temp_git"
echo "$rst"
dry_run || cp -f "$temp_git" "$config_file"
fi
} }
nvim_plugins() { nvim_plugins() {
heading 'nvim plugins' heading 'nvim plugins'
if command -v nvim >/dev/null 2>&1; then if command -v nvim >/dev/null 2>&1; then
dry_run || { dry_run || {
warn "installing neovim plugins..." warn "installing neovim plugins..."
nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync' nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'
} }
else else
error "neovim is not installed; skipping plugin installation..." error "neovim is not installed; skipping plugin installation..."
fi fi
} }
############################################################################### ###############################################################################
@ -143,31 +139,31 @@ nvim_plugins() {
############################################################################### ###############################################################################
if [ -t 1 ]; then if [ -t 1 ]; then
rst=$(tput sgr0) rst=$(tput sgr0)
red=$(tput setaf 1) red=$(tput setaf 1)
green=$(tput setaf 2) green=$(tput setaf 2)
yellow=$(tput setaf 3) yellow=$(tput setaf 3)
blue=$(tput setaf 4) blue=$(tput setaf 4)
magenta=$(tput setaf 5) magenta=$(tput setaf 5)
cyan=$(tput setaf 6) cyan=$(tput setaf 6)
else else
rst='' rst=''
red='' red=''
green='' green=''
yellow='' yellow=''
blue='' blue=''
magenta='' magenta=''
cyan='' cyan=''
fi fi
dry_run() { [ -n "$IS_DRY_RUN" ]; } dry_run() { [ -n "$IS_DRY_RUN" ]; }
usage() { usage() {
echo "Usage: $(basename $0) [-h] [-f] [-t <target>]" echo "Usage: $(basename $0) [-h] [-f] [-t <target>]"
echo "" echo ""
echo " -h print this help and exit" echo " -h print this help and exit"
echo " -f modify filesystem rather than dry run" echo " -f modify filesystem rather than dry run"
echo " -t set <target> directory (default: \$HOME)" echo " -t set <target> directory (default: \$HOME)"
} }
heading() { printf '%s\n' "${blue}===== $1 ==========${rst}"; } heading() { printf '%s\n' "${blue}===== $1 ==========${rst}"; }