Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lf "delete file" command doesn't work with files containing spaces #1400

Open
julianborlle opened this issue Mar 13, 2024 · 1 comment
Open

Comments

@julianborlle
Copy link

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.

@emrakyz
Copy link
Contributor

emrakyz commented Apr 16, 2024

@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):

image

What is your preferred #!/bin/sh shell? Maybe it doesn't support set -f.

image

Mine is set to Dash and I also set my shell inside LF just in case with this setting inside lfrc:
set shell dash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants