简体   繁体   English

将zsh函数参数传递给grep -E

[英]Passing zsh function parameter to grep -E

Background... 背景...

Trying to find which commit(s) last touched a specific file. 尝试查找哪个提交最后触及了特定文件。

I can do this on the CLI piping from git-log to grep but I'm trying to wrap this in a zsh function, more for ease of memory. 我可以在从git-loggrep的CLI管道中执行此操作,但是我试图将其包装在zsh函数中,以简化存储。

Here's my function, and then here is the output I'd like to generate with it. 这是我的函数,然后是我想用它生成的输出。

# match lines from git log that start with commit or include the
# filename I'm interested in and then pipe back through grep to color the output
glpg() {
  \git log --name-only | \grep -E ‘“$"|^commit\s\S' | \grep -B1 --color -E ‘$'
}

Desired usage and output 所需的用法和输出

dwight:assets (add-analytics*) $ glpg clickouts
commit 6662418b8e68e478b95e7254faa6406abdada30f
web/assets/app/viewmodels/clickouts.js
web/assets/app/views/clickouts.html
web/client/app/viewmodels/clickouts.js
web/client/app/views/clickouts.html
--
commit cee37549f613985210c9caf90a48e2cca28d4412
web/client/app/viewmodels/clickouts.js
web/client/app/views/clickouts.html
--
commit df9ea8cd90ff80b89a0c7e2b0657141b105d5e7e
web/client/app/viewmodels/clickouts.js
web/client/app/views/clickouts.html

Three problems. 三个问题。

  • You use Unicode apostrophes and quotes, ' and “. 您可以使用Unicode撇号和引号“和”。 Replace them with ASCII quotes and doublequotes. 将其替换为ASCII引号和双引号。
  • You can't use \\s and \\S to mean space or non-space with a standard (POSIX) grep. 您不能使用\\ s和\\ S来表示标准(POSIX)grep的空格或非空格。 Use ' ' and [^ ] instead to be portable. 使用' '[^ ]代替可移植。
  • The list of all args is referenced with "$@" including the double quotes. 所有参数列表以"$@"引用,包括双引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM