Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

jabsync

  • Loading branch information...
commit 5235aafe63fe80d19efc08a65ee2d14270291b5c 1 parent 3e483b7
JAB authored
Showing with 108 additions and 13 deletions.
  1. +83 −0 bin/srcedit
  2. +15 −8 bin/srcfind
  3. +10 −5 bin/srcgrep
83 bin/srcedit
View
@@ -0,0 +1,83 @@
+#!/usr/bin/env bash
+set -e
+
+helpstr="\
+NAME
+ srcedit - edit files that contain matches to the given regular expression
+
+SYNOPSIS
+ srcedit [-d DIRECTORY] [GREP_OPTIONS] PATTERN
+
+DESCRIPTION
+ See srcfind for directories and files that ignored in the search. Binary
+ files are also ignored (grep's -I option).
+
+ All arguments that are not options of this script are passed as-is to
+ grep. In order to pass options to grep and not have them be interpreted by
+ this script, set them off with the standard \`--'. For example, to do a
+ case-insensitive grep (grep's -i), use:
+
+ srcedit -- -i PATTERN
+
+OPTIONS
+ -d, --directory DIRECTORY
+ The parent directory in which to search. Can be used multiple times.
+
+ -e, --editor-command COMMAND
+ The command to use to edit a file. It should take one argument, the
+ filename. The default is 'gvim -f'.
+
+ -h, --help
+ Print this help.
+
+REQUIREMENTS
+ srcgrep
+
+AUTHOR
+ John Brunelle
+"
+
+directories=()
+editor_command="gvim -f"
+
+args=$(getopt -l directory:editor-command:,help -o d:e:h -- "$@")
+if [ $? -ne 0 ]; then
+ exit 65 #(getopt will have written the error message)
+fi
+eval set -- "$args"
+while [ ! -z "$1" ]; do
+ case "$1" in
+ -d | --directory)
+ directories[${#directories[@]}]="$2"
+ shift
+ ;;
+ -e | --editor-command)
+ editor_command="$2"
+ shift
+ ;;
+
+ -h | --help)
+ echo -n "$helpstr"
+ exit 0
+ ;;
+ --)
+ shift
+ break
+ ;;
+ esac
+ shift
+done
+
+if [ ${#directories[@]} -eq 0 ]; then
+ directories=(.)
+fi
+
+set -u
+
+
+#---
+
+set +e #want to be able to abort certain ones and keep going
+for d in "${directories[@]}"; do
+ srcgrep -d "$d" -- -l "$@" | xargs -I% $editor_command %
+done
23 bin/srcfind
View
@@ -18,7 +18,7 @@ DESCRIPTION
OPTIONS
-d, --directory DIRECTORY
- The parent directory in which to search.
+ The parent directory in which to search. Can be used multiple times.
-0
Use find's -print0 instead of -print.
@@ -33,7 +33,7 @@ AUTHOR
John Brunelle
"
-directory=.
+directories=()
printopt='-print'
args=$(getopt -l directory:,help -o d:0h -- "$@")
@@ -44,7 +44,7 @@ eval set -- "$args"
while [ ! -z "$1" ]; do
case "$1" in
-d | --directory)
- directory="$2"
+ directories[${#directories[@]}]="$2"
shift
;;
-0)
@@ -70,6 +70,10 @@ else
pattern='*'"$pattern"'*'
fi
+if [ ${#directories[@]} -eq 0 ]; then
+ directories=(.)
+fi
+
set -u
@@ -77,8 +81,11 @@ set -u
#(not_mine is a hack that is not generally applicable)
-find "$directory" \
- \( -name .git -o -name .svn -o -name CVS \) -prune -o \
- \( -name '*.pyc' -o -name '*.swp' \) -prune -o \
- \( -name not_mine \) -prune -o \
- -iname "$pattern" $printopt
+for d in "${directories[@]}"; do
+ find "$d" \
+ \( -name .git -o -name .svn -o -name CVS \) -prune -o \
+ \( -name '*.pyc' -o -name '*.swp' \) -prune -o \
+ \( -name _attic \) -prune -o \
+ \( -name not_mine \) -prune -o \
+ -iname "$pattern" $printopt
+done
15 bin/srcgrep
View
@@ -21,7 +21,7 @@ DESCRIPTION
OPTIONS
-d, --directory DIRECTORY
- The parent directory in which to search.
+ The parent directory in which to search. Can be used multiple times.
-h, --help
Print this help.
@@ -33,7 +33,7 @@ AUTHOR
John Brunelle
"
-directory=.
+directories=()
args=$(getopt -l directory:,help -o d:h -- "$@")
if [ $? -ne 0 ]; then
@@ -43,7 +43,7 @@ eval set -- "$args"
while [ ! -z "$1" ]; do
case "$1" in
-d | --directory)
- directory="$2"
+ directories[${#directories[@]}]="$2"
shift
;;
@@ -59,10 +59,15 @@ while [ ! -z "$1" ]; do
shift
done
+if [ ${#directories[@]} -eq 0 ]; then
+ directories=(.)
+fi
+
set -u
#---
-
-srcfind -d "$directory" -0 | xargs -0 grep --color -I "$@"
+for d in "${directories[@]}"; do
+ srcfind -d "$d" -0 | xargs -0 grep --color -I "$@"
+done
Please sign in to comment.
Something went wrong with that request. Please try again.