Using zsh autocompletion for alias Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionWhat's the intended use case for COMPLETE_ALIASES in zsh?zsh alias expansionHow do I get my shell functions to make use of existing autocompletion in zsh?How to disable autocompletion for sudo …?ZSH autocompletion gives seemingly random errors after some timeHow do I set Zsh autocompletion rules for second argument (of function) to an existing command's rules?zsh parse error after alias do=…Bash (Git) - Functions, Alias, and SH script filesCan I change how zsh autocomplete works?zsh: remove predicted textHow to use aliases with auto completion in oh-my-zsh?

Using audio cues to encourage good posture

How to convince students of the implication truth values?

What does the "x" in "x86" represent?

Where are Serre’s lectures at Collège de France to be found?

Did MS DOS itself ever use blinking text?

Compare a given version number in the form major.minor.build.patch and see if one is less than the other

How to tell that you are a giant?

What does "lightly crushed" mean for cardamon pods?

How does the math work when buying airline miles?

Can you use the Shield Master feat to shove someone before you make an attack by using a Readied action?

Most bit efficient text communication method?

How to answer "Have you ever been terminated?"

Extracting terms with certain heads in a function

An adverb for when you're not exaggerating

Is safe to use va_start macro with this as parameter?

How can I use the Python library networkx from Mathematica?

Closed form of recurrent arithmetic series summation

How do pianists reach extremely loud dynamics?

For a new assistant professor in CS, how to build/manage a publication pipeline

What would be the ideal power source for a cybernetic eye?

How come Sam didn't become Lord of Horn Hill?

Can a new player join a group only when a new campaign starts?

What does this Jacques Hadamard quote mean?

How do I find out the mythology and history of my Fortress?



Using zsh autocompletion for alias



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionWhat's the intended use case for COMPLETE_ALIASES in zsh?zsh alias expansionHow do I get my shell functions to make use of existing autocompletion in zsh?How to disable autocompletion for sudo …?ZSH autocompletion gives seemingly random errors after some timeHow do I set Zsh autocompletion rules for second argument (of function) to an existing command's rules?zsh parse error after alias do=…Bash (Git) - Functions, Alias, and SH script filesCan I change how zsh autocomplete works?zsh: remove predicted textHow to use aliases with auto completion in oh-my-zsh?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I have created a few aliases for git in zsh, for example gch = git checkout, grb = git rebase --committer-date-is-author-date and some more complex useful zsh functions for git commands. But how can I allow these aliases to use zsh git autocompletion?










share|improve this question



















  • 1





    What happens when you remove oh-my-zsh and instead just zsh -f and then autoload -U compinit and then compinit and then create the aliases?

    – thrig
    Jan 5 '17 at 18:36

















3















I have created a few aliases for git in zsh, for example gch = git checkout, grb = git rebase --committer-date-is-author-date and some more complex useful zsh functions for git commands. But how can I allow these aliases to use zsh git autocompletion?










share|improve this question



















  • 1





    What happens when you remove oh-my-zsh and instead just zsh -f and then autoload -U compinit and then compinit and then create the aliases?

    – thrig
    Jan 5 '17 at 18:36













3












3








3








I have created a few aliases for git in zsh, for example gch = git checkout, grb = git rebase --committer-date-is-author-date and some more complex useful zsh functions for git commands. But how can I allow these aliases to use zsh git autocompletion?










share|improve this question
















I have created a few aliases for git in zsh, for example gch = git checkout, grb = git rebase --committer-date-is-author-date and some more complex useful zsh functions for git commands. But how can I allow these aliases to use zsh git autocompletion?







zsh autocomplete alias oh-my-zsh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 '18 at 15:45









Michael Mrozek

62.5k29194214




62.5k29194214










asked Jan 5 '17 at 17:49









Patrick ArtounianPatrick Artounian

163




163







  • 1





    What happens when you remove oh-my-zsh and instead just zsh -f and then autoload -U compinit and then compinit and then create the aliases?

    – thrig
    Jan 5 '17 at 18:36












  • 1





    What happens when you remove oh-my-zsh and instead just zsh -f and then autoload -U compinit and then compinit and then create the aliases?

    – thrig
    Jan 5 '17 at 18:36







1




1





What happens when you remove oh-my-zsh and instead just zsh -f and then autoload -U compinit and then compinit and then create the aliases?

– thrig
Jan 5 '17 at 18:36





What happens when you remove oh-my-zsh and instead just zsh -f and then autoload -U compinit and then compinit and then create the aliases?

– thrig
Jan 5 '17 at 18:36










2 Answers
2






active

oldest

votes


















1














If you open the file which contains the autoloaded function defintion for git completion:

On my ubuntu system, its:



