Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

jabsync

  • Loading branch information...
commit 5235aafe63fe80d19efc08a65ee2d14270291b5c 1 parent 3e483b7
JAB authored

Showing 3 changed files with 108 additions and 13 deletions. Show diff stats Hide diff stats

  1. +83 0 bin/srcedit
  2. +15 8 bin/srcfind
  3. +10 5 bin/srcgrep
83 bin/srcedit
... ... @@ -0,0 +1,83 @@
  1 +#!/usr/bin/env bash
  2 +set -e
  3 +
  4 +helpstr="\
  5 +NAME
  6 + srcedit - edit files that contain matches to the given regular expression
  7 +
  8 +SYNOPSIS
  9 + srcedit [-d DIRECTORY] [GREP_OPTIONS] PATTERN
  10 +
  11 +DESCRIPTION
  12 + See srcfind for directories and files that ignored in the search. Binary
  13 + files are also ignored (grep's -I option).
  14 +
  15 + All arguments that are not options of this script are passed as-is to
  16 + grep. In order to pass options to grep and not have them be interpreted by
  17 + this script, set them off with the standard \`--'. For example, to do a
  18 + case-insensitive grep (grep's -i), use:
  19 +
  20 + srcedit -- -i PATTERN
  21 +
  22 +OPTIONS
  23 + -d, --directory DIRECTORY
  24 + The parent directory in which to search. Can be used multiple times.
  25 +
  26 + -e, --editor-command COMMAND
  27 + The command to use to edit a file. It should take one argument, the
  28 + filename. The default is 'gvim -f'.
  29 +
  30 + -h, --help
  31 + Print this help.
  32 +
  33 +REQUIREMENTS
  34 + srcgrep
  35 +
  36 +AUTHOR
  37 + John Brunelle
  38 +"
  39 +
  40 +directories=()
  41 +editor_command="gvim -f"
  42 +
  43 +args=$(getopt -l directory:editor-command:,help -o d:e:h -- "$@")
  44 +if [ $? -ne 0 ]; then
  45 + exit 65 #(getopt will have written the error message)
  46 +fi
  47 +eval set -- "$args"
  48 +while [ ! -z "$1" ]; do
  49 + case "$1" in
  50 + -d | --directory)
  51 + directories[${#directories[@]}]="$2"
  52 + shift
  53 + ;;
  54 + -e | --editor-command)
  55 + editor_command="$2"
  56 + shift
  57 + ;;
  58 +
  59 + -h | --help)
  60 + echo -n "$helpstr"
  61 + exit 0
  62 + ;;
  63 + --)
  64 + shift
  65 + break
  66 + ;;
  67 + esac
  68 + shift
  69 +done
  70 +
  71 +if [ ${#directories[@]} -eq 0 ]; then
  72 + directories=(.)
  73 +fi
  74 +
  75 +set -u
  76 +
  77 +
  78 +#---
  79 +
  80 +set +e #want to be able to abort certain ones and keep going
  81 +for d in "${directories[@]}"; do
  82 + srcgrep -d "$d" -- -l "$@" | xargs -I% $editor_command %
  83 +done
23 bin/srcfind
@@ -18,7 +18,7 @@ DESCRIPTION
18 18
19 19 OPTIONS
20 20 -d, --directory DIRECTORY
21   - The parent directory in which to search.
  21 + The parent directory in which to search. Can be used multiple times.
22 22
23 23 -0
24 24 Use find's -print0 instead of -print.
@@ -33,7 +33,7 @@ AUTHOR
33 33 John Brunelle
34 34 "
35 35
36   -directory=.
  36 +directories=()
37 37 printopt='-print'
38 38
39 39 args=$(getopt -l directory:,help -o d:0h -- "$@")
@@ -44,7 +44,7 @@ eval set -- "$args"
44 44 while [ ! -z "$1" ]; do
45 45 case "$1" in
46 46 -d | --directory)
47   - directory="$2"
  47 + directories[${#directories[@]}]="$2"
48 48 shift
49 49 ;;
50 50 -0)
@@ -70,6 +70,10 @@ else
70 70 pattern='*'"$pattern"'*'
71 71 fi
72 72
  73 +if [ ${#directories[@]} -eq 0 ]; then
  74 + directories=(.)
  75 +fi
  76 +
73 77 set -u
74 78
75 79
@@ -77,8 +81,11 @@ set -u
77 81
78 82 #(not_mine is a hack that is not generally applicable)
79 83
80   -find "$directory" \
81   - \( -name .git -o -name .svn -o -name CVS \) -prune -o \
82   - \( -name '*.pyc' -o -name '*.swp' \) -prune -o \
83   - \( -name not_mine \) -prune -o \
84   - -iname "$pattern" $printopt
  84 +for d in "${directories[@]}"; do
  85 + find "$d" \
  86 + \( -name .git -o -name .svn -o -name CVS \) -prune -o \
  87 + \( -name '*.pyc' -o -name '*.swp' \) -prune -o \
  88 + \( -name _attic \) -prune -o \
  89 + \( -name not_mine \) -prune -o \
  90 + -iname "$pattern" $printopt
  91 +done
15 bin/srcgrep
@@ -21,7 +21,7 @@ DESCRIPTION
21 21
22 22 OPTIONS
23 23 -d, --directory DIRECTORY
24   - The parent directory in which to search.
  24 + The parent directory in which to search. Can be used multiple times.
25 25
26 26 -h, --help
27 27 Print this help.
@@ -33,7 +33,7 @@ AUTHOR
33 33 John Brunelle
34 34 "
35 35
36   -directory=.
  36 +directories=()
37 37
38 38 args=$(getopt -l directory:,help -o d:h -- "$@")
39 39 if [ $? -ne 0 ]; then
@@ -43,7 +43,7 @@ eval set -- "$args"
43 43 while [ ! -z "$1" ]; do
44 44 case "$1" in
45 45 -d | --directory)
46   - directory="$2"
  46 + directories[${#directories[@]}]="$2"
47 47 shift
48 48 ;;
49 49
@@ -59,10 +59,15 @@ while [ ! -z "$1" ]; do
59 59 shift
60 60 done
61 61
  62 +if [ ${#directories[@]} -eq 0 ]; then
  63 + directories=(.)
  64 +fi
  65 +
62 66 set -u
63 67
64 68
65 69 #---
66 70
67   -
68   -srcfind -d "$directory" -0 | xargs -0 grep --color -I "$@"
  71 +for d in "${directories[@]}"; do
  72 + srcfind -d "$d" -0 | xargs -0 grep --color -I "$@"
  73 +done

0 comments on commit 5235aaf

Please sign in to comment.
Something went wrong with that request. Please try again.