Projects / bash programmable completion

bash programmable completion

Since v2.04, bash has allowed you to intelligently program and extend its standard completion behavior to achieve complex command lines with just a few keystrokes. Imagine typing ssh [Tab] and being able to complete on hosts from your ~/.ssh/known_hosts files. Or typing man 3 str [Tab] and getting a list of all string handling functions in the UNIX manual. mount system: [Tab] would complete on all exported file-systems from the host called system, while make [Tab] would complete on all targets in Makefile. This project was conceived to produce programmable completion routines for the most common Linux/UNIX commands, reducing the amount of typing sysadmins and programmers need to do on a daily basis.

Tags
Licenses
Operating Systems
Implementation

RSS Recent releases

  •  16 Jan 2011 19:34

    Release Notes: Feature enhancements and bugfixes.

    •  13 Oct 2009 21:07

      Release Notes: Bugfixes and feature enhancements.

      Release Notes: Many new completion functions have been added, and many existing ones have been improved or optimised. In addition, innumerable bugs have been fixed, including important bash 3.1 compatibility issues. This release is believed to be bash 3.1 compliant.

      Release Notes: The disabling of glob expansion in _filedir() has itself been disabled, as this triggered a bug in bash, which had the annoying effect of temporarily disabling alias expansion. mc completion has been greatly extended. A bug in lilo completion has been fixed. Improvements have been made to iwconfig completion. tcpdump and dhclient completion have been fixed to use the correct interfaces function. MPlayer options should now use dashes, not underscores.

      Release Notes: The patterns for tarball matching were fixed. Evince completion for .pdf files was added. More OpenOffice 2 completions were added. Completion for xine front-ends and kplayer/MPlayer was added.

      RSS Recent comments

      19 May 2010 04:04 joodas Thumbs up

      Hi, you might wanna have a look at ClearCase completion script. jan.tomka.name/project...

      26 Jan 2007 09:24 remberson

      svn mod: listing targets of imported build files
      in bash_completion _ant()

      change:

      local cur prev buildfile i

      to:

      local cur prev buildfile imports i f

      add:

      imports=(

      $( awk -F'"' '/<import file="/ {print $2}' \

      $buildfile )

      $( awk -F"'" "/<target name='/ "'{print $2}' \

      $buildfile )

      )

      for f in ${imports[@]}; do

      if [[ -e $f ]]; then

      COMPREPLY=( ${COMPREPLY[@]} \

      $( awk -F'"' '/<target name="/ {print $2}' \

      $f | grep "^$cur" | grep -v '^-' )

      $( awk -F"'" "/<target name='/ "'{print $2}' \

      $f | grep "^$cur" | grep -v '^-' )

      $( awk -F'"' '/<target [^n]/ {if ($1 ~ /name=/) { print $2 } else if ($3 ~ /name=/) {print $4} else if ($5 ~ /name=/) {print $6}}' \

      $f | grep "^$cur" | grep -v '^-' ) )

      fi

      done

      change:

      have complete-ant-cmd.pl && \

      complete -C complete-ant-cmd.pl -F _ant $filenames ant || \

      complete -F _ant $filenames ant

      }

      to:

      have complete-ant-cmd.pl && \

      complete -C complete-ant-cmd.pl -F _ant $filenames ant || \

      complete -F _ant ant

      }

      26 Jan 2007 09:21 remberson

      cd mod allowing ignore directories
      Allows one not to have to deal with '.svn' and

      'CVS' directories.

      in .bashrc

      cdignore=( CVS .svn )

      in bash_completion _cd() add:

      if [ -z "${CDPATH:-}" ] || [[ "$cur" == ?(.)?(.)/* ]]; then

      _filedir -d

      if [[ -n "$cdignore" ]]; then

      k=0

      a=()

      for f in ${COMPREPLY[@]}; do

      i=0

      for v in ${cdignore[@]}; do

      if [[ "$f" == "$v" ]]; then

      i=1

      fi

      done

      if [[ $i -eq 0 ]]; then

      a[k++]=$f

      fi

      done

      COMPREPLY=( ${a[@]} )

      fi

      return 0

      fi

      30 Dec 2006 01:32 toolguy

      Re: Example of broken completion (mixing env variable and path)
      A bit more work on it to get rid of the redunant loop yields:

      %_cd()
      %{
      > local IFS=$'\t\n' cur=${COMP_WORDS[COMP_CWORD]} i j k
      %
      %# (start of changes)
      > if [[ "$cur" == ?(\\)\$* ]]; then
      > local v vars
      > vars=($(for v in $(compgen -v -X !${cur#?(\\)$}*); do if [ -d "$(eval echo \$$v)" ]; then echo \$$v; fi; done))
      > if (( ${#vars[*]} == 1 )); then
      > # A single completion. Expand it.
      > COMPREPLY=($(eval echo $vars))
      > return 0
      > fi
      > # No single completion. Then just list the variables being directories.
      > COMPREPLY=(${vars[*]});
      > return 0
      > fi
      >
      %# old stuff ...
      %# # try to allow variable completion
      %# if [[ "$cur" == ?(\\)\$* ]]; then
      %# COMPREPLY=( $( compgen -v -P '$' -- "${cur#?(\\)$}" ) )
      %# return 0
      %# fi
      %# (unchanged from here)

      22 Dec 2006 23:24 toolguy

      Re: Example of broken completion (mixing env variable and path)
      Working a bit more on it, the follwoing code does the same more elegantly:

      _cd()

      {

      local IFS=$'\t\n' cur=${COMP_WORDS[COMP_CWORD]} i j k

      # Start of modifications

      if [[ "$cur" == ?(\\)\$* ]]; then

      local v vars=$(compgen -v -X !${cur#?(\\)$}*)

      COMPREPLY=(`for v in $vars; do if [ -d "$(eval echo \\$$v)" ]; then eval echo \\$$v; fi; done`)

      if (( ${#COMPREPLY[*]} == 1 )); then

      return 0

      fi

      # No single completion. Then just list the variables being directories.

      COMPREPLY=(`for v in $vars; do if [ -d "$(eval echo \\$$v)" ]; then echo \\$$v; fi; done`);

      return 0

      fi

      # old stuff removed

      # # try to allow variable completion

      # if [[ "$cur" == ?(\\)\$* ]]; then

      # COMPREPLY=( $( compgen -v -P '$' -- "${cur#?(\\)$}" ) )

      # return 0

      # fi

      #

      # (unchanged from here)

      Screenshot

      Project Spotlight

      KLone

      An embeddable Web server and SDK to write dynamic HTML pages using C/C++.

      Screenshot

      Project Spotlight

      TruPax

      Creates TrueCrypt volumes directly from files and folders.