/usr/share/zsh/functions/Completion/Unix/_git


at the top of the file you will see the #compdef declaration



#compdef git git-cvsserver git-receive-pack git-upload-archive git-upload-pack git-shell gitk tig


you can try adding your aliases to the #compdef definition, e.g.



#compdef git git-cvsserver git-receive-pack [...] tig gch grb
^^^ ^^^


Then starting a new shell to get that new directive loaded.

Then try invoking completion.



What is /usr/share/zsh/functions/Completion/Unix/_git?



Its the file that contains the autoloaded "function" defining the completion behaviour for the all the commands defined in the #compdef directive, in this case the git family of commands, it lives in fpath and is autoloaded by compinit when the completion system is initialized.



What is #compdef ?



from man zshcompsys




#compdef name ... [ -P pattern ... [ -N name ... ] ]

The file will be made autoloadable and the function defined in it
will be called when completing names, each of which is either the
name of a command whose arguments are to be completed or one of a
number of special contexts in the form -context- described below.







share|improve this answer

























  • Is there a nicer way to make this happen so it can fit into my dotfiles?

    – Patrick Artounian
    Jan 8 '17 at 21:24











  • yes there are other ways to script this out but did this work for you? I guess there is no point bothering with improving on this solution if it fundamentally didnt work in the first place.

    – the_velour_fog
    Jan 8 '17 at 21:27











  • Just tried it and no dice. I apologize for rushing into things.

    – Patrick Artounian
    Jan 8 '17 at 21:50












  • @patrick oh ok sorry. it works for me with functions, however I dont use aliases anymore so I couldnt test on my system

    – the_velour_fog
    Jan 8 '17 at 21:54



















0














I've done something very similar. Are you using oh-my-zsh? If so, make sure you've enabled the zsh-completions plugin in your .zshrc file. I'd also recommend the zsh-autosuggestions plugin.



