27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

complete −F _make_targets −X '+($*|*.[cho])' make gmake pmake<br />

# cvs(1) completion<br />

_cvs ()<br />

{<br />

local cur prev<br />

COMPREPLY=()<br />

cur=${COMP_WORDS[COMP_CWORD]}<br />

prev=${COMP_WORDS[COMP_CWORD−1]}<br />

if [ $COMP_CWORD −eq 1 ] || [ "${prev:0:1}" = "−" ]; then<br />

COMPREPLY=( $( compgen −W 'add admin checkout commit diff \<br />

export history import log rdiff release remove rtag status \<br />

tag update' $cur ))<br />

else<br />

COMPREPLY=( $( compgen −f $cur ))<br />

fi<br />

return 0<br />

}<br />

complete −F _cvs cvs<br />

_killall ()<br />

{<br />

local cur prev<br />

COMPREPLY=()<br />

cur=${COMP_WORDS[COMP_CWORD]}<br />

# get a list of processes (the first sed evaluation<br />

# takes care of swapped out processes, the second<br />

# takes care of getting the basename of the process)<br />

COMPREPLY=( $( /usr/bin/ps −u $USER −o comm | \<br />

sed −e '1,1d' −e 's#[]\[]##g' −e 's#^.*/##'| \<br />

awk '{if ($0 ~ /^'$cur'/) print $0}' ))<br />

}<br />

return 0<br />

complete −F _killall killall killps<br />

# A meta−command completion function for commands like sudo(8), which need to<br />

# first complete on a command, then complete according to that command's own<br />

# completion definition − currently not quite foolproof (e.g. mount and umount<br />

# don't work properly), but still quite useful − By Ian McDonald, modified by me.<br />

_my_command()<br />

{<br />

local cur func cline cspec<br />

COMPREPLY=()<br />

cur=${COMP_WORDS[COMP_CWORD]}<br />

if [ $COMP_CWORD = 1 ]; then<br />

COMPREPLY=( $( compgen −c $cur ) )<br />

elif complete −p ${COMP_WORDS[1]} &>/dev/null; then<br />

cspec=$( complete −p ${COMP_WORDS[1]} )<br />

if [ "${cspec%%−F *}" != "${cspec}" ]; then<br />

# complete −F <br />

#<br />

# COMP_CWORD and COMP_WORDS() are not read−only,<br />

# so we can set them before handing off to regular<br />

Appendix G. A Sample .bashrc File 427

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!