framework pour la complétion automatique

This commit is contained in:
Jephté Clain 2015-03-18 16:55:12 +04:00
parent 14752bd09b
commit 9c17a60f45
6 changed files with 54 additions and 33 deletions

View File

@ -0,0 +1,16 @@
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
function __nutools_host_completion() {
local cur prev
_get_comp_words_by_ref cur prev
if [ "$prev" == "-h" -o "$prev" == "-H" ]; then
_known_hosts_real "$cur"
fi
}
if [ -n "$BASH_COMPLETION_DIR" -a -f "$BASH_COMPLETION_DIR/ssh" ]; then
shopt -u hostcomplete
complete -F _ssh ussh cssh
fi
complete -F __nutools_host_completion -o default ruinst runs rruns

View File

@ -0,0 +1,8 @@
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
function __pdev_branches() {
git for-each-ref --format='%(refname:short)' refs/heads |
grep -vF master |
grep -v '^release-' |
grep -v '^hotfix-'
}

View File

@ -5,42 +5,21 @@ if [ -n "$UTOOLS_BASH_COMPLETION" ]; then
if [ -f /etc/debian_version ]; then if [ -f /etc/debian_version ]; then
case "$(</etc/debian_version)" in case "$(</etc/debian_version)" in
6*|squeeze*) 6*|squeeze*)
# le code suivant n'est compatible qu'avec debian squeeze # le code suivant n'est compatible qu'avec debian squeeze (plus
if [ -z "$BASH_COMPLETION" -a "${BASH_VERSINFO[0]}" -ge 4 ]; then # exactement, avec bash 4.0)
source "@@dest@@/lib/ulib/bash_completion" source "@@dest@@/lib/ulib/bash40/completion"
fi
if [ -n "$BASH_COMPLETION" ]; then
if [ -n "$BASH_COMPLETION_DIR" -a -f "$BASH_COMPLETION_DIR/ssh" ]; then
shopt -u hostcomplete
complete -F _ssh ussh cssh
fi
function _nutools_h() {
local cur prev
_get_comp_words_by_ref cur prev
if [ "$prev" == "-h" -o "$prev" == "-H" ]; then
_known_hosts_real "$cur"
fi
}
complete -F _nutools_h -o default ruinst runs rruns
function __pdev_branches() {
git for-each-ref --format='%(refname:short)' refs/heads |
grep -vF master |
grep -v '^release-' |
grep -v '^hotfix-'
}
function _pdev() {
local cur
_get_comp_words_by_ref cur
COMPREPLY=($(compgen -W "$(__pdev_branches)" "$cur"))
}
complete -F _pdev pdev
fi
;; ;;
7*|wheezy*) 7*|wheezy*)
# le code suivant n'est compatible qu'avec debian wheezy # le code suivant n'est compatible qu'avec debian wheezy (plus
# exactement, avec bah 4.1)
#source "@@dest@@/lib/ulib/bash41/completion"
;; ;;
esac esac
fi fi
if [ -n "$BASH_COMPLETION" ]; then
for i in "$@@dest@@/lib/bash_completion.d/"*; do
[ -f "$i" ] || continue
source "$i"
done
fi
fi fi

View File

@ -32,6 +32,12 @@ done
./udist --nutools-makelinks ./udist --nutools-makelinks
./ulink --nutools-makelinks ./ulink --nutools-makelinks
# complétion programmable
bcdir=lib/bash_completion.d
./pdev --nutools-completion >"$bcdir/pdev"
#./prel --nutools-completion >"$bcdir/prel"
#./pfix --nutools-completion >"$bcdir/pfix"
# copier le fichier .nutoolsrc # copier le fichier .nutoolsrc
[ -f ~/.nutoolsrc ] || cp lib/nutoolsrc ~/.nutoolsrc [ -f ~/.nutoolsrc ] || cp lib/nutoolsrc ~/.nutoolsrc

12
pdev
View File

@ -1,5 +1,17 @@
#!/bin/bash #!/bin/bash
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
if [ $# -eq 1 -a "$1" == --nutools-completion ]; then
echo '
function __pdev_completion() {
local cur
_get_comp_words_by_ref cur
COMPREPLY=($(compgen -W "$(__pdev_branches)" "$cur"))
}
complete -F __pdev_completion pdev
'
fi
source "$(dirname "$0")/lib/ulib/ulib" || exit 1 source "$(dirname "$0")/lib/ulib/ulib" || exit 1
urequire DEFAULTS ptools urequire DEFAULTS ptools