Unix - Custom autocomplete functions

From NoskeWiki
Jump to navigation Jump to search


NOTE: This page is a daughter page of: Unix

Programmable completion is a powerful tool which allows you to type any string (say: "myprintprogram") and then if you hit [tab],[tab] (tab key twice) it will show you the options available (eg: "--printhtml --printtxt help").

Simle Completion Function in Bash


#! /bin/csh
  local cur=${COMP_WORDS[COMP_CWORD]}
  COMPREPLY=( $(compgen -W "alpha beta bar baz" -- $cur) )
complete -F _foo foo

Now test by typing:

$ ~/autocomplete_foo.sh
$ foo b[TAB][TAB]
  beta bar baz

Simle Completion Function in Zsh

This represents a page the author has not finished yet, but hopefully will finish soon! As a wiki I can't guarantee the accuracy on any of these pages, but pages with this logo I can almost certainly guarantee DO contain errors and/or big omissions.