Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This not too elegant postprocessing solution seems to work for me (GNU bash, version 3.1.17(6)-release (i686-pc-cygwin)). (Unless I didn't test some border case as usual :))</p> <p>Don't need to eval things, there are only 2 kinds of quotes.</p> <p>Since compgen doesn't want to escape spaces for us, we will escape them ourselves (only if word didn't start with a quote). This has a side effect of full list (on double tab) having escaped values as well. Not sure if that's good or not, since ls doesn't do it...</p> <p>EDIT: Fixed to handle single and double qoutes inside the words. Essentially we have to pass 3 unescapings :). First for grep, second for compgen, and last for words command itself when autocompletion is done.</p> <pre><code>_find_words() { search=$(eval echo "$cur" 2&gt;/dev/null || eval echo "$cur'" 2&gt;/dev/null || eval echo "$cur\"" 2&gt;/dev/null || "") grep -- "^$search" words.dat | sed -e "{" -e 's#\\#\\\\#g' -e "s#'#\\\'#g" -e 's#"#\\\"#g' -e "}" } _words_complete() { local IFS=$'\n' COMPREPLY=() local cur="${COMP_WORDS[COMP_CWORD]}" COMPREPLY=( $( compgen -W "$(_find_words)" -- "$cur" ) ) local escaped_single_qoute="'\''" local i=0 for entry in ${COMPREPLY[*]} do if [[ "${cur:0:1}" == "'" ]] then # started with single quote, escaping only other single quotes # [']bla'bla"bla\bla bla --&gt; [']bla'\''bla"bla\bla bla COMPREPLY[$i]="${entry//\'/${escaped_single_qoute}}" elif [[ "${cur:0:1}" == "\"" ]] then # started with double quote, escaping all double quotes and all backslashes # ["]bla'bla"bla\bla bla --&gt; ["]bla'bla\"bla\\bla bla entry="${entry//\\/\\\\}" COMPREPLY[$i]="${entry//\"/\\\"}" else # no quotes in front, escaping _everything_ # [ ]bla'bla"bla\bla bla --&gt; [ ]bla\'bla\"bla\\bla\ bla entry="${entry//\\/\\\\}" entry="${entry//\'/\'}" entry="${entry//\"/\\\"}" COMPREPLY[$i]="${entry// /\\ }" fi (( i++ )) done } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload