generate shell auto-completion

This commit is contained in:
Mattias Andrée 2012-10-29 22:14:04 +01:00
parent 584823347f
commit 9342d79c9c
4 changed files with 39 additions and 102 deletions

View file

@ -1,36 +0,0 @@
# bash completion for ponysay -*- shell-script -*-
_ponysay()
{
local cur prev words cword
_init_completion -n = || return
options="--version --help --list --altlist --pony --wrap --quote --balloonlist --balloon --file ++file ++pony ++list ++altlist --all ++all"
options="$options --256-colours --tty-colours --kms-colours"
COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
if [ $prev = "-f" ] || [ $prev = "--pony" ] || [ $prev = "--file" ]; then
ponies=$('/usr/bin/ponysay' --onelist)
COMPREPLY=( $( compgen -W "$ponies" -- "$cur" ) )
elif [ $prev = "+f" ] || [ $prev = "++pony" ] || [ $prev = "++file" ]; then
extraponies=$('/usr/bin/ponysay' ++onelist)
COMPREPLY=( $( compgen -W "$extraponies" -- "$cur" ) )
elif [ $prev = "-q" ] || [ $prev = "--quote" ]; then
quoters=$('/usr/bin/ponysay' --quoters)
COMPREPLY=( $( compgen -W "$quoters" -- "$cur" ) )
elif [ $prev = "-b" ] || [ $prev = "--balloon" ] || [ $prev = "--bubble" ]; then
balloons=$('/usr/bin/ponysay' --balloonlist)
COMPREPLY=( $( compgen -W "$balloons" -- "$cur" ) )
elif [ $prev = "-W" ] || [ $prev = "--wrap" ]; then
cols=$(( `stty size | cut -d ' ' -f 2` - 10 ))
COMPREPLY=( $cols $(( $cols / 2 )) 100 60 none inherit )
fi
}
complete -o default -F _ponysay ponysay

View file

@ -1,27 +0,0 @@
# fish completion for ponysay -*- shell-script -*-
# Author: Elis Axelsson <etu AT elis DOT nu>
set -g ponies ('/usr/bin/ponysay' --onelist)
set -g xponies ('/usr/bin/ponysay' ++onelist)
set -g quoters ('/usr/bin/ponysay' --quoters)
set -g balloons ('/usr/bin/ponysay' --balloonlist)
## TODO: update with options [see info manual]: +f +l +L ++list ++altlist ++file --file ++pony {-A, +A, -V, -K, -X}(with alternative)
complete --command ponysay --short-option h --long-option help --description 'help of ponysay'
complete --command ponysay --short-option v --long-option version --description 'version of ponysay'
complete --command ponysay --short-option l --long-option list --description 'list pony names'
complete --command ponysay --short-option L --long-option altlist --description 'list pony names with alternatives'
complete --command ponysay --short-option B --long-option balloonlist --description 'list balloon style names'
complete --command ponysay --short-option f --long-option pony --arguments "$ponies" --description 'pony'
#complete --command ponysay --short-option F --arguments "$xponies" --desc#ription 'extra pony'
complete --command ponysay --short-option q --long-option quote --arguments "$quoters" --no-files --description 'pony'
complete --command ponysay --short-option b --long-option balloon --arguments "$balloons" --no-files --description 'balloon style'
complete --command ponysay --short-option W --long-option wrap --arguments 'Integer' --description 'specify the column when the message should be wrapped' ## TODO arguments `none` and `inherit` should be suggested
complete --command ponysay --arguments 'MESSAGE'
set -e ponies
set -e xponies
set -e quoters
set -e balloons

View file

@ -1,33 +0,0 @@
# zsh completion for ponysay -*- shell-script -*-
#compdef ponysay ponythink
_opts=(
'(--version -v)'{-v,--version}'[Show version and exit]'
'(-h --help)'{-h,--help}'[Show this help and exit]'
'(-l --list)'{-l,--list}'[list pony names]'
'(-L --altlist)'{-L,--altlist}'[list pony names with alternatives]'
'(+l ++list)'{+l,++list}'[list extra pony names]'
'(+L ++altlist)'{+L,++altlist}'[list extra pony names with alternatives]'
'(-B --balloonlist)'{-B,--balloonlist}'[list balloon style names]'
'(-b --ballon)'{-b,--balloon}'[Selecy a balloon style]: :_path_files -W '/usr/share/ponysay/balloons' -g "*(\:r)"'
'(-c --compact)'{-c,--compat}'[Compress messages.]'
'(-W --wrap)'{-W,--wrap}'[The screen column where the message should be wrapped]' # TODO arguments `none` and `inherit` should be suggested
)
_tty_select=(
'(-q --quite)'{-q,--quote}'[Select ponies for MLP:FiM quotes]: :_path_files -W '/usr/share/ponysay/ttyponies' -g "*(\:r)"'
'(-f --pony)'{-f,--pony}'[select pony]: :_path_files -W '/usr/share/ponysay/ttyponies/' -g "*(\:r)"'
'(+f ++pony)'{+f,++pony}'[Select a extra pony]: :_path_files -W '/usr/share/ponysay/extrattyponies' -g "*(\:r)"'
)
_select=(
'(-q --quite)'{-q,--quote}'[Select ponies for MLP:FiM quotes]: :_path_files -W '/usr/share/ponysay/ponies' -g "*(\:r)"'
'(-f --pony)'{-f,--pony}'[select pony]: :_path_files -W '/usr/share/ponysay/ponies/' -g "*(\:r)"'
'(+f ++pony)'{+f,++pony}'[Select a extra pony]: :_path_files -W '/usr/share/ponysay/extraponies' -g "*(\:r)"'
)
if [[ "${(f)"$(tty)"##*/}" == "tty*" ]]; then
_arguments \
"$_opts[@]" \
"$_tty_select[@]"
else
_arguments \
"$_opts[@]" \
"$_select[@]"
fi

View file

@ -357,6 +357,8 @@ class Setup():
if fileout is not None: fileout.close() if fileout is not None: fileout.close()
if filein is not None: filein .close() if filein is not None: filein .close()
(fileout, filein) = (None, None)
env = conf['custom-env-python'] env = conf['custom-env-python']
if env is None: if env is None:
(out, err) = Popen(['env', 'python', '--version'], stdout=PIPE, stderr=PIPE).communicate() (out, err) = Popen(['env', 'python', '--version'], stdout=PIPE, stderr=PIPE).communicate()
@ -371,7 +373,6 @@ class Setup():
mane = True mane = True
break break
if mane: if mane:
(fileout, filein) = (None, None)
try: try:
fileout = open('ponysay.install', 'wb+') fileout = open('ponysay.install', 'wb+')
filein = open('ponysay.py', 'rb') filein = open('ponysay.py', 'rb')
@ -432,16 +433,44 @@ class Setup():
if ext is not None: if ext is not None:
compress('ponysay.pdf', 'ponysay.pdf.' + ext, ext) compress('ponysay.pdf', 'ponysay.pdf.' + ext, ext)
for command in commands:
source = 'completion/template'
sourceed = 'completion/template.%s' % (command)
try:
fileout = open(sourceed, 'wb+')
filein = open(source, 'rb')
data = filein.read().decode('utf-8', 'replace')
if data.startswith('(ponysay\n'):
data = ('(%s ' % command) + data[len('(ponysay\n'):]
elif data.startswith('(ponysay '):
data = ('(%s ' % command) + data[len('(ponysay '):]
elif '\n(ponysay\n' in data:
edpos = data.find('\n(ponysay\n')
data = data[:edpos] + ('\n(%s\n' % command) + data[edpas + len('\n(ponysay\n'):]
elif '\n(ponysay ' in data:
data = data[:edpos] + ('\n(%s ' % command) + data[edpas + len('\n(ponysay '):]
else:
raise Exception('File %s does not look like expected' % source)
fileout.write(data.encode('utf-8'))
finally:
if fileout is not None: fileout.close()
if filein is not None: filein .close()
for shell in [item[0] for item in shells]: for shell in [item[0] for item in shells]:
if conf[shell] is not None: if conf[shell] is not None:
src = 'completion/%s-completion.%s' % (shell, 'sh' if shell == 'bash' else shell)
for command in commands: for command in commands:
sourceed = 'completion/template.%s' % (command)
generated = 'completion/%s-completion.%s' % (shell, command)
generatorcmd = './completion/auto-auto-complete.py %s --output %s --source %s' % (shell, generated, sourceed)
Popen(generatorcmd.split(' ')).communicate()
if conf[command] is not None: if conf[command] is not None:
dest = src + '.' + command dest = generated + '.install'
(fileout, filein) = (None, None) (fileout, filein) = (None, None)
try: try:
fileout = open(dest, 'wb+') fileout = open(dest, 'wb+')
filein = open(src, 'rb') filein = open(generated, 'rb')
data = filein.read().decode('utf-8', 'replace') data = filein.read().decode('utf-8', 'replace')
data = data.replace('/usr/bin/ponysay', conf[command]) data = data.replace('/usr/bin/ponysay', conf[command])
@ -512,7 +541,7 @@ class Setup():
if conf[shell] is not None: if conf[shell] is not None:
for command in commands: for command in commands:
if conf[command] is not None: if conf[command] is not None:
src = 'completion/%s-completion.%s.%s' % (shell, 'sh' if shell == 'bash' else shell, command) src = 'completion/%s-completion.%s.install' % (shell, command)
dest = conf[shell].replace('ponysay', command) dest = conf[shell].replace('ponysay', command)
self.cp(False, src, [dest]) self.cp(False, src, [dest])
if conf['pdf'] is not None: if conf['pdf'] is not None:
@ -653,7 +682,8 @@ class Setup():
files.append('manuals/manpage%s.%s.%s' % (man, str(sec), comp)) files.append('manuals/manpage%s.%s.%s' % (man, str(sec), comp))
for shell in [item[0] for item in shells]: for shell in [item[0] for item in shells]:
for command in commands: for command in commands:
files.append('completion/%s-completion.%s.%s' % (shell, 'sh' if shell == 'bash' else shell, command)) files.append('completion/%s-completion.%s' % (shell, command))
files.append('completion/%s-completion.%s.install' % (shell, command))
self.removeLists(files, dirs) self.removeLists(files, dirs)
print() print()
@ -670,6 +700,9 @@ class Setup():
for shell in [item[0] for item in shells]: for shell in [item[0] for item in shells]:
files.append('completion/%s-completion.%s.install' % (shell, 'sh' if shell == 'bash' else shell)) files.append('completion/%s-completion.%s.install' % (shell, 'sh' if shell == 'bash' else shell))
files.append('completion/%s-completion-think.%s' % (shell, 'sh' if shell == 'bash' else shell)) files.append('completion/%s-completion-think.%s' % (shell, 'sh' if shell == 'bash' else shell))
for shell in [item[0] for item in shells]:
for command in commands:
files.append('completion/%s-completion.%s.%s' % (shell, 'sh' if shell == 'bash' else shell, command))
self.removeLists(files, dirs) self.removeLists(files, dirs)
print() print()