I have an idea for a little command-line tool that would hopefully let me navigate directories quicker and I need to know if given a character from < STDIN > it is possible, from within perl, to automatically inject characters into < STDIN > dependent on the context (so it would look like an unsolicited tab-expansion if the circumstances are correct).
For example, supposing I had the following directories in some directory somewhere:
dir1 directory_2 test testing tested experiments
and contained in testing was the directories
fully_tested partially_tested
then invocation of the script would first list all directories cd-able from where I called and wait for input. If the first character I entered was a 't' I would like to automatically inject 'est' into STDIN (since "test" is in the union of test, testing, and tested), list all directories beginning with "test" and wait for further input.
if the next char was either 'e' or 'i' it would cd automatically into tested or testing respectively (since these directories are then uniquely determined), if it was some yet to be decided "easy to reach key" like * I would cd into test, hitting '.' would do a cd .., and hitting any other alphabetic character would have no effect (and perhaps some other easy to reach key might list everything).
Getting back to the example, typing the chars 'tef' means I would cd into testing/fully_tested (since 'te' uniquely matches testing and the 'f' uniquely matches fully_tested)
As for actually coding this up I would like it to be my own problem (I believe it is possible to process input on a char by char basis) so to reiterate, all I'm asking here is:
Does perl provide some mechanism via which STDIN can be modified without user interaction (such that I can emulate tab-expand on the commandline, but with this expansion happening behind the scenes)? Or in other words, on evaluation of the last input I want to silently do the tab expansion (with it "looking like a tab expansion" wrt to my input stream, as per the commandline) without explicitly hitting a < TAB >
More detail: as far as I know what I am doing presently what I would end up with once coded up is something that would look like the following at runtime (suppose my home directory has the folders Desktop, Documents, Documents_bak, Downloads, Music)
Desktop/ Documents/ Documents_bak/ Downloads/ Music
D
Desktop/ Documents/ Documents_bak/ Downloads
o
Documents/ Documents_bak/ Downloads
c
Documents/ Documents_bak
_
programming/ books/ ...(other directories)
which doesn't look very nice... What I would actually like is something that resembled
Desktop/ Documents/ Documents_bak/ Downloads/ Music
D
Desktop/ Documents/ Documents_bak/ Downloads
Do
Documents/ Documents_bak/ Downloads
Documents
Documents/ Documents_bak
Documents_bak/
programming/ books/ ...(other directories)
Documents_bak/
where the last line "Documents_bak/" is actually the input stream as though I had typed it all (so I could delete some of it if I wanted). It is only how to achieve this little bit that presents a problem to me
EDIT* I am not (as far as I'm aware) trying to reinvent the wheel here - I'm just trying to cut out the < TAB >, < RET >, retype 'cd ' steps when changing directories. I.e. with my scheme it would take just "tef" to cd into testing/fully_tested yet just in bash I need "t< TAB >i< TAB >< RET >cd< SPACE >f< TAB >< RET >" to do the same.