質問

I have the following alias

alias ackalias "acknoredirect !:2-$ '^[\sun]alias.?(!:1)' ~/.alias"

The problem is that it doesn't work if I do ackalias tmux; it always needs 2 or more arguments. For example, the following works great: ackalias tmux -A 2 -B 2

Is it possible to replace !:2-$ in the alias definition with something that says that 2nd and more arguments are optional?

Update
@Mark As you suggested, I tried out the below simple example and found issues when I have 2 or more optional arguments. Check the below example:

alias test2 'echo \!:1* \!:2* \!:3* \!:4*' test2 a test2 a b test2 a b c test2 a b c d test2 a b c d e

The output was:

a a b b a b c b c c a b c d b c d c d d a b c d e b c d e c d e d e

I might need to add if conditions but it should eventually work. Thanks.

役に立ちましたか?

解決 2

Finally this worked!

alias test4 'set arg1 = `echo \!:1* | awk '"'"'{ print $1 }'"'"'`; \\ echo -n "Arg num 1 = $arg1 "; \\ set arg2 = `echo \!:2* | awk '"'"'{ print $1 }'"'"'`; \\ echo -n "Arg num 2 = $arg2 "; \\ set arg3 = `echo \!:3* | awk '"'"'{ print $1 }'"'"'`; \\ echo -n "Arg num 3 = $arg3 "; \\ set arg4 = `echo \!:4* | awk '"'"'{ print $1 }'"'"'`; \\ echo -n "Arg num 4 = $arg4 "; \\ set arg5 = `echo \!:5* | awk '"'"'{ print $1 }'"'"'`; \\ echo -n "Arg num 5 = $arg5 "; \\ echo ""; \\ ' test4 abc test4 abc def ghi test4 abc def ghi jkl test4 abc def ghi jkl mno test4 abc def ghi jkl mno pqr I soon need to start converting to zsh..

他のヒント

try

alias ackalias "acknoredirect \!:2* '^[\sun]alias.?(\!:1)' ~/.alias"

(note I also added escapes before the !'s)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top