Fix dangerous copy/move script in lf

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
This commit is contained in:
Rokosun 2024-10-22 07:59:30 +00:00 committed by GitHub
parent 628ed4dc99
commit 9d1942569b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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"