11.04.2013 Views

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Appen<strong>di</strong>ce K. Un esempio <strong>di</strong> file .bashrc<br />

complete -f -o default -X ’!*.+(htm*|HTM*)’ lynx html2ps<br />

# Multime<strong>di</strong>a<br />

complete -f -o default -X ’!*.+(jp*g|gif|xpm|png|bmp)’ xv gimp<br />

complete -f -o default -X ’!*.+(mp3|MP3)’ mpg123 mpg321<br />

complete -f -o default -X ’!*.+(ogg|OGG)’ ogg123<br />

complete -f -o default -X ’!*.pl’ perl perl5<br />

# This is a ’universal’ completion function - it works when commands have<br />

# a so-called ’long options’ mode , ie: ’ls --all’ instead of ’ls -a’<br />

_get_longopts ()<br />

{<br />

$1 --help | sed -e ’/--/!d’ -e ’s/.*--\([^[:space:].,]*\).*/--\1/’| \<br />

grep ^"$2" |sort -u ;<br />

}<br />

_longopts_func ()<br />

{<br />

case "${2:-*}" in<br />

-*) ;;<br />

*) return ;;<br />

esac<br />

case "$1" in<br />

\~*) eval cmd="$1" ;;<br />

*) cmd="$1" ;;<br />

esac<br />

COMPREPLY=( $(_get_longopts ${1} ${2} ) )<br />

}<br />

complete -o default -F _longopts_func configure bash<br />

complete -o default -F _longopts_func wget id info a2ps ls recode<br />

_make_targets ()<br />

{<br />

local mdef makef gcmd cur prev i<br />

COMPREPLY=()<br />

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

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

# if prev argument is -f, return possible filename completions.<br />

# we could be a little smarter here and return matches against<br />

# ‘makefile Makefile *.mk’, whatever exists<br />

case "$prev" in<br />

-*f) COMPREPLY=( $(compgen -f $cur ) ); return 0;;<br />

esac<br />

# if we want an option, return the possible posix options<br />

case "$cur" in<br />

802

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

Saved successfully!

Ooh no, something went wrong!