Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making zsh autocorrect work with custom git aliases

Tags:

git

zsh

I have a custom alias for git that I use with git df (it’s basically a shortcut for git diff).

However, with git’s zsh autocorrect, everytime I use git df in a directory that contains a db directory, I get this:

% ls
app/ config/ db/ lib/ log/ spec/

% git alias | grep "df"
df = diff

% git df
zsh: correct 'df' to 'db' [nyae]?

Is there a way I could make zsh aware of my git aliases so it takes them into account when trying to autocorrect my commands? I want it to detect that git df exist and not suggest me git db instead.

I don’t want to create a zsh alias (eg. alias gdf="git diff") or use alias git="nocorrect git".

Thanks for your help!

like image 644
remi Avatar asked Jul 30 '12 13:07

remi


2 Answers

You can force zsh to rebuild the autocorrect cache by running the command hash -rf or rehash. That fixed my problem when zsh was autocorrecting to the wrong thing.

like image 77
kristenmills Avatar answered Oct 11 '22 17:10

kristenmills


Git has an autocorrect feature:

git config --global help.autocorrect 

Will wait 2s before autocorrecting:

git config --global help.autocorrect 2 

I think that if you want to implement this feature in zsh you will have to change the git completion function directly.

like image 42
fvisconte Avatar answered Oct 11 '22 17:10

fvisconte