From f4e3447eb7e37dc25272990f7e6459507e9715a9 Mon Sep 17 00:00:00 2001 From: David Tomaschik Date: Mon, 9 Feb 2026 23:11:54 -0800 Subject: [PATCH] Cleanup skel --- bin/backup.sh | 5 ++ bin/prune-broken-symlinks.sh | 46 ++++++++++++++ bin/setup/nerdfonts.sh | 25 +++++--- dotfiles/zshrc.d/prune-broken-symlinks.zsh | 4 +- install.sh | 74 ++++++++++++---------- 5 files changed, 108 insertions(+), 46 deletions(-) create mode 100755 bin/prune-broken-symlinks.sh diff --git a/bin/backup.sh b/bin/backup.sh index 0a0e671..468c533 100755 --- a/bin/backup.sh +++ b/bin/backup.sh @@ -3,6 +3,11 @@ set -o nounset set -o errexit +if [ "$(uname)" != "Linux" ]; then + echo "Error: This backup script is only intended for use on Linux." >&2 + exit 1 +fi + DEFAULT=`echo /media/${USER}/[bB]ackup/${USER}/` DEST="${1:-${DEFAULT}}" diff --git a/bin/prune-broken-symlinks.sh b/bin/prune-broken-symlinks.sh new file mode 100755 index 0000000..a9499ec --- /dev/null +++ b/bin/prune-broken-symlinks.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# shellcheck disable=SC2039,SC2086 + +set -o nounset + +prune_broken_symlinks() { + ask=1 + dir="." + + if [ "${1:-}" = "-y" ]; then + ask=0 + shift + fi + + if [ -n "${1:-}" ]; then + dir="$1" + fi + + # Check if there are any broken symlinks first + broken_links=$(find -L "$dir" -xdev -type l -print 2>/dev/null) + if [ -z "$broken_links" ]; then + return 0 + fi + + if [ "$ask" -eq 1 ]; then + # Print broken links + echo "$broken_links" + + printf "Delete these links? [y/N] " + read -r reply + case "$reply" in + [yY]*) + ;; + *) + echo "Aborted." + return 0 + ;; + esac + fi + + # Perform deletion + find -L "$dir" -xdev -type l -exec rm -- {} + 2>/dev/null +} + +# Execute the function +prune_broken_symlinks "$@" diff --git a/bin/setup/nerdfonts.sh b/bin/setup/nerdfonts.sh index adc6221..e34fd23 100755 --- a/bin/setup/nerdfonts.sh +++ b/bin/setup/nerdfonts.sh @@ -2,7 +2,7 @@ set -ue -VER="v2.2.2" +VER="v3.4.0" FONTS=( https://github.com/ryanoasis/nerd-fonts/releases/download/${VER}/DejaVuSansMono.zip @@ -13,14 +13,21 @@ FONTS=( https://github.com/ryanoasis/nerd-fonts/releases/download/${VER}/OpenDyslexic.zip ) -FPATH=${HOME}/.fonts/nerdfonts -mkdir -p ${FPATH} -cd ${FPATH} +if [ "$(uname)" = "Darwin" ]; then + FPATH="${HOME}/Library/Fonts" +else + FPATH="${HOME}/.local/share/fonts/nerdfonts" +fi -for f in ${FONTS[@]}; do - BN=$(basename $f) - wget -O ${FPATH}/${BN} ${f} - unzip -o -d ${FPATH} ${FPATH}/${BN} +mkdir -p "${FPATH}" +cd "${FPATH}" + +for f in "${FONTS[@]}"; do + BN=$(basename "$f") + wget -O "${FPATH}/${BN}" "$f" + unzip -o -d "${FPATH}" "${FPATH}/${BN}" done -fc-cache -v +if command -v fc-cache >/dev/null 2>&1; then + fc-cache -v +fi diff --git a/dotfiles/zshrc.d/prune-broken-symlinks.zsh b/dotfiles/zshrc.d/prune-broken-symlinks.zsh index a7f3461..84b7249 100644 --- a/dotfiles/zshrc.d/prune-broken-symlinks.zsh +++ b/dotfiles/zshrc.d/prune-broken-symlinks.zsh @@ -22,10 +22,10 @@ prune-broken-symlinks() { echo ${FILES} echo -n 'Delete these links? [y/n] ' if read -q ; then - ${FINDCMD} -print0 | xargs -r -0 rm + ${FINDCMD} -exec rm {} + fi echo else - ${FINDCMD} -print0 | xargs -r -0 rm + ${FINDCMD} -exec rm {} + fi } diff --git a/install.sh b/install.sh index b0cff56..981ae97 100755 --- a/install.sh +++ b/install.sh @@ -12,16 +12,13 @@ HOME=${HOME:-$(cd ~ && pwd)} case $(uname) in Linux) FINDTYPE="-xtype" - MD5CMD="md5sum" ;; Darwin|*BSD) FINDTYPE="-type" - MD5CMD="md5 -q" ;; *) echo "Unknown OS: $(uname), guessing no GNU utils." FINDTYPE="-type" - MD5CMD="md5sum" ;; esac @@ -33,7 +30,14 @@ prerequisites() { if have_command zsh ; then case $- in *i*) - case "$(getent passwd "${USER}" | cut -d: -f7)" in + local shell_path + if [ "$(uname)" = "Darwin" ]; then + # dscl output is "UserShell: /bin/zsh" + shell_path="$(dscl . -read "/Users/${USER}" UserShell | awk '{print $2}')" + else + shell_path="$(getent passwd "${USER}" | cut -d: -f7)" + fi + case "${shell_path}" in */zsh) ;; *) @@ -91,7 +95,7 @@ install_basic_dir() { local SRCDIR="${1}" local DESTDIR="${2}" local file - find "${SRCDIR}" ${FINDTYPE} f -print | \ + find "${SRCDIR}" \( -name .git -o -name README.md -o -name .gitignore \) -prune -o ${FINDTYPE} f -print | \ while read -r file ; do local TARGET="${DESTDIR}/${file#"${SRCDIR}"/}" mkdir -p "$(dirname "${TARGET}")" @@ -174,30 +178,32 @@ install_keys() { setup_git_email() { local gc_local="${HOME}/.gitconfig.local" - if test -f "${gc_local}" ; then - return 0 + local current_email="" + + if [ -f "${gc_local}" ]; then + current_email=$(git config -f "${gc_local}" user.email || true) fi - if [ "${USER:0:5}" != "david" ] ; then - return 0 + + if [ -n "${GIT_EMAIL:-}" ]; then + # Use environment variable + git config -f "${gc_local}" user.email "${GIT_EMAIL}" + elif [ -n "${current_email}" ]; then + # Already has an email set + GIT_EMAIL="${current_email}" + else + # Prompt the user + echo -n "Enter git email (leave blank to skip): " >&2 + read -r GIT_EMAIL || true + if [ -n "${GIT_EMAIL}" ]; then + git config -f "${gc_local}" user.email "${GIT_EMAIL}" + fi fi - local domain="$(hostname -f | grep -E -o '[a-z0-9-]+\.[a-z0-9-]+$')" - case "$(echo "${domain}" | ${MD5CMD} | awk '{print $1}')" in - b21a24d528346ef7d3932306ed96ede5|a5ed434a3f5089b489576cceab824f25) - ;; - *) - return 0 - ;; - esac - echo -e "[user]\n email=${USER}@${domain}" > "${gc_local}" + export GIT_EMAIL } read_saved_prefs() { # Can't use basedir here as we don't have it yet - local old_pref_file="$(dirname "$0")/installed-prefs" local pref_file="$(dirname "$0")/.installed-prefs" - if [ -f "${old_pref_file}" ] && ! [ -f "${pref_file}" ] ; then - mv "${old_pref_file}" "${pref_file}" - fi if [ -f "${pref_file}" ] ; then verbose "Loading saved skel preferences from ${pref_file}" # source is a bashism @@ -223,15 +229,10 @@ echo_pref() { } cleanup() { - # Needs zsh - if ! have_command zsh ; then - return 0 + if [ -x "${BASEDIR}/bin/prune-broken-symlinks.sh" ]; then + "${BASEDIR}/bin/prune-broken-symlinks.sh" -y "${HOME}/.zshrc.d" + "${BASEDIR}/bin/prune-broken-symlinks.sh" -y "${HOME}/bin" fi - zsh >/dev/null 2>&1 <&2 + fi fi test "$MINIMAL" = 1 || { prerequisites