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

Tab completion for the 'debian' plugin #3686

Closed
balasankarc opened this issue Mar 12, 2015 · 15 comments · Fixed by #7698
Closed

Tab completion for the 'debian' plugin #3686

balasankarc opened this issue Mar 12, 2015 · 15 comments · Fixed by #7698
Labels
Area: plugin Issue or PR related to a plugin Topic: alias Pull Request or issue regarding aliases Topic: completion Pull Request or issue regarding completion

Comments

@balasankarc
Copy link

When using apt- commands normally, I can get tab completion to automatically complete the package name OR list the packages matching pattern. Is it possible to get that with the debian plugin?
Like while using acs.

@ncanceill
Copy link
Contributor

Completion for the acs alias should be identical to a regular apt-cache search. Is it not the case?

In order to help us help you, please answer the following three questions about your completion issue:

  • How can we reproduce the issue?
  • What should be the correct behavior?
  • What happens instead?

@balasankarc
Copy link
Author

When I use apt-get install , after I type apt-get install iceweasel and press tab, I get a list of all the packages starting with 'iceweasel'. But, that doesn't happen with ai iceweasel.

But when I am using sudo ai, tab completion works. It should be made to support without sudo also.

@apjanke
Copy link
Contributor

apjanke commented Sep 28, 2015

The Debian plugin already has support for completion on those sudo commands. It dynamically defines completion wrappers for them.

    alias ai='sudo $apt_pref install'

[...snip...]

apt_pref_compdef() {
    local f fb
    f="_apt_pref_${2}"

    eval "function ${f}() {
        shift words; 
    service=\"\$apt_pref\"; 
    words=(\"\$apt_pref\" '$2' \$words); 
    ((CURRENT++))
    test \"\${apt_pref}\" = 'aptitude' && _aptitude || _apt
    }"

    compdef "$f" "$1"
}

[...snip...]

apt_pref_compdef ai  "install"
apt_pref_compdef ail "install"

But it doesn't seem to be working.

I think the problem is that unless you have the complete_aliases option set, aliases are expanded before locating the completion function to use. So these special completions are never actually invoked. Maybe they were written before 5b75cc7 when complete_aliases was turned back off by default.

Also, the test \"\${apt_pref}\" = 'aptitude' && _aptitude || _apt test is broken because $apt_pref holds the complete path to the program, not just its basename.

Normally, zsh is smart enough to do completion for a command that starts with sudo. But because these aliases are using $apt_pref instead of the raw command name. That seems to be enough to break the completions.

If you don't need to support changing $apt_pref during the course of a session, we can probably just change the aliases to eager-evaluate $apt_pref at plugin load time, remove all the special completion code, and things will probably just work. Or you could turn the aliases in to functions, and the custom completion wrappers might start working.

@crypdick
Copy link

I'm also experiencing this. @apjanke Where do I set complete_aliases option?

@mcornella
Copy link
Member

In your zshrc file should be enough, with a simple setopt complete_aliases

@balasankarc
Copy link
Author

setopt completealiases fixed my issue. Should I close it or leave it open for you guys to investigate (if there is something to investigate) ?

@apjanke
Copy link
Contributor

apjanke commented Feb 2, 2016

The problem is that setting complete_aliases will break completion for other things, and most users will want it off, per #4407. I think this is effectively a bug in the debian plugin and we should leave this open.

@mcornella mcornella reopened this Feb 2, 2016
@mcornella mcornella added the Topic: completion Pull Request or issue regarding completion label Mar 30, 2016
@okapia
Copy link

okapia commented Jan 7, 2017

You should make complete_aliases the default. If that breaks completion for "other things" then change those other things to be functions instead of aliases.

@NellyWhads
Copy link

@apjanke Any thougths on a fix for this? I've been scowering the corners of the web hoping someone has found a solution I could use (the setopt mentioned here isn't working for me)

@okapia
Copy link

okapia commented Dec 21, 2017

@NellyWhadsDev: if setopt complete_aliases isn't working for you then you must have some other issue. To begin with is completion after 'apt-cache search ' working for you? Where are you setting the option: could it be getting reset?

@NellyWhads
Copy link

@okapia I'm setting it at the very end of my .zshrc, using antigen as my framework (the setopt complete_aliases is done after antigen apply, after a few other setopt's that all work correctly.

@NellyWhads
Copy link

@okapia here's a little update:

  1. tab-autocompletion works after sudo apt-get install (for searching through package names)
  2. tab-autocompletion does not work after apt-cache search (tried with sudo as well)
  3. bash-completion is installed

@NellyWhads
Copy link

Bumping this, any thoughts?

@okapia
Copy link

okapia commented Jan 18, 2018

