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

Problem using eln with file names containing spaces with xonsh #244

Closed
tkossak opened this issue Aug 2, 2023 · 14 comments
Closed

Problem using eln with file names containing spaces with xonsh #244

tkossak opened this issue Aug 2, 2023 · 14 comments
Labels
done improvement New feature or request

Comments

@tkossak
Copy link

tkossak commented Aug 2, 2023

Describe the bug
Problem using files containing spaces in their names, when using clifm with xonsh shell.

To Reproduce
Run clifm using CLIFM_SHELL=/home/kossak/.local/bin/xonsh clifm (enter proper path to xonsh) and then:

<0> $ n 'a - a'
<0> $ vim 4   # 4 is my ELN of above file - change it to proper ELN on your computer
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jul 08 2023 13:06:53)
Unknown option argument: "-\"
More info with: "vim -h"

I also tried expanding ELN (by entering vim 4 and hitting tab) but the same error appears:

<0> $ vim a\ -\ a
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jul 08 2023 13:06:53)
Unknown option argument: "-\"
More info with: "vim -h"

In xonsh vim a\ -\ a also returns this error but vim 'a - a' works. Is it possible to configure eln expansion to use quotes instead of escaping spaces with \?

Expected behavior
After running vim 4 vim opens the file a - a

Desktop (please complete the following information):

  • OS: Linux Manjaro KDE
  • Terminal: Konsole
  • CliFM version: 1.13.8
  • Installation source: git
  • xonsh v0.14.0
@tkossak tkossak changed the title Problem with using eln with files containing dash Problem with using eln with file names containing dash Aug 2, 2023
@tkossak tkossak changed the title Problem with using eln with file names containing dash Problem using eln with file names containing dash Aug 2, 2023
@tkossak tkossak changed the title Problem using eln with file names containing dash Problem using eln with file names containing dash with xonsh Aug 2, 2023
@tkossak
Copy link
Author

tkossak commented Aug 2, 2023

It actually is a problem with xonsh shell. It would work if eln was expanded using quotes, not slashes. Maybe I will just stop using xonsh inside clifm, and switch back to bash...

@leo-arch
Copy link
Owner

leo-arch commented Aug 2, 2023

Hi @tkossak. First, the obvious thing: xonsh is quite unorthodox in this regard. Escaping (using backslashes), just as quoting (using either single or double quotes), is a standard method (POSIX indeed) to disable special meanings.

However, providing an option to choose among these escaping mechanisms (backslash, single, or double quotes) when auto-expanding file names, might be an interesting feature.

For the time being, you can still make it work using the ; character, which instructs clifm to pass the current command line verbatim to the system shell (in this case, xonsh). Example:

;vim 'a - a'

Far from perfect, but it does the trick.

@leo-arch
Copy link
Owner

leo-arch commented Aug 3, 2023

A little improvement: vim 'a - a' should work (no need for leading semicolon anymore).

Btw, there are several open issues in the xonsh repo complaining about this: it cannot handle backslashes. See for example xonsh/xonsh#3595 and xonsh/xonsh#1432. Sadly, the devs do not seem to like the idea of supporting backslashes at all, despite the fact that it is a quite standard feature (and indeed the default quoting mechanism for most shells). As specified by POSIX, all the three quoting mechanisms (backslash, single, and double quotes) shall be supported by a compliant shell. Of course, xonsh do not need to be POSIX compliant (and probably it is not even intended to be so); but there are some drawbacks, mostly portability. This issue seems to be a good example.

@tkossak
Copy link
Author

tkossak commented Aug 3, 2023

Yes, xonsh does not try to be 100% POSIX compatible, instead it wants to be more PYTHON compatible.

vim 'a - a' works, but I need to write file name manually instead of expanding ELN (or manually remove all slashes and enclose it in quotes)

So it's feature request ticket :). If we could configure clifm to use single single (or double) quotes instead of slashes it would be awesome. I would use it even with bash, because slashes look ugly, especially when file name has more spaces and is long - it's difficult to find at first glance where file name ends, and where command arguments are.

Thank you very much for your hard work!

