zsh alias -> function?

前端 未结 2 962
一生所求
一生所求 2021-02-01 03:01

Suppose I have:

alias gg=\"git grep\"

then stuff like:

gg \"int x\"

works, but

gg int x
         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 03:49

    For your particular use case, this is a bad idea. git-grep is expecting a single-arg pattern. You're trying to get the shell to treat your space (between int and x) as part of the pattern. This will break quickly when you try something like: gg foo.*bar or various other things that the shell might interpret. So anything after gg really should be quoted. This is why git grep int x also doesn't work: fatal: ambiguous argument 'x': unknown revision or path not in the working tree...

    If you think gg is a worthwhile keystroke saver, you should keep your arg to it consistent with what git-grep expects. Your original alias is fine for this. And continue to single- or double-quote your pattern, just like you do with any other regex-accepting command.

提交回复
热议问题