Reputation: 5506
I'm adding some aliases to my .zshrc file and wondering if I can add an alias that doesn't execute immediately?
Example of usage I want:
I want to be able to have an alias for creating a new git branch
Ideally I can type the alias gcb
which will output git checkout -b
in the terminal and doesn't execute, then I can add the new branch name and hit enter.
Note:
I know I can do the following:
command alias_name
to prevent the alias immediately executing, but I'm seeking a way to do this without the command keyword as having to type that extra text almost defeats the purpose of the alias shortcut
Thanks!
Upvotes: 1
Views: 1082
Reputation: 22225
A definition
alias foo=bar
immediately defines the alias foo in the current zsh process. If you later type
foo x y
the command bar x y
is executed. Note that by definition of zsh, this behaviour only works in interactive shells. If you want to exploit this in a shell script, you have to enable alias expansion explicitly.
Upvotes: 1