-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgredit
More file actions
executable file
·53 lines (47 loc) · 1.08 KB
/
gredit
File metadata and controls
executable file
·53 lines (47 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# set -x
edit="vim %s +%s"
function runGrep {
found=`grep -n $@`
name=(`echo "$found" | awk -F ':' '{print $1}'`)
num=(`echo "$found" | awk -F ':' '{print $2}'`)
getDetails $@
editPrompt
}
function is_integer {
[ "$1" -eq "$1" ] > /dev/null 2>&1
return $?
}
function getDetails {
found=`grep -c $@`
files=(`echo "$found" | awk -F ':' '{print $1}'`)
occurs=(`echo "$found" | awk -F ':' '{print $2}'`)
filecount=0
occurance=0
for ((i=0; i<${#files[@]}; i++)); do
if is_integer ${occurs[$i]};
then
if [ "${occurs[$i]}" -gt "0" ];
then
let filecount=$filecount+1
filelist=(${filelist[@]} ${files[$i]})
let occurance=$occurance+${occurs[$i]}
fi
fi
done
printf "Found %s occurances in %s file(s)" $occurance $filecount
}
function editPrompt {
for ((i=0; i<${#name[@]}; i++)); do
if is_integer ${num[$i]};
then
printf "\nEdit on line %s of %s [Y/n] ? " ${num[$i]} ${name[$i]}
read prompt
if [ "$prompt" = "n" -o "$prompt" = "N" ]; then
continue
fi
`printf "$edit" ${name[$i]} ${num[$i]}`
fi
done
}
runGrep $@