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

Recent releases

  •  13 Sep 2013 13:29

    Release Notes: This release adds numerous new and improved completions and bugfixes.

    •  16 Jan 2011 18:39

      Release Notes: Feature enhancements and bugfixes.

      •  13 Oct 2009 19:22

        Release Notes: Bugfixes and feature enhancements.

        •  01 Mar 2006 18:42

          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.

          •  21 Jul 2005 22:00

            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.

            Recent comments

            12 Nov 2013 07:49 ranr

            where to download from?

            19 May 2010 04:04 joodas

            Hi, you might wanna have a look at ClearCase completion script. http://jan.tomka.name/project/clearcase-completion-bash

            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)

            Screenshot

            Project Spotlight

            OpenStack4j

            A Fluent OpenStack client API for Java.

            Screenshot

            Project Spotlight

            TurnKey TWiki Appliance

            A TWiki appliance that is easy to use and lightweight.