From 3256bc2ce259a77f5718e83bd4d87a67455aeb26 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 13 Jan 2023 20:06:51 -0700 Subject: hstow: factor out disjoin_hstow_file, replacing read_globs_file --- bin/hstow | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'bin/hstow') diff --git a/bin/hstow b/bin/hstow index d20f502c..9f34add6 100755 --- a/bin/hstow +++ b/bin/hstow @@ -2,7 +2,7 @@ # hstow -- POSIX sh minimal reimplementation of GNU Stow for dotfiles # -# Copyright (C) 2022 Sean Whitton +# Copyright (C) 2022-2023 Sean Whitton # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -44,10 +44,10 @@ if ! command -v readlink >/dev/null; then } fi -read_globs_file () { +disjoin_hstow_file () { if [ -e "$DIR/$1" ]; then while read -r line; do - printf "|./%s" "$line" + printf "|$2" "$line" done <"$DIR/$1" | cut -c2- fi } @@ -72,13 +72,14 @@ stow () { [ -h "$HOME/.STOW/$NAME" ] \ || ( cd "$HOME/.STOW"; ln -s "$DIR" "$NAME" ) conflicts= - ignores="$(read_globs_file .hstow-local-ignore)" + ignores="$(disjoin_hstow_file .hstow-local-ignore "./%s")" # Files that (i) always/often have their symlinks replaced with # regular files when applications access them; and (ii) we don't # ever want to edit the copy under $DIR directly, but only via the # link/copy under $HOME. - $always_adopt || adoptions="$(read_globs_file .hstow-always-adopt)" + $always_adopt \ + || adoptions="$(disjoin_hstow_file .hstow-always-adopt "./%s")" for file in $(find . ! -name . ! -type d ! -name "$cchars" \ ! -name .gitignore \ @@ -134,13 +135,10 @@ unstow () { cd "$HOME" # For speed, skip directories into which we'll never stow anything. - ignores="$([ -e "$DIR/.hstow-unstow-ignore" ] || exit 0 - while read -r line; do - printf "|./%s/" "$line" - done <"$DIR/.hstow-unstow-ignore")" + ignores="$(disjoin_hstow_file .hstow-unstow-ignore "./%s/")" dir_pat=".$(echo $DIR | cut -c$(echo $HOME | wc -m | tr -d ' ')-)/" - dirs_pat="$(echo "^($dir_pat$ignores)" | sed -e 's#\.#\\.#g')" + dirs_pat="$(echo "^($dir_pat|$ignores)" | sed -e 's#\.#\\.#g')" for file in $(find . ! \( -user "$(id -un)" -o -group "$(id -gn)" \) \ -prune -o -type l ! -name . ! -name "$cchars" -print \ | grep -Ev "$dirs_pat"); do -- cgit v1.2.3