Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: paths for filename arguments



On Oct 7,  3:38pm, Vincent Lefevre wrote:
} Subject: paths for filename arguments
}
} $ lesspath=(~/text ~/doc)
} $ less less:blah
} 
} should make zsh search for file "blah" in the working directory, and
} if it is not there, it should be searched in ~/text, then ~/doc. Before
} executing less, zsh should replace "less:" by nothing or the correct
} path element.

You can do this with a shell function wrapper around the commands that
you want to have this behavior, as long as you're willing to have the
"functionargzero" option set.

pathmagic=(less more vi)	# put all such commands in this array
function $pathmagic {
    integer i=0
    local file search
    while ((i++ < $#)); do
	if [[ $argv[i] == $0\:* ]]; then
	    eval 'search=(. $'$0path ')'
	    for file in $^search/${argv[i]#$0\:}; do
		if [[ -f $file ]]; then
		    argv[i]=$file
		    break
		fi
	    done
	fi
    done
    command $0 "$@"
}

Now each of the commands named in the `pathmagic' array will recognize a
$path-style variable prefixed with its name (lesspath, morepath, vipath,
etc.) and will convert arguments of the form command:file into files in
the corresponding path.

Fixing it so that

	vi less:foo more:bar

also works, is left as an exercise for the reader.

You could of course also do this with completion, but then the expanded
forms appear in the history so history references won't track changes to
the path variables.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author