diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2023-01-13 20:06:51 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2023-01-13 20:06:51 -0700 |
commit | 3256bc2ce259a77f5718e83bd4d87a67455aeb26 (patch) | |
tree | e84aa5b7cdca25aea2f659c2f29cbfa1338aa7e8 /bin/hstow | |
parent | 1d1b898189dd2d891edb7d0c6abc2cfab042e39d (diff) | |
download | dotfiles-3256bc2ce259a77f5718e83bd4d87a67455aeb26.tar.gz |
hstow: factor out disjoin_hstow_file, replacing read_globs_file
Diffstat (limited to 'bin/hstow')
-rwxr-xr-x | bin/hstow | 18 |
1 files changed, 8 insertions, 10 deletions
@@ -2,7 +2,7 @@ # hstow -- POSIX sh minimal reimplementation of GNU Stow for dotfiles # -# Copyright (C) 2022 Sean Whitton <spwhitton@spwhitton.name> +# Copyright (C) 2022-2023 Sean Whitton <spwhitton@spwhitton.name> # # 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 |