Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's a generalized version of another completion script I have that does something similar. It assumes a generic hypothetical command "flist", using some directory of files defined by FLIST_DIR to complete the command (omitting options). </p> <p>Modify the following for your program (<code>teamocil</code>), change the default dir from <code>$HOME/flist</code> to <code>$HOME/.teamocil</code>), define your own filters/transformations, etc; and then just source it (e.g., <code>. ~/bin/completion/bash_completion_flist</code>), optionally adding it to your existing list of bash completions. </p> <pre><code># bash_completion_flist: # for some hypothetical command called "flist", # generate completions using a directory of files FLIST_DIR=${FLIST_DIR=:-"$HOME/flist"} _flist_list_files() { ls $FLIST_DIR | sed 's/\..*//' } _flist() { local cur="${COMP_WORDS[COMP_CWORD]}" COMPREPLY=() [[ ${cur} != -* ]] \ &amp;&amp; COMPREPLY=($(compgen -W "$(_flist_list_files)" -- ${cur})) } complete -o bashdefault -o default -o nospace -F _flist flist 2&gt;/dev/null \ || complete -o default -o nospace -F _flist flist </code></pre> <p>Notes:</p> <ul> <li>it could be shorter, but this is more or less a template for longer, more complicated completions. (Functions are Good.)</li> <li>the actual completion command (<code>complete -o ...</code>) is a bit of a hack to work across different versions of bash.</li> <li>the suffix stripping is over-simplfied if there are "." in the filename, and is left as an exercise for the reader :-) There are multiple ways to do this (sed, awk, etc); the best is via bash-isms (<code>base=${filename%.*}</code>), but the easiest is arguably the simple sed with some assumptions about the filename format.</li> </ul>
 

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