Junio C Hamano <gitster@xxxxxxxxx> 于2021年4月2日周五 上午3:49写道: > > ZheNing Hu <adlternative@xxxxxxxxx> writes: > > >> The way to do the same without an extra script on disk is for you to > >> use sh-c yourself. > >> > >> .cmd = sh -c 'echo 123' > > > > This is indeed a viable solution, But the extra "sh -c" seems to put an > > unnecessary burden on the user. > > Nobody forces you to write long script in the configuration file. > In fact, the "find author from history" is so useful that I'd think > people have an alias or a script in ~/bin/ already for their own > interactive use. E.g. > > $ cat ~/bin/git-who > #!/bin/sh > git log -1 --format="%an <%ae>" --author="$1" > $ cat ~/bin/git-one > #!/bin/sh > git show -s --pretty=reference "$1" > > and with them: > > trailer.key.cmd = git who > > that is internally wrapped into > > sh -c 'git who "$@"' > > and fed "gitster@" as the first parameter when "--trailer=key:gitster@" > is given would work just fine. > Okay, now I get it. This allows us to run some common scripts or just use "sh -c". I might need some additional tests to illustrate those changes made by using '.cmd'. > > Sometimes I wonder, why not recommend using environment variables > > like $ARG? > > I am also fine with that; when we discovered the design flaw of > .command, I think I suggested either would make a viable choice. > The only downside is that it would squat on a good name $ARG and > forbids end-users from using the symbol for other purpose, but as > long as the application is limited in scope, that would be fine. I agree with you. This may indeed be a minor drawback. Thanks, Junio. -- ZheNing Hu