嘿,我想创建一个像这样的git存储库:
curl -u 'USER' https://api.github.com/user/repos -d '{"name":"REPO"}'
但是我想在终端(Ubuntu)中使用别名来做,比如
alias newRepo = curl -u 'USER' https://api.github.com/user/repos -d '{"name":"$1"}';
git remote add origin git@github.com:USER/$1.git;
所以在终端后我输入:
newRepo test
它创建了回购并添加了远程“原点”。
答案 0 :(得分:2)
你可以在" Git alias for displaying the GitHub commit url"中找到涉及shell函数的git别名的好例子。
当输入git config alias命令时,诀窍是找到单引号/双引号/转义的正确组合。
在你的情况下,考虑到你有一个'!',如果你是bash(no '!' within double quotes)
,你不能用双引号括起你的git config alias参数离开$
single quote ($'...'
},接受' !
',并转义单引号(再次使用bash;在zsh中更容易):
举个例子:
vonc@bigvonc MINGW64 /c/Users/vonc
$ git config --global --replace-all alias.newrepo2 '!f() { echo \'e\'; }; f'
bash: syntax error near unexpected token `}'
vonc@bigvonc MINGW64 /c/Users/vonc
$ git config --global --replace-all alias.newrepo2 $'!f() { echo \'e\'; }; f'
最后的命令是:
vonc@bigvonc MINGW64 /c/Users/vonc
$ git config --global --replace-all alias.newrepo $'!f() { curl -u \'USER\' https://api.github.com/user/repos -d \'{"name":"$1"}\'; git remote add origin git@github.com:USER/$1.git; }; f'
话虽如此,如果您输入curl -u 'USER' https://api.github.com/user/repos -d '{"name":"xxx"}'
,它会要求您提供' USER
'的密码。
这意味着:
USER
'应该是$(whoami)
git config
多命令别名似乎不支持等待在stdin中输入参数... 答案 1 :(得分:0)
您无法将参数传递给别名。创建一个bash函数。