Bash: melhorando a complementação de comandos


sudo su -
# bash completion
linha=`awk '/enable bash completion/ {print NR}' /etc/bash.bashrc`
sed -i.backup "$((linha+1)),$((linha+3))s/^#//g" /etc/bash.bashrc

# uma vez configurado você pode por exemplo ver as opções do find assim
find -[tab][tab]

sudo apt-get install -y bash-completion-lib
sudo apt-get install -y python-optcomplete

# complementos para django: http://djangoadvent.com/1.2/improved-bash-completion/
# baixe este arquivo
# e insira também no ~/bashrc
if [[ -f ~/bin/django_bash_completion ]]; then
. ~/bin/django_bash_completion
fi

Esta informação também foi compartilhada aqui: http://ur1.ca/0zsee
Um artigo sobre complementação do Django.
Artigo do Eustáquio Rangel sobre a complementação de comandos do git

Artigo em ingles sobre completion http://aplawrence.com/Unix/customtab.html
other http://www.oreillynet.com/linux/blog/2007/02/improving_bash.html
more here.

Video do Linux Journal


Um script para incrementar as coisas, desse cara.
#!/bin/bash
_opts () {
perl -ne '
print if s/^.IP .\\fB\\-/-/ and s/\\(f(P|I|B|R)|)|".*//g;
print if s/^.IX Item .\-/-/ and s/"//g;
print if s/^.It Fl /-/;'
}
_man_generic() {
local IFS=$'\t\n' cmd cur opts
cur="${COMP_WORDS[COMP_CWORD]}"
cmd=$(basename "$1")
opts=$( for n in $(manpath | tr ':' '\n'); do \
n="$n/man1/${cmd}.1"; \
[ -f "$n" ] && cat "$n" | _opts; \
[ -f "$n".gz ] && gunzip -c "$n".gz | _opts; \
done | perl -pe 's/, | (--)/\n$1/' | sort | uniq )
COMPREPLY=($(compgen -W "$opts" -- "$cur"))
}
# just add a line like the following
# for any command you wish completed
complete -o default -F _man_generic wget
complete -o default -F _man_generic curl
complete -o default -F _man_generic rsync
# or alternatively, use a slicker syntax
for cmd in ls wget curl rsync; do
complete -o default -F _man_generic $cmd
done

linux-cookbook

Grupos do Google
Participe do grupo linux-cookbook
E-mail:
Visitar este grupo