cmd, readline, and /path/filename completion
Chris Liechti
cliechti at gmx.net
Wed Jul 24 04:28:03 EDT 2002
Dave Cinege <dcinege at psychosis.com> wrote in
news:mailman.1027493794.5576.python-list at python.org:
> Dunno much about programming readline, so maybe this is obvious.
me neither
> I toying with a unix shell written in python using shlex and cmd.
> (For now based on the _Python 2.1 Bible_ lextocon example...)
>
> It's actually quite functional at this point. (Though replacing
> bash with it, doesn't quite work yet... <grin>)
>
> I'm trying to tweak the readline functionality, and am a bit lost.
>
> In Bash
> cd /etc/<tab>
> Will display a list of files in /etc/ to complete against.
>
> In my shell, I will always see the files in the current directory.
>
> What must be done to mimic the bash functionaly?
i think you have to search all directories in os.environ["PATH"] for
executables if its the first word on the line, except when its a path, only
search that dir.
search the current dir if its the second or so arg/word on the line (more
specific, you first have to check if the word is a valid path an list that
dir it it is, otherwise list the current sir and both only if it isn't
already a file).
> Is it an option that
> must be turned on in readline? Do I have to snag the line, and if it
> is a valid path, cd to that path? (then back to PWD)
you don't need to change the directory. just use os.listdir() the get a
list of files. (and fileter that for executables with os.stat() in the firt
case)
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list