shell - 带参数的 ZSH 别名

标签 shell zsh alias zshrc

我正在尝试为我的简单 git add/commit/push 创建一个带参数的别名。

我看到函数可以用作别名,所以我尝试了但没有成功。

之前我有:

alias gitall="git add . ; git commit -m 'update' ; git push"

但我希望能够修改我的提交:

function gitall() {
    "git add ."
    if [$1 != ""]
        "git commit -m $1"
    else
        "git commit -m 'update'"
    fi
    "git push"
}

最佳答案

如果出于某种原因你真的需要使用带有参数的别名,你可以通过在你的别名中嵌入一个函数并立即执行它来破解它:

alias example='f() { echo Your arg was $1. };f'

我看到这种方法在 .gitconfig 别名中使用了很多。

关于shell - 带参数的 ZSH 别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34340575/

相关文章:

linux - 如何使用 zip ssh 命令压缩除特定其他文件夹之外的文件夹?

linux - 如何将包含路径的变量插入sed

vim - ZSH:如何在命令行中运行 Vim 风格的替代命令?

shell - "Exception handling"在 shell 脚本中

mysql - 查询Mysql错误: Not unique table/alias

linux - 在 rc.local 中通过管道将 echo 传送到 sendmail 失败

shell - 如何在 shell 脚本中使用 chmod

rvm - zsh中rbenv版本显示右键提示不刷新

search - 在ElasticSearch中搜索使用别名

git - "git checkout main_branch; git merge topic_branch"的别名?