summaryrefslogtreecommitdiff
path: root/bin/hstow
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2023-01-19 09:52:34 -0700
committerSean Whitton <spwhitton@spwhitton.name>2023-01-19 11:00:59 -0700
commit8ab0e26154e513a9d1f65757be56bc36037b3621 (patch)
tree4bbebaa46bfad8b3dd7bb36d1d43cfd79eeeaf26 /bin/hstow
parentc50e6e4519d7c4bfd8fe1e642bf6c565a0106222 (diff)
downloaddotfiles-8ab0e26154e513a9d1f65757be56bc36037b3621.tar.gz
hstow: readlinks: handle add'l fields, check that input names a link
Diffstat (limited to 'bin/hstow')
-rwxr-xr-xbin/hstow16
1 files changed, 11 insertions, 5 deletions
diff --git a/bin/hstow b/bin/hstow
index c10b4907..3fce0a72 100755
--- a/bin/hstow
+++ b/bin/hstow
@@ -53,10 +53,16 @@ fi
# Here we unconditionally bypass readlink(1), for speed.
# The long regexp is because only BREs have backreferences in POSIX.
readlinks () {
- while read -r line; do
- printf '%s\t%s\n' "$line" "$(ls -ld "$line")"
- done | sed \
-'s/\([^\t]*\)\t\([^[:blank:]]\{1,\}[[:blank:]]\{1,\}\)\{8\}\1 -> /\1\t/'
+ local restc=$1 assume="${2:-false}" first= rest=
+ while read -r first rest; do
+ if $assume || [ -h "$first" ]; then
+ [ -n "$rest" ] && rest="$rest$tab"
+ rest="$rest$(ls -ld "$first")"
+ fi
+ printf '%s\t%s\n' "$first" "$rest"
+ done | sed 's/^\([^\t]\{1,\}\)\t\('\
+"$(printf "%${restc}s" | sed 's/ /[^\\t]\\{1,\\}\\t/g')"\
+'\)\([^[:blank:]]\{1,\}[[:blank:]]\{1,\}\)\{8\}\1 -> /\1\t\2/'
}
disjoin_hstow_file () {
@@ -157,7 +163,7 @@ unstow () {
for file in \
$(find . ! \( -user "$(id -un)" -o -group "$(id -gn)" \) \
-prune -o -type l ! -name . ! -name "$cchars" -print \
- | grep -Ev "$dirs_pat" | readlinks | awk -F'\t' \
+ | grep -Ev "$dirs_pat" | readlinks 0 true | awk -F'\t' \
'$2 ~ /^(\.\.\/)*\.STOW\/'"$NAME"'\// { print $1 }'); do
rm "$file"
while true; do