0

I've added tab completion for my program to bash. It works quite well, but I don't know how to handle partial completion of words. Example: the user types

./program /home/user/De

and presses TAB. This is then completed to

./program /home/user/Desktop/ 

, but there's now a trailing whitespace after 'Desktop/', which is not what I want. Basically, I need a way of preventing bash from adding whitespace after the completed word.

I don't want to use bash's completion for paths.

Edit: This seems to be unclear. When TAB is pressed, my tab-completion function finds out which word to complete (in this case, that's '/home/user/De'). It then generates a list of matches (in this case, the only match is '/home/user/Desktop'). Bash uses this list to do the actual completion: It changes '/home/user/De' to '/home/user/Desktop/ '. I want to prevent bash from adding that whitespace after 'Desktop/'.

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149

1 Answers1

0

tried it in speech marks ?

./program "/home/user/[tab]"

am unsure about this question in total :) bash actually does the auto completion am unsure how you have written a script that auto completes something that bash does for u -

anyhow... you have stated you don't want bash to add extra space - unless you plan to rewrite bash or add to it - this won't be possible

Instead this is something u need to add to your own code to remove white spaces. try

var1=${var1//[[:space:]]}

after getting the value in where var1 is variable name for input

V H
  • 8,382
  • 2
  • 28
  • 48
  • Same thing happens. Anyway, that's not something I can control - it's up to whoever's typing that to type it correctly. I'd like to make this easy for users. – Aran-Fey Oct 23 '12 at 10:48
  • Bash has a "Programmable Completion", see `man bash`. You can extend it specifically for commands, so that it expands to whatever you want. – Olaf Dietsche Oct 23 '12 at 11:14
  • 1
    http://stackoverflow.com/questions/10129747/conditional-trailing-space-with-bash-programmable-completion think its already answered here – V H Oct 23 '12 at 11:22
  • That's exactly what I needed! Thanks! Edit: Now, how do I mark this as solved? – Aran-Fey Oct 23 '12 at 11:39