From e325b776eb2fc65600e887d7edd87105888ba91b Mon Sep 17 00:00:00 2001 From: Xingyu Wang Date: Wed, 26 Feb 2020 11:49:01 +0800 Subject: [PATCH 1/2] PRF @geekpi --- ...20200219 Don-t like IDEs- Try grepgitvi.md | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/translated/tech/20200219 Don-t like IDEs- Try grepgitvi.md b/translated/tech/20200219 Don-t like IDEs- Try grepgitvi.md index a9b0118513..eaeda1abea 100644 --- a/translated/tech/20200219 Don-t like IDEs- Try grepgitvi.md +++ b/translated/tech/20200219 Don-t like IDEs- Try grepgitvi.md @@ -1,26 +1,27 @@ [#]: collector: (lujun9972) [#]: translator: (geekpi) -[#]: reviewer: ( ) +[#]: reviewer: (wxy) [#]: publisher: ( ) [#]: url: ( ) [#]: subject: (Don't like IDEs? Try grepgitvi) [#]: via: (https://opensource.com/article/20/2/no-ide-script) [#]: author: (Yedidyah Bar David https://opensource.com/users/didib) -不喜欢 IDE 么?试试看 grepgitvi +不喜欢 IDE?试试看 grepgitvi ====== -一个简单又原始的脚本来用 Vim 打开你选择的文件。 -![Files in a folder][1] -像大多数开发者一样,我整天都在搜索和阅读源码。就我个人而言,我从来没有习惯集成开发环境 (IDE),多年来,我主要使用 **grep** 并复制/粘贴的文件名来打开 Vi(m)。 +> 一个简单又原始的脚本来用 Vim 打开你选择的文件。 + +![](https://img.linux.net.cn/data/attachment/album/202002/26/113942a99a1aujmjpfnfrh.jpg) + +像大多数开发者一样,我整天都在搜索和阅读源码。就我个人而言,我从来没有习惯过集成开发环境 (IDE),多年来,我主要使用 `grep` (找到文件),并复制/粘贴文件名来打开 Vi(m)。 最终,我写了这个脚本,并根据需要缓慢地对其进行了完善。 -它依赖 [Vim][2] 和 [rlwrap][3],并使用 Apache 2.0 许可开源。要使用该脚本,请[将它放到 PATH 中][4],然后在文本目录下运行: - +它依赖 [Vim][2] 和 [rlwrap][3],并使用 Apache 2.0 许可证开源。要使用该脚本,请[将它放到 PATH 中][4],然后在文本目录下运行: ``` -`grepgitvi ` +grepgitvi ``` 它将返回搜索结果的编号列表,并提示你输入结果编号并打开 Vim。退出 Vim 后,它将再次显示列表,直到你输入除结果编号以外的任何内容。你也可以使用向上和向下箭头键选择一个文件。(这对我来说)更容易找到我已经看过的结果。 @@ -42,7 +43,7 @@ # # Requires vim and rlwrap # -# Usage: grepgitvi <grep options> <grep/vim pattern> +# Usage: grepgitvi # TMPD=$(mktemp -d /tmp/grepgitvi.XXXXXX) @@ -51,36 +52,36 @@ COLORED=${TMPD}/colored RLHIST=${TMPD}/readline-history -[ -z "${DIRS}" ] && DIRS=. +[ -z "${DIRS}" ] && DIRS=. cleanup() { -        rm -rf "${TMPD}" + rm -rf "${TMPD}" } trap cleanup 0 -find ${DIRS} -iname .git -prune -o \\! -iname "*.min.css*" -type f -print0 > ${TMPD}/allfiles +find ${DIRS} -iname .git -prune -o \! -iname "*.min.css*" -type f -print0 > ${TMPD}/allfiles -cat ${TMPD}/allfiles | xargs -0 grep --color=always -n -H "$@" > $COLORED -cat ${TMPD}/allfiles | xargs -0 grep -n -H "$@" > $UNCOLORED +cat ${TMPD}/allfiles | xargs -0 grep --color=always -n -H "$@" > $COLORED +cat ${TMPD}/allfiles | xargs -0 grep -n -H "$@" > $UNCOLORED max=`cat $UNCOLORED | wc -l` pat="${@: -1}" inp='' while true; do -        echo "============================ grep results ===============================" -        cat $COLORED | nl -        echo "============================ grep results ===============================" -        prompt="Enter a number between 1 and $max or anything else to quit: " -        inp=$(rlwrap -H $RLHIST bash -c "read -p \"$prompt\" inp; echo \$inp") -        if ! echo "$inp" | grep -q '^[0-9][0-9]*$' || [ "$inp" -gt "$max" ]; then -                break -        fi + echo "============================ grep results ===============================" + cat $COLORED | nl + echo "============================ grep results ===============================" + prompt="Enter a number between 1 and $max or anything else to quit: " + inp=$(rlwrap -H $RLHIST bash -c "read -p \"$prompt\" inp; echo \$inp") + if ! echo "$inp" | grep -q '^[0-9][0-9]*$' || [ "$inp" -gt "$max" ]; then + break + fi -        filename=$(cat $UNCOLORED | awk -F: "NR==$inp"' {print $1}') -        linenum=$(cat $UNCOLORED | awk -F: "NR==$inp"' {print $2-1}') -        vim +:"$linenum" +"norm zz" +/"${pat}" "$filename" + filename=$(cat $UNCOLORED | awk -F: "NR==$inp"' {print $1}') + linenum=$(cat $UNCOLORED | awk -F: "NR==$inp"' {print $2-1}') + vim +:"$linenum" +"norm zz" +/"${pat}" "$filename" done ``` @@ -91,7 +92,7 @@ via: https://opensource.com/article/20/2/no-ide-script 作者:[Yedidyah Bar David][a] 选题:[lujun9972][b] 译者:[geekpi](https://github.com/geekpi) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 From 0ca2df9cf88212e1a92c1ebe0a38f726c4438934 Mon Sep 17 00:00:00 2001 From: Xingyu Wang Date: Wed, 26 Feb 2020 11:50:00 +0800 Subject: [PATCH 2/2] PUB @geekpi https://linux.cn/article-11934-1.html --- .../20200219 Don-t like IDEs- Try grepgitvi.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename {translated/tech => published}/20200219 Don-t like IDEs- Try grepgitvi.md (98%) diff --git a/translated/tech/20200219 Don-t like IDEs- Try grepgitvi.md b/published/20200219 Don-t like IDEs- Try grepgitvi.md similarity index 98% rename from translated/tech/20200219 Don-t like IDEs- Try grepgitvi.md rename to published/20200219 Don-t like IDEs- Try grepgitvi.md index eaeda1abea..7284c57f0f 100644 --- a/translated/tech/20200219 Don-t like IDEs- Try grepgitvi.md +++ b/published/20200219 Don-t like IDEs- Try grepgitvi.md @@ -1,8 +1,8 @@ [#]: collector: (lujun9972) [#]: translator: (geekpi) [#]: reviewer: (wxy) -[#]: publisher: ( ) -[#]: url: ( ) +[#]: publisher: (wxy) +[#]: url: (https://linux.cn/article-11934-1.html) [#]: subject: (Don't like IDEs? Try grepgitvi) [#]: via: (https://opensource.com/article/20/2/no-ide-script) [#]: author: (Yedidyah Bar David https://opensource.com/users/didib)