zsh-调用结束时没有空格的别名 [英] zsh - alias with no space at the end of the invocation

查看:102
本文介绍了zsh-调用结束时没有空格的别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个别名,例如:

I would like to have an alias like:

alias gra-bitbucket="gra origin https://gismoranas@bitbucket.org/gismoranas"

这样我就可以像这样使用它:

so that I can use it like:

gra-bitbucket/some-repo.git

将新来源添加到git存储库(gra是 oh-my-zsh!的别名)

to add a new origin to a git repository (gra is a oh-my-zsh! alias).

我的问题是我不想每次都写整个URL。它一定不能是别名,但是最好设置一个线性设置。

My issue is that I don't want to have to write the whole url each time. It must not be an alias, but it would be nice to have a one liner setting.

推荐答案

是为原始问题而写的,该问题并未消除它是否在别名调用中指定末尾没有空格,还是在调用的命令中别名定义的代码与用户提供的代码之间没有空格。 >

Note that this is written for the original question, which did not disambiguate whether it specified "no space at the end" of the invocation of the alias, or no space between the alias-defined code and user-provided code in the invoked command.

请勿为此使用别名;函数是更好的工具。

Don't use an alias for that; a function is the better tool.

gra-bitbucket() { gra origin https://gismoranas@bitbucket.org/gismoranas"$@"; }

如果您的shell是bash而不是zsh,则需要使用 function 关键字定义名称中带有短划线的函数(POSIX规则不允许使用)。因此:

If your shell were bash rather than zsh, you would need to use the function keyword to define a function with a dash in the name (which is disallowed under POSIX rules). Thus:

# this version works with bash as well (but not POSIX sh)
function gra-bitbucket { gra origin https://gismoranas@bitbucket.org/gismoranas"$@"; }

...或者,如果要与任何POSIX shell兼容,请删除-(在这种情况下,用 _ 代替):

...or, if you want to be compliant with any POSIX shell, remove the - from the name (in this case, substituting a _):

# this version works with all POSIX shells
gra_bitbucket() { gra origin https://gismoranas@bitbucket.org/gismoranas"$@"; }






在所有这些情况下,用法(但(以POSIX格式进行的名称更改)与您所需的别名相同,是否可以使用该别名:


In all of these cases, usage (but for the name change in the POSIX form) is identical to what it would be for your desired alias, were that alias possible:

gra-bitbucket /some-repo.git

...将引用 https://gismoranas@bitbucket.org/gismoranas/some-repo.git

这篇关于zsh-调用结束时没有空格的别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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