24

I installed oh-my-zsh to make terminal use a bit easier. One thing that bugs me though is the prolific aliases added by it, like "ga", "gap", "gcmsg", "_", which are harder to remember than the original command, and pollutes the command hash table.

So is there a way to disable aliases altogether? Or a way to clear all aliases so that I can put it in my .zshrc?

Siyuan Ren
  • 1,302
  • 2
  • 11
  • 15

5 Answers5

14

If you don't want any of oh-my-zsh's aliases, but you want to keep other aliases, you can save the aliases before loading oh-my-zsh

save_aliases=$(alias -L)

and restore them afterwards.

eval $save_aliases; unset save_aliases

If you want to remove all aliases at some point, you can use unalias -m '*' (remove all aliases matching *, i.e. all of them).

If you absolutely hate aliases and don't want to ever see one, you can make the alias builtin inoperative: unalias -m '*'; alias () { : }. Or you can simply turn off alias expansion with setopt no_aliases.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • Thanks! I like this solution because it will still work after updates to oh-my-zsh and its git plugin. – rangfu Apr 04 '22 at 15:23
11

You can use unalias with -m option:

unalias -m '*'

to delete all defined aliases

cuonglm
  • 150,973
  • 38
  • 327
  • 406
  • When I append this line to `.zshrc`, there is still one alias `globurl='noglob urlglobber '` left. Any idea why? – Siyuan Ren Oct 14 '14 at 08:46
  • Maybe it's loaded after `unalias` ran. ,Maybe you should put the `unalias` command at the end of your `.zshrc` – cuonglm Oct 14 '14 at 08:47
  • I did put it at the end. That is why it is so confusing. – Siyuan Ren Oct 14 '14 at 08:55
  • What is output of `zstyle`? – cuonglm Oct 14 '14 at 09:09
  • See https://gist.github.com/netheril96/70be43f8627eea5603f1 for the `zstyle` output. – Siyuan Ren Oct 14 '14 at 09:16
  • I recursively grepped .oh-my-zsh directory and cannot find any thing containing the word `globber` or `globurl`. – Siyuan Ren Oct 14 '14 at 09:17
  • @SiyuanRen: I think because of these lines `url-globbers (eval) :url-quote-magic 'zmodload -i zsh/parameter; reply=( noglob ${(k)galiases[(R)(* |)(noglob|urlglobber|globurl) *]:-} ${(k)aliases[(R)(* |)(noglob|urlglobber|globurl) *]:-} )'`. It returns new alias definition. – cuonglm Oct 14 '14 at 09:24
  • It is just odd that this is defined but nowhere to be found in my filesystem. – Siyuan Ren Oct 14 '14 at 09:29
  • @SiyuanRen: You can post it as another question, to get more details answer from another users. I don't have deep knowledge about `zsh` to give you an explanation about that. – cuonglm Oct 14 '14 at 09:53
  • 1
    @SiyuanRen This alias is defined when the function `url-quote-magic` is loaded (see `/usr/share/zsh/functions/Zle/url-quote-magic` or wherever it is on your system). Oh-my-zsh binds `self-insert` to `url-quote-magic`. – Gilles 'SO- stop being evil' Oct 14 '14 at 22:44
10

If you only want to remove the git aliases, I recommend one of the following two choices:

  1. Change ~/.oh-my-zsh/plugins/git/git.plugin.zsh by removing all the aliases at the bottom

  2. Make a copy of that plugin (recommended location: ~/.oh-my-zsh/custom/plugins/git-noalias/git-noalias.plugin.zsh), edit that copy to not have the aliases, and then change your ~/.zshrc to do plugins=(git-noalias) instead of plugins=(git).

This will give you all the benefits of the plugin (I'm not sure what they are but they may be related to the automatic Git status/branch information displayed within Git folders) without the aliases.

A.Wan
  • 201
  • 2
  • 4
  • The advantage of not having aliases but keep the [git plugin](https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/git/git.plugin.zsh) of oh-my-zsh is the functions. – Timo Nov 16 '20 at 12:27
0

Simple method: If the problem is the multiple lines of git aliases comment out the aliases you want to disable

nano ~/.oh-my-zsh/plugins/git/git.plugin.zsh

comment out the unwanted lines #, to go faster using nano make use of the Replace function

alias g='git'
#alias ga='git add'
#alias gaa='git add --all'
...
-1

The simple solution

Helpful for some problems, but NOT related to the removal of MANY aliases: If you want to delete one or two aliases and not want to overwrite them, put in .zshrc:

unalias <alias>

The advantage is that you can keep your plugin as is and do not have to touch it.

Timo
  • 326
  • 2
  • 10