创建一个包含bash命令替换和参数的git别名 [英] Creating a git alias containing bash command substitution and an argument
问题描述
知道了:
git diff $(git status -s | awk'FNR == $ LINE_NUM {print $ 2}')
...其中,行号是按状态输出的文件.
...where line number is the file output by status.
现在,我想在 .gitconfig
中为此命令创建一个别名:
Now I want to create an alias for this command in .gitconfig
:
[alias]
diff-num = $WHAT_SHOULD_I_PUT_HERE?
我希望该别名根据我将在命令行中键入的行号参数运行git的diff命令.我是bash的新手,我不确定是否需要bash函数来处理此问题或如何将参数传递给替代命令.
I want this alias to run git's diff command based on the line number argument I'll type in on the command line. I'm new to bash and I'm not sure if I need a bash function to handle this or how to pass the argument into the substituted command.
推荐答案
通常的形式是使用常规的!
shell逸出,定义一个任意命名的shell函数并运行git为它提供您的参数.我的第一个选择是 lgdo
,
The usual form for this is to use the conventional !
shell escape, define an arbitrarily-named shell function and run that, git supplies it with your args. One of my goto's is lgdo
,
git config alias.lgdo '!f() { git log --graph --decorate --oneline "${@---all}"; }; f'
另外,我有 gr
和 grl
作为 git config --get-regexp {,-local}
别名:
also, I have gr
and grl
as git config --get-regexp {,--local}
aliases:
[alias]
grl = "!f() { git config --local --get-regexp \"${@-.}\"; }; f"
gr = "!f() { git config --get-regexp \"${@-.}\"; }; f"
这篇关于创建一个包含bash命令替换和参数的git别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!