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.

# completion routine<br />

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

}<br />

# set current token number to 1 less than now<br />

COMP_CWORD=$(( $COMP_CWORD − 1 ))<br />

# get function name<br />

func=${cspec#*−F }<br />

func=${func%% *}<br />

# get current command line minus initial command<br />

cline="${COMP_LINE#$1 }"<br />

# split current command line tokens into array<br />

COMP_WORDS=( $cline )<br />

$func $cline<br />

elif [ "${cspec#*−[abcdefgjkvu]}" != "" ]; then<br />

# complete −[abcdefgjkvu]<br />

#func=$( echo $cspec | sed −e 's/^.*\(−[abcdefgjkvu]\).*$/\1/' )<br />

func=$( echo $cspec | sed −e 's/^complete//' −e 's/[^ ]*$//' )<br />

COMPREPLY=( $( eval compgen $func $cur ) )<br />

elif [ "${cspec#*−A}" != "$cspec" ]; then<br />

# complete −A <br />

func=${cspec#*−A }<br />

func=${func%% *}<br />

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

fi<br />

else<br />

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

fi<br />

complete −o default −F _my_command nohup exec eval trace truss strace sotruss gdb<br />

complete −o default −F _my_command command type which man nice<br />

# Local Variables:<br />

# mode:shell−script<br />

# sh−shell:bash<br />

# End:<br />

Appendix G. A Sample .bashrc File 428

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

Saved successfully!

Ooh no, something went wrong!