zsh中的两个单词别名

24
在ZSH中创建一个单词别名很容易。
alias ll='ls -lah'

有没有一种方法可以在Zsh中使用两个单词别名,以便两个单词都被解析为同一个别名?我主要想用它来修正打字错误。
alias 'gits t'='git st'
2个回答

7

8
啊,这已经不再适用于我了... 要么显示"gits: command not found",要么是"gits:1: gits t=git st command not found"。 - Kevin Burke
2
这是因为它从来没有做过你想要的事情,而是做了其他的事情,并且不是正确的答案。自从5.4.2版本以来,默认情况下就会出现错误。https://unix.stackexchange.com/a/607909/5132 - JdeBP

4

与纯 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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接