From 9c17a60f45c7c1f29ec932c33145c0497aea9bb5 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 18 Mar 2015 16:55:12 +0400 Subject: [PATCH 1/4] =?UTF-8?q?framework=20pour=20la=20compl=C3=A9tion=20a?= =?UTF-8?q?utomatique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/bash_completion.d/nutools | 16 +++++++ lib/bash_completion.d/ptools | 8 ++++ lib/bashrc.d/bash_completion.nutools | 45 +++++-------------- lib/uinst/conf | 6 +++ .../{bash_completion => bash40/completion} | 0 pdev | 12 +++++ 6 files changed, 54 insertions(+), 33 deletions(-) create mode 100644 lib/bash_completion.d/nutools create mode 100644 lib/bash_completion.d/ptools rename lib/ulib/{bash_completion => bash40/completion} (100%) diff --git a/lib/bash_completion.d/nutools b/lib/bash_completion.d/nutools new file mode 100644 index 0000000..1df64fb --- /dev/null +++ b/lib/bash_completion.d/nutools @@ -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 diff --git a/lib/bash_completion.d/ptools b/lib/bash_completion.d/ptools new file mode 100644 index 0000000..41b14d3 --- /dev/null +++ b/lib/bash_completion.d/ptools @@ -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-' +} diff --git a/lib/bashrc.d/bash_completion.nutools b/lib/bashrc.d/bash_completion.nutools index 35ac9a5..2f97b73 100644 --- a/lib/bashrc.d/bash_completion.nutools +++ b/lib/bashrc.d/bash_completion.nutools @@ -5,42 +5,21 @@ if [ -n "$UTOOLS_BASH_COMPLETION" ]; then if [ -f /etc/debian_version ]; then case "$("$bcdir/pdev" +#./prel --nutools-completion >"$bcdir/prel" +#./pfix --nutools-completion >"$bcdir/pfix" + # copier le fichier .nutoolsrc [ -f ~/.nutoolsrc ] || cp lib/nutoolsrc ~/.nutoolsrc diff --git a/lib/ulib/bash_completion b/lib/ulib/bash40/completion similarity index 100% rename from lib/ulib/bash_completion rename to lib/ulib/bash40/completion diff --git a/pdev b/pdev index e050b6b..7fdce59 100755 --- a/pdev +++ b/pdev @@ -1,5 +1,17 @@ #!/bin/bash # -*- 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 urequire DEFAULTS ptools From 041a830245dc493808111a9b9bc4a945c07eedfa Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 18 Mar 2015 17:26:21 +0400 Subject: [PATCH 2/4] suite du support de bash_completion --- lib/bashrc.d/bash_completion.nutools | 6 ++--- .../bash40/{completion => bash_completion} | 16 +++++++++---- lib/ulib/bash41/bash_completion | 24 +++++++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) rename lib/ulib/bash40/{completion => bash_completion} (99%) create mode 100644 lib/ulib/bash41/bash_completion diff --git a/lib/bashrc.d/bash_completion.nutools b/lib/bashrc.d/bash_completion.nutools index 2f97b73..428db05 100644 --- a/lib/bashrc.d/bash_completion.nutools +++ b/lib/bashrc.d/bash_completion.nutools @@ -7,12 +7,12 @@ if [ -n "$UTOOLS_BASH_COMPLETION" ]; then 6*|squeeze*) # le code suivant n'est compatible qu'avec debian squeeze (plus # exactement, avec bash 4.0) - source "@@dest@@/lib/ulib/bash40/completion" + source "@@dest@@/lib/ulib/bash40/bash_completion" ;; 7*|wheezy*) # le code suivant n'est compatible qu'avec debian wheezy (plus - # exactement, avec bah 4.1) - #source "@@dest@@/lib/ulib/bash41/completion" + # exactement, avec bash 4.1) + source "@@dest@@/lib/ulib/bash41/bash_completion" ;; esac fi diff --git a/lib/ulib/bash40/completion b/lib/ulib/bash40/bash_completion similarity index 99% rename from lib/ulib/bash40/completion rename to lib/ulib/bash40/bash_completion index 8ea7b15..26f73c6 100644 --- a/lib/ulib/bash40/completion +++ b/lib/ulib/bash40/bash_completion @@ -1,12 +1,20 @@ ##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 -## Fonctions pour l'autocomplétion bash, si le package bash-completion n'est pas installé -## Attention! Ces fonctions ne sont testées que sur Debian Squeeze. Ce module -## est incompatible avec bash_completion sur Debian Wheezy. +## Fonctions pour l'autocomplétion bash, si le package bash-completion n'est pas +## installé. ATTENTION! Ces fonctions ont été pour la plupart récupérées de +## l'implémentation sous Debian Squeeze, ce qui signifie qu'elles sont conçues +## pour fonctionner avec bash 4.0 ##@cooked nocomments ##@require base uprovide bash_completion -if [ -z "$BASH_COMPLETION" ]; then +function __is_bash_completion_enabled() { + [ -n "$BASH_COMPLETION" ] +} +function __is_bash_completion_module_enabled() { + [ -n "$BASH_COMPLETION_DIR" -a -f "$BASH_COMPLETION_DIR/$1" ] +} + +if ! __is_bash_completion_enabled; then BASH_COMPLETION=1 shopt -s extglob progcomp diff --git a/lib/ulib/bash41/bash_completion b/lib/ulib/bash41/bash_completion new file mode 100644 index 0000000..4cef4a1 --- /dev/null +++ b/lib/ulib/bash41/bash_completion @@ -0,0 +1,24 @@ +##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 +## Fonctions pour l'autocomplétion bash, si le package bash-completion n'est pas +## installé. ATTENTION! Ces fonctions ont été pour la plupart récupérées de +## l'implémentation sous Debian Wheezy, ce qui signifie qu'elles sont conçues +## pour fonctionner avec bash 4.1 +##@cooked nocomments +##@require base +uprovide bash_completion + +function __is_bash_completion_enabled() { + [ -n "$BASH_COMPLETION" ] && return 0 + grep -qE '^[ \t]*(\.|source)[ \t]*/usr/share/bash-completion/bash_completion' /etc/bash.bashrc && return 0 + grep -qE '^[ \t]*(\.|source)[ \t]*/usr/share/bash-completion/bash_completion' ~/.bashrc && return 0 + return 1 +} +function __is_bash_completion_module_enabled() { + [ -f "/usr/share/bash-completion/completions/$1" ] && return 0 + [ -n "$BASH_COMPLETION_COMPAT_DIR" -a -f "$BASH_COMPLETION_COMPAT_DIR/$1" ] +} + +if ! __is_bash_completion_enabled; then + export BASH_COMPLETION=1 + : +fi From e8d683b91a73178c3387497a9558f0fd74291c32 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 18 Mar 2015 17:45:36 +0400 Subject: [PATCH 3/4] bug --- pdev | 1 + 1 file changed, 1 insertion(+) diff --git a/pdev b/pdev index 7fdce59..9cb6af2 100755 --- a/pdev +++ b/pdev @@ -10,6 +10,7 @@ function __pdev_completion() { } complete -F __pdev_completion pdev ' + exit 0 fi source "$(dirname "$0")/lib/ulib/ulib" || exit 1 From 163df888d8b9623ee03e2c876d4f2687a71611e8 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 18 Mar 2015 17:54:45 +0400 Subject: [PATCH 4/4] bug --- lib/bashrc.d/bash_completion.nutools | 2 +- lib/ulib/bash41/bash_completion | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/bashrc.d/bash_completion.nutools b/lib/bashrc.d/bash_completion.nutools index 428db05..aed8e57 100644 --- a/lib/bashrc.d/bash_completion.nutools +++ b/lib/bashrc.d/bash_completion.nutools @@ -17,7 +17,7 @@ if [ -n "$UTOOLS_BASH_COMPLETION" ]; then esac fi if [ -n "$BASH_COMPLETION" ]; then - for i in "$@@dest@@/lib/bash_completion.d/"*; do + for i in "@@dest@@/lib/bash_completion.d/"*; do [ -f "$i" ] || continue source "$i" done diff --git a/lib/ulib/bash41/bash_completion b/lib/ulib/bash41/bash_completion index 4cef4a1..ab79ef5 100644 --- a/lib/ulib/bash41/bash_completion +++ b/lib/ulib/bash41/bash_completion @@ -8,17 +8,18 @@ uprovide bash_completion function __is_bash_completion_enabled() { - [ -n "$BASH_COMPLETION" ] && return 0 + [ -n "$__NUTOOLS_BASH_COMPLETION" ] && return 0 grep -qE '^[ \t]*(\.|source)[ \t]*/usr/share/bash-completion/bash_completion' /etc/bash.bashrc && return 0 grep -qE '^[ \t]*(\.|source)[ \t]*/usr/share/bash-completion/bash_completion' ~/.bashrc && return 0 return 1 } function __is_bash_completion_module_enabled() { [ -f "/usr/share/bash-completion/completions/$1" ] && return 0 - [ -n "$BASH_COMPLETION_COMPAT_DIR" -a -f "$BASH_COMPLETION_COMPAT_DIR/$1" ] + [ -n "$BASH_COMPLETION_COMPAT_DIR" -a -f "$BASH_COMPLETION_COMPAT_DIR/$1" ] && return 0 + return 1 } if ! __is_bash_completion_enabled; then - export BASH_COMPLETION=1 - : + export __NUTOOLS_BASH_COMPLETION=1 fi +[ -n "$BASH_COMPLETION" ] || export BASH_COMPLETION=1