8
1
I'd like to instruct bash to use a special method to perform completion on certain directory names. For example, bash would call a program of mine to perform completion if a path starts with "$$", and perform completion normally otherwise.
Is this at all possible? How would you implement it?
Bounty: I'd really appreciate an answer to that question. The goal is to allow autojump to complete paths for all commands when the user starts them with a certain prefix. So for example when copying a file from a far directory, you could type:
cp $$patern + <Tab>
and autojump would complete
cp /home/user/CompliCatedDireCTOry/long/path/bla/bla
and you would just have to add where you want to put the file. Of course I can use ott's comment to add it to a few specific commands, but if anyone has a better idea, I'd be very grateful.
If you vote to close my question, please explain why. – Peltier – 2011-09-07T11:44:20.983
See the section "Programmable Completion" in the bash man page. – None – 2011-09-07T11:35:44.807
2"complete" supports "-G pattern" to match your $$ an the beginning and "-F func" to call your own function, but it needs one or more command names to work. – None – 2011-09-07T13:14:50.320
Why not just use an environment variable? For example: cp $prefix/file /path/to/dest/ – Xenoactive – 2011-09-09T19:58:50.387
@Xenoactive: because autojump is fully automated, and works on more than one path. Using manually set environment variables doesn't help. Or maybe you have a powerful idea that I don't understand? – Peltier – 2011-09-10T10:34:19.447