zsh中的两个单词别名

时间:2012-07-08 01:45:34

标签: alias zsh

在ZSH中轻松做一个单词别名。

alias ll='ls -lah'

有没有办法用Zsh做两个单词别名,这样两个单词都被解析为同一个别名的一部分?我最喜欢将它用于拼写错误修复。

alias 'gits t'='git st'

2 个答案:

答案 0 :(得分:6)

试试这个:

alias func='gits t'
func() {
    'gits t'='git st'
}

有关 Zsh 别名函数的更多信息:

答案 1 :(得分:2)

与普通bash相同:

$ cd
$ vim .zshrc
...
tg() {
    if [ -z "$1" ]; then
        echo "Use correct second argument: apply/destroy/plan/etc"
    else
        if [ "$1" = "0all" ]; then
            terragrunt destroy -auto-approve && terragrunt apply -auto-approve
        elif [ "$1" = "0apply" ]; then
            terragrunt apply -auto-approve
        elif [ "$1" = "0destroy" ]; then
            terragrunt destroy -auto-approve
        else
            terragrunt "$@"
        fi
    fi
}
...

别忘了重新读取文件:

$ source .zshrc

使用后,例如:

$ tg 0apply