Is there a way to "import" a list of words into bash's read builtin to have custom tab-completion? I've been writing a wrapper script for suckless' minimalist irc client "ii", and I don't have a way to tab-complete nicks.
1 Answer
I am pretty sure bash can't do that. But in zsh
foo() { local -a compcontext compcontext=( ${(f)"$(</tmp/names)"} ) vared -c -p 'Enter in user: ' user } Will generate a list of matches from a file with a single name on each line.
Or, if you want to complete words for read and not the input it reads; in bash complete -W "$(</tmp/names)" read will accomplish that.
- What do you mean by "words for read and not the input"? Not sure I understand you. I know you can tab-complete file names with
read -e, but I'd like to be able to tab-complete custom words.Thomas Berryhill– Thomas Berryhill2014-10-06 16:57:00 +00:00Commented Oct 6, 2014 at 16:57 - Arguments for
read, like completing the -e.llua– llua2014-10-06 17:03:58 +00:00Commented Oct 6, 2014 at 17:03 - Ah, I see. Well, I might look into that zsh solution then. Bash would be preferred, though.Thomas Berryhill– Thomas Berryhill2014-10-06 17:08:10 +00:00Commented Oct 6, 2014 at 17:08
- Just want to confirm that his is still true even as of bash 5.0. No manipulation with
completechanges the behavior, the completion database is totally ignored byread -e.kkm mistrusts SE– kkm mistrusts SE2019-11-24 06:55:00 +00:00Commented Nov 24, 2019 at 6:55