summaryrefslogtreecommitdiff
path: root/bin/hstow
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2023-01-13 20:06:51 -0700
committerSean Whitton <spwhitton@spwhitton.name>2023-01-13 20:06:51 -0700
commit3256bc2ce259a77f5718e83bd4d87a67455aeb26 (patch)
treee84aa5b7cdca25aea2f659c2f29cbfa1338aa7e8 /bin/hstow
parent1d1b898189dd2d891edb7d0c6abc2cfab042e39d (diff)
downloaddotfiles-3256bc2ce259a77f5718e83bd4d87a67455aeb26.tar.gz
hstow: factor out disjoin_hstow_file, replacing read_globs_file
Diffstat (limited to 'bin/hstow')
-rwxr-xr-xbin/hstow18
1 files changed, 8 insertions, 10 deletions
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 <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