#!/bin/sh path=. files= pattern="*" editlist= editoption= if [ "$#" = 0 ]; then echo "Usage: mvim [...]" echo "Examples:" echo " mvim lib .pm : List all files under lib/ that match *.pm" echo " mvim .pm : List all files under ./ that match *.pm" echo " mvim lib : List all files under lib/" echo " mvim lib .pm -o : List all files under lib/ that match .pm, save '-o' for an argument to vim" exit fi if [ "$#" -gt 0 ]; then i=1 for arg in $*; do if [ -d "$arg" ]; then path=$arg if [ "$i" = "$#" ]; then pattern="*" newfiles=`find $path -name "$pattern" -type f | grep -v "\.svn"` files="$files $newfiles" fi elif [ -f "$arg" ]; then files="$files $arg" elif [[ "$arg" =~ '^-' ]]; then editoption="$editoption $arg" else pattern="*$arg*" newfiles=`find $path -name "$pattern" -type f | grep -v "\.svn"` files="$files $newfiles" fi i=$(($i + 1 )); done fi PS3="Enter the number of the file to edit. CTRL-D to finish. > " select f in $files; do if [ "$f" = "" ]; then if [ -f "$REPLY" ]; then f=$REPLY elif [ "$REPLY" = "all" ]; then editlist=$files break fi fi if [ "$f" != "" ]; then echo "Adding $f" editlist="$editlist $f" fi done if [ "$editlist" != "" ]; then vim $editoption $editlist fi