2

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.

0

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 Oct 6 '14 at 16:57
  • Arguments for read, like completing the -e. – llua Oct 6 '14 at 17:03
  • Ah, I see. Well, I might look into that zsh solution then. Bash would be preferred, though. – Thomas Berryhill Oct 6 '14 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.