diff options
| author | Rokosun <79040025+futureisfoss@users.noreply.github.com> | 2024-10-22 18:34:33 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-22 18:34:33 +0000 |
| commit | 61026e18de13b27a37337359d596f5ebfdb0f294 (patch) | |
| tree | a9fd085e857d6157af55e8f14fb278d5f7c9d5b8 | |
| parent | 628ed4dc995f3c09e33c24a01c817c18b1a268af (diff) | |
| download | eibhear-61026e18de13b27a37337359d596f5ebfdb0f294.tar.gz eibhear-61026e18de13b27a37337359d596f5ebfdb0f294.tar.zst eibhear-61026e18de13b27a37337359d596f5ebfdb0f294.zip | |
Fix dangerous copy/move script in lf (#1437)
Context: I accidentally pressed the C key on my .config directory and was presented with a list of directories to copy it to, then I pressed escape to quit the fzf menu without choosing anything - instead of doing nothing the script copied all of the contents inside my .config directory into my home directory. After dealing with that mess I decided to make this PR which does the following:
- Allow users to escape out of the fzf menu without unexpected copies
- Asks the user for confirmation before copying/moving files
- Some improvements in the UI
| -rw-r--r-- | .config/lf/lfrc | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/.config/lf/lfrc b/.config/lf/lfrc index dad917d..5598a30 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -92,25 +92,37 @@ cmd delete ${{ }} cmd moveto ${{ - clear; tput cup $(($(tput lines)/3)); tput bold set -f - clear; echo "Move to where?" - dest="$(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs | fzf | sed 's|~|$HOME|')" && + dest=$(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' "${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs" | fzf --prompt 'Move to where? ' | sed 's|~|$HOME|') + [ -z "$dest" ] && exit + destpath=$(eval printf '%s' \"$dest\") + clear; tput cup $(($(tput lines)/3)); tput bold + echo "From:" + echo "$fx" | sed 's/^/ /' + printf "To:\n %s\n\n\tmove?[y/N]" "$destpath" + read -r ans + [ "$ans" != "y" ] && exit for x in $fx; do - eval mv -iv \"$x\" \"$dest\" + mv -iv "$x" "$destpath" done && - notify-send "🚚 File(s) moved." "File(s) moved to $dest." + notify-send "🚚 File(s) moved." "File(s) moved to $destpath." }} cmd copyto ${{ - clear; tput cup $(($(tput lines)/3)); tput bold set -f - clear; echo "Copy to where?" - dest="$(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs | fzf | sed 's|~|$HOME|')" && + dest=$(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' "${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs" | fzf --prompt 'Copy to where? ' | sed 's|~|$HOME|') + [ -z "$dest" ] && exit + destpath=$(eval printf '%s' \"$dest\") + clear; tput cup $(($(tput lines)/3)); tput bold + echo "From:" + echo "$fx" | sed 's/^/ /' + printf "To:\n %s\n\n\tcopy?[y/N]" "$destpath" + read -r ans + [ "$ans" != "y" ] && exit for x in $fx; do - eval cp -ivr \"$x\" \"$dest\" + cp -ivr "$x" "$destpath" done && - notify-send "📋 File(s) copied." "File(s) copies to $dest." + notify-send "📋 File(s) copied." "File(s) copied to $destpath." }} cmd setbg "$1" |