Once you've done that, you'll need to add the following to your .zshrc file (if it's not already there)



fpath=(~/.zsh/completions $fpath)
autoload -U compinit && compinit





share|improve this answer

























  • Yes, I am oh-my-zsh and I also already have that in the zshrc.

    – Patrick Artounian
    Jan 8 '17 at 21:21












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f335145%2fusing-zsh-autocompletion-for-alias%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














If you open the file which contains the autoloaded function defintion for git completion:

On my ubuntu system, its:



/usr/share/zsh/functions/Completion/Unix/_git


at the top of the file you will see the #compdef declaration



#compdef git git-cvsserver git-receive-pack git-upload-archive git-upload-pack git-shell gitk tig


you can try adding your aliases to the #compdef definition, e.g.



#compdef git git-cvsserver git-receive-pack [...] tig gch grb
^^^ ^^^


Then starting a new shell to get that new directive loaded.

Then try invoking completion.



What is /usr/share/zsh/functions/Completion/Unix/_git?



Its the file that contains the autoloaded "function" defining the completion behaviour for the all the commands defined in the #compdef directive, in this case the git family of commands, it lives in fpath and is autoloaded by compinit when the completion system is initialized.



What is #compdef ?



from man zshcompsys




#compdef name ... [ -P pattern ... [ -N name ... ] ]

The file will be made autoloadable and the function defined in it
will be called when completing names, each of which is either the
name of a command whose arguments are to be completed or one of a
number of special contexts in the form -context- described below.







share|improve this answer

























  • Is there a nicer way to make this happen so it can fit into my dotfiles?

    – Patrick Artounian
    Jan 8 '17 at 21:24











  • yes there are other ways to script this out but did this work for you? I guess there is no point bothering with improving on this solution if it fundamentally didnt work in the first place.

    – the_velour_fog
    Jan 8 '17 at 21:27











  • Just tried it and no dice. I apologize for rushing into things.

    – Patrick Artounian
    Jan 8 '17 at 21:50












  • @patrick oh ok sorry. it works for me with functions, however I dont use aliases anymore so I couldnt test on my system

    – the_velour_fog
    Jan 8 '17 at 21:54
















1














If you open the file which contains the autoloaded function defintion for git completion:

On my ubuntu system, its:



/usr/share/zsh/functions/Completion/Unix/_git


at the top of the file you will see the #compdef declaration



#compdef git git-cvsserver git-receive-pack git-upload-archive git-upload-pack git-shell gitk tig


you can try adding your aliases to the #compdef definition, e.g.



#compdef git git-cvsserver git-receive-pack [...] tig gch grb
^^^ ^^^


Then starting a new shell to get that new directive loaded.

Then try invoking completion.



What is /usr/share/zsh/functions/Completion/Unix/_git?



Its the file that contains the autoloaded "function" defining the completion behaviour for the all the commands defined in the #compdef directive, in this case the git family of commands, it lives in fpath and is autoloaded by compinit when the completion system is initialized.



What is #compdef ?



from man zshcompsys




#compdef name ... [ -P pattern ... [ -N name ... ] ]

The file will be made autoloadable and the function defined in it
will be called when completing names, each of which is either the
name of a command whose arguments are to be completed or one of a
number of special contexts in the form -context- described below.







share|improve this answer

























  • Is there a nicer way to make this happen so it can fit into my dotfiles?

    – Patrick Artounian
    Jan 8 '17 at 21:24











  • yes there are other ways to script this out but did this work for you? I guess there is no point bothering with improving on this solution if it fundamentally didnt work in the first place.

    – the_velour_fog
    Jan 8 '17 at 21:27











  • Just tried it and no dice. I apologize for rushing into things.

    – Patrick Artounian
    Jan 8 '17 at 21:50












  • @patrick oh ok sorry. it works for me with functions, however I dont use aliases anymore so I couldnt test on my system

    – the_velour_fog
    Jan 8 '17 at 21:54














1












1








1







If you open the file which contains the autoloaded function defintion for git completion:

On my ubuntu system, its:



/usr/share/zsh/functions/Completion/Unix/_git


at the top of the file you will see the #compdef declaration



#compdef git git-cvsserver git-receive-pack git-upload-archive git-upload-pack git-shell gitk tig


you can try adding your aliases to the #compdef definition, e.g.



#compdef git git-cvsserver git-receive-pack [...] tig gch grb
^^^ ^^^


Then starting a new shell to get that new directive loaded.

Then try invoking completion.



What is /usr/share/zsh/functions/Completion/Unix/_git?



Its the file that contains the autoloaded "function" defining the completion behaviour for the all the commands defined in the #compdef directive, in this case the git family of commands, it lives in fpath and is autoloaded by compinit when the completion system is initialized.



What is #compdef ?



from man zshcompsys




#compdef name ... [ -P pattern ... [ -N name ... ] ]

The file will be made autoloadable and the function defined in it
will be called when completing names, each of which is either the
name of a command whose arguments are to be completed or one of a
number of special contexts in the form -context- described below.







share|improve this answer















If you open the file which contains the autoloaded function defintion for git completion:

On my ubuntu system, its:



/usr/share/zsh/functions/Completion/Unix/_git


at the top of the file you will see the #compdef declaration



#compdef git git-cvsserver git-receive-pack git-upload-archive git-upload-pack git-shell gitk tig


you can try adding your aliases to the #compdef definition, e.g.



#compdef git git-cvsserver git-receive-pack [...] tig gch grb
^^^ ^^^


Then starting a new shell to get that new directive loaded.

Then try invoking completion.



What is /usr/share/zsh/functions/Completion/Unix/_git?



Its the file that contains the autoloaded "function" defining the completion behaviour for the all the commands defined in the #compdef directive, in this case the git family of commands, it lives in fpath and is autoloaded by compinit when the completion system is initialized.



What is #compdef ?



from man zshcompsys




#compdef name ... [ -P pattern ... [ -N name ... ] ]

The file will be made autoloadable and the function defined in it
will be called when completing names, each of which is either the
name of a command whose arguments are to be completed or one of a
number of special contexts in the form -context- described below.








share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 5 '17 at 21:19

























answered Jan 5 '17 at 21:13









the_velour_fogthe_velour_fog

5,47753467




5,47753467












  • Is there a nicer way to make this happen so it can fit into my dotfiles?

    – Patrick Artounian
    Jan 8 '17 at 21:24











  • yes there are other ways to script this out but did this work for you? I guess there is no point bothering with improving on this solution if it fundamentally didnt work in the first place.

    – the_velour_fog
    Jan 8 '17 at 21:27











  • Just tried it and no dice. I apologize for rushing into things.

    – Patrick Artounian
    Jan 8 '17 at 21:50












  • @patrick oh ok sorry. it works for me with functions, however I dont use aliases anymore so I couldnt test on my system

    – the_velour_fog
    Jan 8 '17 at 21:54


















  • Is there a nicer way to make this happen so it can fit into my dotfiles?

    – Patrick Artounian
    Jan 8 '17 at 21:24











  • yes there are other ways to script this out but did this work for you? I guess there is no point bothering with improving on this solution if it fundamentally didnt work in the first place.

    – the_velour_fog
    Jan 8 '17 at 21:27











  • Just tried it and no dice. I apologize for rushing into things.

    – Patrick Artounian
    Jan 8 '17 at 21:50












  • @patrick oh ok sorry. it works for me with functions, however I dont use aliases anymore so I couldnt test on my system

    – the_velour_fog
    Jan 8 '17 at 21:54

















Is there a nicer way to make this happen so it can fit into my dotfiles?

– Patrick Artounian
Jan 8 '17 at 21:24





Is there a nicer way to make this happen so it can fit into my dotfiles?

– Patrick Artounian
Jan 8 '17 at 21:24













yes there are other ways to script this out but did this work for you? I guess there is no point bothering with improving on this solution if it fundamentally didnt work in the first place.

– the_velour_fog
Jan 8 '17 at 21:27





yes there are other ways to script this out but did this work for you? I guess there is no point bothering with improving on this solution if it fundamentally didnt work in the first place.

– the_velour_fog
Jan 8 '17 at 21:27













Just tried it and no dice. I apologize for rushing into things.

– Patrick Artounian
Jan 8 '17 at 21:50






Just tried it and no dice. I apologize for rushing into things.

– Patrick Artounian
Jan 8 '17 at 21:50














@patrick oh ok sorry. it works for me with functions, however I dont use aliases anymore so I couldnt test on my system

– the_velour_fog
Jan 8 '17 at 21:54






@patrick oh ok sorry. it works for me with functions, however I dont use aliases anymore so I couldnt test on my system

– the_velour_fog
Jan 8 '17 at 21:54














0














I've done something very similar. Are you using oh-my-zsh? If so, make sure you've enabled the zsh-completions plugin in your .zshrc file. I'd also recommend the zsh-autosuggestions plugin.



Once you've done that, you'll need to add the following to your .zshrc file (if it's not already there)



fpath=(~/.zsh/completions $fpath)
autoload -U compinit && compinit





share|improve this answer

























  • Yes, I am oh-my-zsh and I also already have that in the zshrc.

    – Patrick Artounian
    Jan 8 '17 at 21:21
















0














I've done something very similar. Are you using oh-my-zsh? If so, make sure you've enabled the zsh-completions plugin in your .zshrc file. I'd also recommend the zsh-autosuggestions plugin.



Once you've done that, you'll need to add the following to your .zshrc file (if it's not already there)



fpath=(~/.zsh/completions $fpath)
autoload -U compinit && compinit





share|improve this answer

























  • Yes, I am oh-my-zsh and I also already have that in the zshrc.

    – Patrick Artounian
    Jan 8 '17 at 21:21














0












0








0







I've done something very similar. Are you using oh-my-zsh? If so, make sure you've enabled the zsh-completions plugin in your .zshrc file. I'd also recommend the zsh-autosuggestions plugin.



Once you've done that, you'll need to add the following to your .zshrc file (if it's not already there)



fpath=(~/.zsh/completions $fpath)
autoload -U compinit && compinit





share|improve this answer















I've done something very similar. Are you using oh-my-zsh? If so, make sure you've enabled the zsh-completions plugin in your .zshrc file. I'd also recommend the zsh-autosuggestions plugin.



Once you've done that, you'll need to add the following to your .zshrc file (if it's not already there)



fpath=(~/.zsh/completions $fpath)
autoload -U compinit && compinit






share|improve this answer














share|improve this answer



share|improve this answer








edited 10 hours ago









Rui F Ribeiro

42.1k1484142




42.1k1484142










answered Jan 5 '17 at 19:20









Brian TullyBrian Tully

11




11












  • Yes, I am oh-my-zsh and I also already have that in the zshrc.

    – Patrick Artounian
    Jan 8 '17 at 21:21


















  • Yes, I am oh-my-zsh and I also already have that in the zshrc.

    – Patrick Artounian
    Jan 8 '17 at 21:21

















Yes, I am oh-my-zsh and I also already have that in the zshrc.

– Patrick Artounian
Jan 8 '17 at 21:21






Yes, I am oh-my-zsh and I also already have that in the zshrc.

– Patrick Artounian
Jan 8 '17 at 21:21


















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f335145%2fusing-zsh-autocompletion-for-alias%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







-alias, autocomplete, oh-my-zsh, zsh

Popular posts from this blog

Frič See also Navigation menuinternal link

Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant

fontconfig warning: “/etc/fonts/fonts.conf”, line 100: unknown “element blank” The 2019 Stack Overflow Developer Survey Results Are In“tar: unrecognized option --warning” during 'apt-get install'How to fix Fontconfig errorHow do I figure out which font file is chosen for a system generic font alias?Why are some apt-get-installed fonts being ignored by fc-list, xfontsel, etc?Reload settings in /etc/fonts/conf.dTaking 30 seconds longer to boot after upgrade from jessie to stretchHow to match multiple font names with a single <match> element?Adding a custom font to fontconfigRemoving fonts from fontconfig <match> resultsBroken fonts after upgrading Firefox ESR to latest Firefox