summaryrefslogtreecommitdiff
path: root/bin/hstow
diff options
context:
space:
mode:
Diffstat (limited to 'bin/hstow')
-rwxr-xr-xbin/hstow34
1 files changed, 21 insertions, 13 deletions
diff --git a/bin/hstow b/bin/hstow
index 311fce2a..c10b4907 100755
--- a/bin/hstow
+++ b/bin/hstow
@@ -50,6 +50,15 @@ if ! command -v readlink >/dev/null; then
}
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/'
+}
+
disjoin_hstow_file () {
if [ -e "$DIR/$1" ]; then
while read -r line; do
@@ -148,19 +157,18 @@ unstow () {
for file in \
$(find . ! \( -user "$(id -un)" -o -group "$(id -gn)" \) \
-prune -o -type l ! -name . ! -name "$cchars" -print \
- | grep -Ev "$dirs_pat"); do
- if readlink "$file" | grep -Eq '^(\.\./)*\.STOW/'"$NAME/"; then
- rm "$file"
- while true; do
- file="$(dirname $file)"
- [ "$file" = . ] && break
- if [ -z "$(dir_contents $file)" ]; then
- rmdir "$file"
- else
- break
- fi
- done
- fi
+ | grep -Ev "$dirs_pat" | readlinks | awk -F'\t' \
+ '$2 ~ /^(\.\.\/)*\.STOW\/'"$NAME"'\// { print $1 }'); do
+ rm "$file"
+ while true; do
+ file="$(dirname $file)"
+ [ "$file" = . ] && break
+ if [ -z "$(dir_contents $file)" ]; then
+ rmdir "$file"
+ else
+ break
+ fi
+ done
done
[ -e "$HOME/.STOW/$NAME" ] && rm "$HOME/.STOW/$NAME"
if [ -d "$HOME/.STOW" ] \