Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ig: loop until users sends SIGINT

  • Loading branch information...
commit 3dcc61d26b80962dff0e61215c76687a8b9ed14a 1 parent cca0048
@falconindy authored
Showing with 13 additions and 6 deletions.
  1. +13 −6 ig
View
19 ig
@@ -4,18 +4,25 @@
# 'interactive' grep
#
+showfile() {
+ local file linenum choice=$1
+
+ # sanitize $choice of control characters and split
+ IFS=':' read file linenum _ < <(sed 's/\[[[:digit:]]*[mK]//g' <<< "$choice")
+
+ vim "$file" +$linenum
+}
+
(( $# < 2 )) && { echo "usage: ${0##*/} [grep-options] <pattern> files..."; exit 1; } >&2
IFS=$'\n' read -r -d $'\0' -a results < <(grep --color=always -n "$@")
(( ${#results[@]} )) || exit 1
+PS3="select a # or ^C to end] "
while [[ -z $choice ]]; do
- select choice in "${results[@]}"; do break; done
+ select choice in "${results[@]}"; do
+ showfile "$choice"
+ done
done
-# sanitize choice of control characters and split
-IFS=':' read file linenum _ < <(sed 's/\[[[:digit:]]*[mK]//g' <<< "$choice")
-
-vim "$file" +$linenum
-
Please sign in to comment.
Something went wrong with that request. Please try again.