Last active
April 13, 2024 21:45
-
-
Save StaticRocket/2ca72943b87f2b760b5e3d5d66f65322 to your computer and use it in GitHub Desktop.
Unstow a package by replaceing all symbolic links with a copy of the files they were pointing to.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
HELP_TEXT=" | |
Usage: $0 [PACKAGE]... | |
Unstow a package by replacing all symbolic links with a copy of the files they | |
were pointing to. | |
This script currently assumes the 'stow dir' is the current dir and that the | |
'target' is the parent directory. These are the current default values for | |
stow. | |
" | |
unstow_package() { | |
stow -D -n -v "$1" 2>&1 | sed -n '/UNLINK:/ba :a s/UNLINK: //p' \ | |
| while read -r input; do | |
printf 'Unstowing: %s\n' "$input" | |
if real_path=$(realpath "../$input") \ | |
&& link_path=$(realpath -s "../$input"); then | |
if [ -z "$SIMULATE" ]; then | |
rm "$link_path" | |
cp -ar "$real_path" "$link_path" | |
else | |
printf '%s -> %s\n' \ | |
"$real_path" \ | |
"$link_path" | |
fi | |
else | |
printf '%s\n' 'Error, unable to find backing file for link!' | |
fi | |
done | |
} | |
if [ $# -eq 0 ]; then | |
printf '%s\n' "$HELP_TEXT" | |
else | |
for package in "$@"; do | |
unstow_package "$package" | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment