Olivier Favre-Simon wrote: > Jorge Godoy wrote: > >> Olivier Favre-Simon <[EMAIL PROTECTED]> writes: >> >> >> >>> That, plus: >>> >>> - Make it eXecutable: chmod +x start-myapp.py >>> >>> >> It is here... What's your umask? It's 022 here. >> >> >> > Sorry... must check eyesight :-/ > >>> - Add a bash-completion file for tg-admin: tg<tab>q<tab> woud yield >>> tg-admin quickstart >>> >>> >> Just if a zsh would also come together ;-) I don't use bash... ;-) >> >> >> > I'll try to do a bash-completion file (starting from the subversion one > because tg-admin has same CLI style as svn). > > zsh is great shell too (mostly originator of real command completion), > but I don't currently use it... > > Sorry for our Win32 friends too (cmd.exe anyone) . Do tools like > TotalCommander and others have shell completion too ? > > > Done. Here is a first draft of a bash-completion file for tg-admin.
Any improvements are welcome. BTW that's when you get involved in such old-fashioned scripts that you know why python is the greatest of all languages :-)) As for all other bashcomp files just source it from your .bash_profile or .bashrc, or simply source it from an already running shell.
# Programmable completion for the TurboGears tg-admin command under bash.
# Source this file (or add it to ~/.bash_completion and start a new shell)
# and bash's completion mechanism will know all about tg-admin's options!
# Shamelessly ripped from Subversion's svnadmin shell-completion source.
# Work with >=bash-2.05a with programmable completion and extended pattern
matching enabled
# (use 'shopt -s extglob progcomp' to enable these if they are not already
enabled).
shopt -s extglob
_tg-admin ()
{
local cur cmds cmdOpts optsParam opt helpCmds optBase i
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
cmds='quickstart shell sql toolbox update'
if [[ $COMP_CWORD -eq 1 ]] ; then
COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
return 0
fi
# options that require a parameter
# note: continued lines must end '|' continuing lines must start '|'
# optsParam="-r|--revision|--parent-dir|--fs-type"
### TODO ###
optsParam=""
# if not typing an option, or if the previous option required a
# parameter, then fallback on ordinary filename expansion
helpCmds='help|--help|h|\?'
if [[ ${COMP_WORDS[1]} != @($helpCmds) ]] && \
# [[ "$cur" != -* ]] || \
[[ ${COMP_WORDS[COMP_CWORD-1]} == @($optsParam) ]] ; then
return 0
fi
cmdOpts=
case ${COMP_WORDS[1]} in
quickstart)
cmdOpts="" ### TODO ###
;;
shell)
cmdOpts="" ### TODO ###
;;
sql)
if [[ $COMP_CWORD -eq 2 ]] ; then
cmdOpts="create drop execute list record sql status
upgrade"
else
cmdOpts=""
fi
;;
help)
cmdOpts="" ### TODO ###
;;
toolbox)
cmdOpts="" ### TODO ###
;;
update)
cmdOpts="" ### TODO ###
;;
*)
;;
esac
# cmdOpts="$cmdOpts help"
# take out options already given
for (( i=2; i<=$COMP_CWORD-1; ++i )) ; do
opt=${COMP_WORDS[$i]}
case $opt in
--*) optBase=${opt/=*/} ;;
-*) optBase=${opt:0:2} ;;
esac
cmdOpts=" $cmdOpts "
cmdOpts=${cmdOpts/ ${optBase} / }
# take out alternatives
case $optBase in
-q) cmdOpts=${cmdOpts/ --quiet / } ;;
--quiet) cmdOpts=${cmdOpts/ -q / } ;;
-h) cmdOpts=${cmdOpts/ --help / } ;;
--help) cmdOpts=${cmdOpts/ -h / } ;;
-r) cmdOpts=${cmdOpts/ --revision / } ;;
--revision) cmdOpts=${cmdOpts/ -r / } ;;
esac
# skip next option if this one requires a parameter
if [[ $opt == @($optsParam) ]] ; then
((++i))
fi
done
COMPREPLY=( $( compgen -W "$cmdOpts" -- $cur ) )
return 0
}
complete -F _tg-admin -o default tg-admin
signature.asc
Description: OpenPGP digital signature

