fned (597B) [raw]
1 #!/bin/sh 2 # fned -- file:number editor 3 # reads file:number:blah (grep-style) from stdin or ARGV and opens 4 # the file in $EDITOR at that point (for vi/m). Other editors just 5 # open the file & print the line 6 # 7 # example: 8 # 9 # fned "$(git grep -n 'pattern' | fzf)" 10 # 11 # see also: plumb(1) 12 # 13 die() { 14 echo "$*" 1>&2 15 exit 1 16 } 17 [ -z "$1" ] && die "usage: fned 'file:line:desc'" 18 19 fstr="$*" 20 file=${fstr%%:*} 21 nofile=${fstr##$file:} 22 line=${nofile%%:*} 23 24 case ${EDITOR:-vi} in 25 vi*) $EDITOR -c "$line" "$file" ;; 26 *) 27 echo "fned: $EDITOR doesn't support line jumps. Go to $line" 28 $EDITOR "$file" 29 ;; 30 esac