zsh-users
 help / color / mirror / code / Atom feed
* paths for filename arguments
@ 1999-10-07 13:38 Vincent Lefevre
  1999-10-07 16:10 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Vincent Lefevre @ 1999-10-07 13:38 UTC (permalink / raw)
  To: zsh-users

Is there a way to specify a path in arguments (a bit like with RISC OS,
for those who know -- but this would be done here at the shell level)?

For instance,

$ 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.

Perhaps this can already be done with variable expansion, but with a
more complicated syntax, I suppose...

One could also define compctl-like commands to avoid writing "less:",
so that

$ less --option blah

would add a correct path to "blah", but do nothing with "--option".

-- 
Vincent Lefèvre <vincent@vinc17.org> - PhD student in Computer Science
Web: <http://www.vinc17.org/> or <http://www.ens-lyon.fr/~vlefevre/> - 100%
validated HTML - Acorn Risc PC, Yellow Pig 17, Championnat International
des Jeux Mathématiques et Logiques, TETRHEX, etc.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: paths for filename arguments
  1999-10-07 13:38 paths for filename arguments Vincent Lefevre
@ 1999-10-07 16:10 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 1999-10-07 16:10 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-10-07 16:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-10-07 13:38 paths for filename arguments Vincent Lefevre
1999-10-07 16:10 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).