@tkossak tkossak changed the title Problem using eln with file names containing dash with xonsh Problem using eln with file names containing spaces with xonsh Aug 3, 2023
@leo-arch
Copy link
Owner

leo-arch commented Aug 3, 2023

I have been playing around with this (cause I think is a feature to have) and have been able to make it work pretty nice, except for directories: TAB completion/suggestions is complex machinery. The thing is that I don't like to provide a non-complete feature because it looks weak (and it is it), but I could provide you with temporary snapshots hidden behind a non-documented option to make some tests.

EDIT: non-complete means that alternative quoting mechanisms (both single and double quotes) will work only for ELN expansions provided they do not point to directories.

@tkossak
Copy link
Author

tkossak commented Aug 3, 2023

Sure, If you tell me commit hash to install clifm from, I can try it

@leo-arch
Copy link
Owner

leo-arch commented Aug 3, 2023

The new feature (though highly experimental) is ready. This is how it works:

  1. Select the quoting style setting QuotingStyle in the config file (the COMMAND LINE section feels like the right place) to any of these values: backslash (default), single, or double (single would be the most natural choice in this case).
  2. Regular files (not dirs) expanded/completed from ELN's will use the desired quoting style.

Needles to say, this feature is completely undocumented (hidden) and might be modified (or even completely removed) in the (near) future.

@tkossak
Copy link
Author

tkossak commented Aug 4, 2023

Expanding eln works as it should (tried QuotingStyle=single), but using eln directly doesn't (because of xonsh), eg inside clifm:

$ n 'a - a'
$ vim 1<TAB>  # works, it changes into: vim 'a - a'
$ vim 1
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jul 08 2023 13:06:53)
Unknown option argument: "-\"
More info with: "vim -h"

clifm v1.13.9 with xonsh as $CLIFM_SHELL.

In bash both eln and expanded eln works.

@leo-arch
Copy link
Owner

leo-arch commented Aug 4, 2023

Should be working now.

EDIT: A little tip: vim 1 (runs the command via the system shell, or whatever shell specified via CLIFM_SHELL); 1 vim, by contrast, runs the command bypassing the shell, directly via execv(3), in which case the quoting style doesn't make any difference: whatever 1 points to is passed to vim as is. The second command works no matter the quoting style.

@leo-arch leo-arch added the improvement New feature or request label Aug 4, 2023
@tkossak
Copy link
Author

tkossak commented Aug 7, 2023

Works, thank you (also for the tip).

@leo-arch leo-arch added the done label Aug 7, 2023
@leo-arch leo-arch closed this as completed Aug 7, 2023
@tkossak
Copy link
Author

tkossak commented Aug 8, 2023

Got another improvement for this feature: it would nice if quoting expansion worked also for tab completion! eg:

$ n 'a - a'
$ ls a<TAB>

Last command is expanded into: ls a\ -\ a, but should be ls 'a - a'

@leo-arch
Copy link
Owner

leo-arch commented Aug 8, 2023

Hi @tkossak. Yes, I'm totally aware of this, and this is why I said that this feature is not complete. The thing is that 1<TAB> is one thing and a<TAB> is a completely different thing (or at least quite more complex): in the first case, we know we have an ELN, which could be either a directory or a file name (always in the current directory); in the second case, by contrast, none of these conditions can be given for granted, cause it may be anything, from a simple file name, to a directory name, to a path or any other completion type. This is why I limited this feature to ELN's in the first place.

I'll bear this in mind however.

@freijon
Copy link

freijon commented Aug 18, 2023

btw. same issue with nushell.
Nushell also supports back-ticks (`) as quote style, so maybe this could easily be added as well?

@leo-arch
Copy link
Owner

leo-arch commented Aug 18, 2023

Hi @freijon. Thanks for pointing this out. For the time being, the same trick used for xonsh can be used for nushell.

As to the backticks, that's quite unorthodox, and more importantly, dangerous: most shells (following the POSIX specification) use backticks for command substitution : now, if you're not running nushell and your quote style is backtick, the underlying shell will try to execute a command named as your file, which is clearly not what you intended, and also a security concern.

I'll take a look at it, however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
done improvement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants