Open julianborlle opened 5 months ago
@julianborlle
You shouldn't have spaces in your filenames! : No Bullshit Instant Filename Sanitizer: Threaded & Recursive & Lightweight
Jokes aside,
Can you try this:
cmd delete ${{
clear; tput cup $(($(tput lines)/3)); tput bold
set -f
printf "%s\n\t" "${fx}"
printf "delete?[y/N]"
read ans
[ "${ans}" = "y" ] && rm -rf -- ${fx}
}}
We change the variable with this "${fx}"
so it captures the variable both with curly brackets and double quotes which prevents the variable, either being split or expand before showing you the files that would be deleted.
The second also has curly brackets (it's the best practice for variables) but it doesn't have double quotes. This part is important because when you put double quotes to that; the variable is accepted as a single argument, rather than multiple arguments consisting of different files.
Though you shouldn't have needed this since the function disables globbing (filename expansion) with set -f
and uses a rm
command with --
which even accepts files starting with a dash.
I have tested it, and here I can delete a file with multiple spaces in it (the parent directory also has a space):
What is your preferred #!/bin/sh
shell? Maybe it doesn't support set -f
.
Mine is set to Dash and I also set my shell inside LF just in case with this setting inside lfrc
:
set shell dash
The command by itself won't escape the spaces in the file name so the rf command won't match any files. Even worse, it might match other files not selected if their name is contained in the original file.