NellyWhadsDev: based on what you say, your problem has nothing to do with aliases which is what this bug was originally opened to handle. What it comes down to is that the apt-cache completion is explicitly defined to not complete anything after "apt-cache search" because search terms can be literally anything. But it will prompt for a "search term". Similarly, nothing is completed after grep: you're just prompted for a "pattern".

If you want completion of an acs alias to prompt for a "search term", this bug is relevant. If you want to complete packages instead of search terms, you'll need to use a modified _apt. If you want the default _apt function to do this, it'll probably need to be configurable because packages are not search terms.

@mcornella mcornella added Topic: alias Pull Request or issue regarding aliases Area: plugin Issue or PR related to a plugin labels Mar 24, 2019
@mcornella
Copy link
Member

I've submitted #7698 which should take care of this issue, please test and +1 if it works.

pull bot pushed a commit to XionZhao/oh-my-zsh that referenced this issue Jun 11, 2019
…7698)

* Use double quotes to cache value of $apt_pref and $apt_upgr
* Clean up and fix syntax of command checks
* Clean up README and document $apt_pref/$apt_upgr overriding mechanism
* Rename `ag` alias (apt upgrade) to `au`
* Clean up README and fix syntax

Fixes ohmyzsh#3686 
Fixes ohmyzsh#4660 
Closes ohmyzsh#5906

Co-authored-by: Noah Vesely <fowlslegs@riseup.net>
dukegod pushed a commit to dukegod/oh-my-zsh that referenced this issue Jul 16, 2019
…7698)

* Use double quotes to cache value of $apt_pref and $apt_upgr
* Clean up and fix syntax of command checks
* Clean up README and document $apt_pref/$apt_upgr overriding mechanism
* Rename `ag` alias (apt upgrade) to `au`
* Clean up README and fix syntax

Fixes ohmyzsh#3686 
Fixes ohmyzsh#4660 
Closes ohmyzsh#5906

Co-authored-by: Noah Vesely <fowlslegs@riseup.net>
atsuya pushed a commit to atsuya/oh-my-zsh that referenced this issue Aug 3, 2019
…7698)

* Use double quotes to cache value of $apt_pref and $apt_upgr
* Clean up and fix syntax of command checks
* Clean up README and document $apt_pref/$apt_upgr overriding mechanism
* Rename `ag` alias (apt upgrade) to `au`
* Clean up README and fix syntax

Fixes ohmyzsh#3686 
Fixes ohmyzsh#4660 
Closes ohmyzsh#5906

Co-authored-by: Noah Vesely <fowlslegs@riseup.net>
chihchun pushed a commit to chihchun/oh-my-zsh that referenced this issue Aug 6, 2019
…7698)

* Use double quotes to cache value of $apt_pref and $apt_upgr
* Clean up and fix syntax of command checks
* Clean up README and document $apt_pref/$apt_upgr overriding mechanism
* Rename `ag` alias (apt upgrade) to `au`
* Clean up README and fix syntax

Fixes ohmyzsh#3686 
Fixes ohmyzsh#4660 
Closes ohmyzsh#5906

Co-authored-by: Noah Vesely <fowlslegs@riseup.net>
lewg pushed a commit to lewg/oh-my-zsh that referenced this issue Nov 25, 2019
…7698)

* Use double quotes to cache value of $apt_pref and $apt_upgr
* Clean up and fix syntax of command checks
* Clean up README and document $apt_pref/$apt_upgr overriding mechanism
* Rename `ag` alias (apt upgrade) to `au`
* Clean up README and fix syntax

Fixes ohmyzsh#3686 
Fixes ohmyzsh#4660 
Closes ohmyzsh#5906

Co-authored-by: Noah Vesely <fowlslegs@riseup.net>
spiliopoulos pushed a commit to spiliopoulos/zsh-config that referenced this issue Jun 17, 2020
…7698)

* Use double quotes to cache value of $apt_pref and $apt_upgr
* Clean up and fix syntax of command checks
* Clean up README and document $apt_pref/$apt_upgr overriding mechanism
* Rename `ag` alias (apt upgrade) to `au`
* Clean up README and fix syntax

Fixes ohmyzsh#3686 
Fixes ohmyzsh#4660 
Closes ohmyzsh#5906

Co-authored-by: Noah Vesely <fowlslegs@riseup.net>
crdant referenced this issue in crdant/oh-my-zsh-custom Dec 30, 2020
* Use double quotes to cache value of $apt_pref and $apt_upgr
* Clean up and fix syntax of command checks
* Clean up README and document $apt_pref/$apt_upgr overriding mechanism
* Rename `ag` alias (apt upgrade) to `au`
* Clean up README and fix syntax

Fixes #3686 
Fixes #4660 
Closes #5906

Co-authored-by: Noah Vesely <fowlslegs@riseup.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: plugin Issue or PR related to a plugin Topic: alias Pull Request or issue regarding aliases Topic: completion Pull Request or issue regarding completion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants