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

variables not expanded after xargs #173

Open
jidanni opened this issue Nov 5, 2017 · 12 comments
Open

variables not expanded after xargs #173

jidanni opened this issue Nov 5, 2017 · 12 comments

Comments

@jidanni
Copy link

jidanni commented Nov 5, 2017

$ $BRO<TAB> #makes $BROWSER. Good!
$ xargs $BRO<TAB> #just beeps. Bad.
@jidanni
Copy link
Author

jidanni commented May 23, 2019

As of 2019 why does this
$ cat $BR<TAB>OWSER
expand, but this
$ xargs $BR<BROWSER>OWSER doesn't?
Please make them both work.

@jidanni jidanni changed the title variables not TAB expanded except in first position variables NOT expanded after xargs May 23, 2019
@jidanni jidanni changed the title variables NOT expanded after xargs variables expanded after xargs May 23, 2019
@jidanni jidanni changed the title variables expanded after xargs variables not expanded after xargs May 23, 2019
@jidanni
Copy link
Author

jidanni commented Feb 28, 2020

Normally I can expand $BROWSER
$ $BROW<TAB>
but not in this case:
$ bla bla bla | xargs $BROW<TAB>

@scop
Copy link
Owner

scop commented Feb 29, 2020

This would fix it

diff --git a/bash_completion b/bash_completion
index 1d2d2d0b..b8957333 100644
--- a/bash_completion
+++ b/bash_completion
@@ -1820,4 +1823,5 @@ _command_offset()
 
     if [[ $COMP_CWORD -eq 0 ]]; then
+        _variables && return
         local IFS=$'\n'
         compopt -o filenames

There are more places than this where we complete with command names, but we don't complete variable names in any of them based on a quick look. Not entirely sure why. On the other hand a correct completion would depend on exactly what the variable is pointing to; e.g. it should behave differently if it expands to a dir (no space added) or a command (space added) and not even complete variable names that don't expand to either.
But perhaps it would be an improvement just to simply complete the variable names like in this diff. Thoughts?

@jidanni
Copy link
Author

jidanni commented Feb 29, 2020

Well all I know is the user has already typed in a "$" and a few more letters, before hitting TAB.
And files on Unix don't often start with $, and if they did occasionally. the user could type ./$ or \$ or ./\$ etc. Therefore just expand variables when ever encountering $.

@scop
Copy link
Owner

scop commented Mar 1, 2020

Didn't mean that, but rather variables like $HOME, $TMPDIR, etc.

@jidanni
Copy link
Author

jidanni commented Mar 1, 2020

All I know is that if I do
$ xyz=abc
I expect $x<TAB> will expand to $xyz in all cases, except when inside ' ... '.

@scop
Copy link
Owner

scop commented Mar 1, 2020

I'm fairly certain that there is also an expectation whether the completion should add a space after completing the variable or not. But meh, as said, completing the variable in this particular case could be an improvement in the first place, space or not.

@jidanni
Copy link
Author

jidanni commented Mar 1, 2020

Yup, needs a space after it too.

@scop
Copy link
Owner

scop commented Mar 1, 2020

...except when you're completing let's say $HOME or $TMPDIR, or anything that is a directory, then the space is incorrect.

@jidanni
Copy link
Author

jidanni commented Mar 1, 2020

Hmm, OK. Perhaps detect slashes. And if it is a URL then just like directories, as the user probably wants to put something on the end too...(?)

@scop
Copy link
Owner

scop commented Mar 1, 2020

URL completion is out of scope for completion of command names, no URL will complete to a valid one. But as you see, there's more to it than it looks on the surface.

@jidanni
Copy link
Author

jidanni commented Mar 1, 2020 via email

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