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

Add an equivalent of bash's 'insert-completions' #6931

Closed
hexagonal-sun opened this issue Apr 21, 2020 · 5 comments
Closed

Add an equivalent of bash's 'insert-completions' #6931

hexagonal-sun opened this issue Apr 21, 2020 · 5 comments
Labels

Comments

@hexagonal-sun
Copy link

Hello,

I've been looking at the docs for an equivilent in fish of bash's 'insert-completions' function. According to the man page:

Insert all completions of the text before point that would have been generated by possible-completions.

My use-case of this is if there is a common prefix in a package and I wish to install/uninstall them. Say I have a bunch of packages that I want to install:

xf86-video-amdgpu
xf86-video-ati
xf86-video-dummy
xf86-video-fbdev
xf86-video-intel
xf86-video-nouveau

If I were to write pacman -S xf86-video and run the insert-completions command the list is expanded to the results returned by completion:

pacman -S xf86-video-amdgpu xf86-video-ati xf86-video-dummy xf86-video-fbdev xf86-video-intelm xf86-video-nouveau

which then allows me to further edit the command.

@faho
Copy link
Member

faho commented Apr 21, 2020

complete --do-complete can be used for this:

function insert-completions
    # We need to remove the descriptions, and we also don't want everything to be inserted on separate lines
    commandline -i -- (complete --do-complete | string replace -r '\t.*' '' | string join " ")
 end

bind \cg insert-completions

triggers it on control-g.

@faho faho added the question label Apr 21, 2020
@zanchey
Copy link
Member

zanchey commented Apr 22, 2020

That's pretty nifty, is it worth formalising as a fish_insert_completions function?

@hexagonal-sun
Copy link
Author

hexagonal-sun commented Apr 23, 2020

@faho Thanks for your suggestion. I gave it a go, however I had an issue when running C-g with the command line sudo pacman -S xf86-

commandline: Invalid combination of options,
insertion mode switches can not be used when not in insertion mode

.fishrc (line 3): 
    commandline -i -- (complete --do-complete | string replace -r '\t.*' '' | string join " ")
    ^
in function 'insert-completions'

(Type 'help commandline' for related documentation)

Update: it seems to be sudo that's causing the issue. If I run the completion without sudo it works fine.

@faho
Copy link
Member

faho commented Apr 23, 2020

Yeah, commandline is too zealous about option parsing - it thinks not having a thing to insert is an error worth complaining about. It should just return 1 in that case without saying anything.

faho added a commit that referenced this issue Apr 23, 2020
That's just, like, a normal thing to happen.

We can return false, but it's not an error worth complaining about.

See #6931.
@faho faho closed this as completed May 18, 2020
@jedbrown
Copy link

jedbrown commented Jun 4, 2024

Thanks for making this issue. The solution isn't quite equivalent. For example, typing pacman -S xf86- and triggering insert-completions yields pacman -S xf86-xf86-input-elographics xf86-input-evdev [...]. I'm newly tinkering with Fish so don't know how to remove the stem before inserting the completions.

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

No branches or pull requests

4 participants