CMDER:如何在另一个别名中使用别名? [英] Cmder : how to use an alias in another alias?

查看:193
本文介绍了CMDER:如何在另一个别名中使用别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会在Cmder中的另一个别名中使用一个别名。

I would use an alias in another alias in Cmder.

我对一个大命令有一个很好的别名(第一个),我会使用它在另一个(第二个)内部:

I'm having a nice alias (the first) to a big command, and I would use it inside another one (the second) :

mergelocdist=git fetch origin --prune --verbose && git checkout $1 && git merge --ff-only --verbose origin/$2 || git rebase --preserve-merges --verbose origin/$2

mm=mergelocdist master master

别名在Cmder 别名文件中,而我在Windows 7 x64上。

The aliases are in the Cmder aliases file, and I'm on Windows 7 x64.

已经在此问题中提出了该主题,至今没有任何答复。

The topic has already been asked in this question,with no replies as now.

如果您回答我,也请回答这个人:)

If you answer to me, please also answer to this guy :)

找到了,似乎有帮助,但我不知道如何。

Found this, seems to have something to help but I don't figure how.

推荐答案

Benj:
我怀疑您现在已经找到答案了,但是我发现没有人回答这个问题,所以我会的。

Benj: I suspect that you've already found an answer by now, but I see that no one has answered this question, so I will.

如果我可以提出其他建议,别名文件。

If I may make an alternative suggestion to the aliases file. It looks like you're trying to solve this for git.

我发现在Windows中执行此操作的最佳方法是编辑 〜/ .bashrc 文件。在大多数Windows计算机上,它将位于 C:\Users\< USERNAME> \.bashrc 下。

The best way I've found to do this in Windows is to edit the ~/.bashrc file. On most Windows machines it would be under C:\Users\<USERNAME>\.bashrc.

您可以创建一个函数,例如:

You can create a function such as:

function MergeLocDistFn {
    local co_branch=$1
    local merge_branch=$2

    echo ">> Debug Command: git checkout ${co_branch}"
    git checkout ${co_branch}

    echo ">> Debug Command: git merge --ff-only --verbose origin/${merge_branch} || git rebase --preserve-merges --verbose origin/${merge_branch}"
    git merge --ff-only --verbose origin/${merge_branch} || git rebase --preserve-merges --verbose origin/${merge_branch}
}

然后,您可以在〜/ .bashrc 文件中创建别名,如下所示:

Then you can create aliases in the ~/.bashrc file, like the following:

alias mergelocdist=MergeLocDistFn
alias mm='MergeLocDistFn master master'

The这种方法的优点是,它将使您的函数真正变得更加复杂,正如我在此处所示,也可以使用echo语句对其进行调试。

The advantage to this approach is that it will allow you to get really sophisticated with the function and as I'm showing here, debug it as well with echo statements.

请参见随附示例输出的图片。
bashrc的示例输出

See the attached picture of the example output. example output from bashrc

还请注意,如果您希望在PowerShell提示符下执行此操作,则修改PowerShell配置文件甚至更加容易,只需告诉我,我会告诉您如何操作。

Note also, if you'd rather do this for a PowerShell prompt, it's even easier to modify the PowerShell profile, just let me know and I'll show you how.

另一个说明,您也可以在.bashrc中为当前分支创建一个函数。下面是一个示例函数:

Another note, you can also create a function in the .bashrc for the current branch. Here's an example function:

function current_branch() {
  ref=$(git symbolic-ref HEAD 2> /dev/null) || \
  ref=$(git rev-parse --short HEAD 2> /dev/null) || return
  echo ${ref#refs/heads/}
}

使用current_branch函数的示例:

Here's an example of using the current_branch function:

alias gpush='git push -u origin $(current_branch)'

我希望他能帮上忙,只要您需要任何澄清,请告诉我。

I hope that his helps, just let me know if you need any clarifications on this.

这篇关于CMDER:如何在另一个别名中使用别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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