创建像git的日志两个字的命令别名? [英] Creating an alias for a two word command like git log?

查看:174
本文介绍了创建像git的日志两个字的命令别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,我有一个像 git的日志中的两道命令的apt-get安装我要添加默认参数。例如,大多数的时间我想了添加 - 缩写提交参数到我的 git的日志,和在 -y 参数的apt-get安装

Sometimes I have a two word command like git log or apt-get install that I want to add a default parameter to. For example, most of the time I want to add the --abbrev-commit parameter to my git log, and the -y parameter to apt-get install.

git log --abbrev-commit
apt-get install --abbrev-commit

不过,我似乎无法创建涉及两个单词的命令别名:

However, I can't seem to create an alias that involves two word commands:

$ alias 'git log'='git log --abbrev-commit'
bash: alias: `git log': invalid alias name
 $ alias git log='git log --abbrev-commit'
bash: alias: git: not found

我如何做到这一点?

How do I do this?

推荐答案

您不能做你使用一个shell别名想什么。这只是不是他们如何工作。在混帐一个你可以用git配置处理。运行:

You can't do what you're trying with a shell alias. That's just not how they work. The git one you can handle with git configuration. Run:

git config --global log.abbrevCommit true

或交替,修改〜/的.gitconfig 并添加:

[log]
    abbrevCommit = true

如果您想preFER有每个库行为,而不是编辑全局配置,你可以删除 - 全球标记或编辑项目的的.git /配置,而不是你的全局配置。

If you'd prefer to have per-repository behaviour rather than editing your global config, you can remove the --global flag or edit your project's .git/config instead of your global configuration.

apt-get的一会更难。你可以写一个bash函数来做到这一点,虽然。喜欢的东西(未经测试):

The apt-get one will be harder. You could write a bash function to do it, though. Something like (untested):

apt-get() {
    if [[ $1 == "install" ]]
    then
        command apt-get -y "$@"
    else
        command apt-get "$@"
    fi
}

这篇关于创建像git的日志两个字的命令别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