# dlocate.bash -- bash completion for dloc and dlocate # Copyright 2006, 2007 Kevin Ryde # dlocate.bash is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2, or (at your option) any later # version. # # dlocate.bash is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You can get a copy of the GNU General Public License online at # http://www.gnu.org/licenses, or you should have one in the file COPYING # which comes with GNU Emacs and other GNU programs. Failing that, write to # the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301 USA. # This script sets up command line completions in bash for the dlocate # program, and my modified "dloc" version of that. See "Programmable # Completion" and "Commands For Completion" in the bash manual for how these # completion setups work. # # This script can be used standalone, or together with the bash_completion # project # # http://freshmeat.net/projects/bashcompletion/ # # To install you can either # # 1) Source from your .bashrc, # # . /my-directory/dlocate.bash # # 2) Or load it with bash_completion, to have it only when using that, either # # 2a) Source from your ~/.bash_completion file, # # . /my-directory/dlocate.bash # # 2b) Or put it in the $BASH_COMPLETION_DIR directory (which might be for # instance "/etc/bash_completion.d", and bash_completion will source # it from there (along with everything else in that directory). # # Revisions: # Version 1 - the first version. _dlocate() { # $1 is command being completed, ie. "chart" # $2 is current word, ie. the one to complete # $3 is the preceding word local cur=$2 prev=$3 COMPREPLY=() case "$prev" in -conf | -L | -ls | -lsconf | -man | -md5sum | -md5check | -s) # currently installed debian package name, found from the directory # names under /usr/share/doc (much faster than running dpkg) COMPREPLY=( $(cd /usr/share/doc; compgen -X '.*' -f "$cur") ) return 0 ;; -S | -l) # glob and grep patterns return 0; esac # command line option case "$cur" in -*) # command line option local options=' -h -S -l -L -s -ls -lsconf -conf -du -md5sum -md5check -man --' local IFS=$' \n\t' COMPREPLY=( $( compgen -W "$options" -- $cur ) ) return 0 ;; esac return 0 } complete -F _dlocate dlocate complete -F _dlocate dloc # Local variables: # mode: sh # sh-shell: bash # End: