From 61026e18de13b27a37337359d596f5ebfdb0f294 Mon Sep 17 00:00:00 2001 From: Rokosun <79040025+futureisfoss@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:34:33 +0000 Subject: [PATCH] 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 --- .config/lf/lfrc | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/.config/lf/lfrc b/.config/lf/lfrc index dad917df..5598a307 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"