瀏覽代碼

Update for newer saturnin

Alois Mahdal 4 年之前
父節點
當前提交
5b1ef1bd55
共有 6 個文件被更改,包括 106 次插入33 次删除
  1. 4
    2
      mkit.ini
  2. 2
    1
      packaging/debian/dottum.install
  3. 2
    1
      packaging/template.spec
  4. 4
    0
      src/app.skel
  5. 86
    29
      src/complete.bash.skel
  6. 8
    0
      src/complete/install.sh

+ 4
- 2
mkit.ini 查看文件

@@ -26,6 +26,7 @@
26 26
     XDG_CONFIG_HOME = $HOME/.config
27 27
 
28 28
 [roots]
29
+    bcompl  = /usr/share/bash-completion/completions
29 30
     bin     = [ENV:PREFIX]/bin
30 31
     doc     = [ENV:PREFIX]/share/doc/dottum
31 32
     libexec = [ENV:PREFIX]/libexec/dottum
@@ -43,7 +44,7 @@
43 44
     __SATURNIN_SHARE__        = [roots:share]
44 45
     __VDEP_SHELLFU_GE__  = 0.10.10
45 46
     __VDEP_SHELLFU_LT__  = 0.11.0
46
-    __VDEP_SATURNIN_GE__ = 0.5.0
47
+    __VDEP_SATURNIN_GE__ = 0.5.6
47 48
     __VDEP_SATURNIN_LT__ = 0.6.0
48 49
 
49 50
 [modes]
@@ -51,12 +52,13 @@
51 52
     libexec = 755
52 53
 
53 54
 [files]
55
+    bcompl  = src/complete.bash                 dottum
54 56
     bin = src/app dottum
55 57
     doc = LICENSE.md
56 58
     doc = README.md
57
-    etc_bc = src/complete.bash dottum.bash
58 59
     libexec = src/libexec/dottum-install
59 60
     sfincb  = src/shellfu/dottum.sh
60 61
     share   = src/help
62
+    share   = src/complete
61 63
 
62 64
 #mkit version=0.0.35

+ 2
- 1
packaging/debian/dottum.install 查看文件

@@ -1,6 +1,7 @@
1
-/etc/bash_completion.d/dottum.bash
2 1
 /usr/bin/dottum
3 2
 /usr/libexec/dottum/dottum-install
3
+/usr/share/bash-completion/completions/dottum
4
+/usr/share/dottum/complete/install.sh
4 5
 /usr/share/doc/dottum/LICENSE.md
5 6
 /usr/share/doc/dottum/README.md
6 7
 /usr/share/dottum/help

+ 2
- 1
packaging/template.spec 查看文件

@@ -30,13 +30,14 @@ make %{?_smp_mflags} PREFIX=/usr
30 30
 %make_install PREFIX=/usr
31 31
 
32 32
 %files
33
-%config %{_sysconfdir}/bash_completion.d/%{name}.bash
34 33
 %dir %{_datadir}/%{name}
35 34
 %dir %{_libexecdir}/%{name}
36 35
 %doc %{_docdir}/%{name}/LICENSE.md
37 36
 %doc %{_docdir}/%{name}/README.md
38 37
 %{_bindir}/%{name}
38
+%{_datadir}/%{name}/complete/install.sh
39 39
 %{_datadir}/%{name}/help
40
+%{_datadir}/bash-completion/completions/%{name}
40 41
 %{_libexecdir}/%{name}/dottum-install
41 42
 %{sfincb}/dottum.sh
42 43
 

+ 4
- 0
src/app.skel 查看文件

@@ -9,6 +9,7 @@ saturnin__main \
9 9
     --saturnin-app-codename "__MKIT_PROJ_CODENAME__" \
10 10
     --saturnin-app-git-hash "__MKIT_PROJ_GIT_LASTHASH__" \
11 11
     --saturnin-app-tagline "__MKIT_PROJ_TAGLINE__" \
12
+    --saturnin-app-url "__MKIT_PROJ_VCS_BROWSER__" \
12 13
     --saturnin-app-version "__MKIT_PROJ_VERSION__" \
13 14
     --saturnin-builtins "__SATURNIN_BUILTINS__" \
14 15
     --saturnin-cache-home "__SATURNIN_CACHE_HOME__" \
@@ -27,4 +28,7 @@ saturnin__main \
27 28
     --saturnin-libexec "__SATURNIN_LIBEXEC__" \
28 29
     --saturnin-libexec-prefix "__MKIT_PROJ_PKGNAME__-" \
29 30
     --saturnin-meta-help "+__SATURNIN_SHARE__/help" \
31
+    --saturnin-sccompgen-path "__SATURNIN_SCCOMPGEN_PATH__" \
32
+    --saturnin-msgmode "__SATURNIN_MSGMODE__" \
33
+    --saturnin-verbose "__SATURNIN_VERBOSE__" \
30 34
     "$@"

+ 86
- 29
src/complete.bash.skel 查看文件

@@ -1,38 +1,95 @@
1 1
 #!/bin/bash
2 2
 
3 3
 __SATURNIN_COMPLETE_CMDNAME=__MKIT_PROJ_PKGNAME__
4
+__SATURNIN_COMPLETE_M_OPTS="-D -V -d -h -v --full-debug --help --verbose --debug --version --version-semver"
4 5
 
5 6
 #shellcheck disable=SC2016
6
-__SATURNIN_COMPLETE_CODETMPL='
7
-__%s() {
8
-    local cur opts sopts
7
+__SATURNIN_COMPLETE_CODE='#!/bin/bash
8
+
9
+__'"$__SATURNIN_COMPLETE_CMDNAME"'() {
10
+    local Meta=$1       # current metacommand
11
+    local Partial=$2    # current unfinished word
12
+    local Previous=$3   # word preceding the unfinished one
13
+    local ScmdWords     # words from subcommand on, if already present
14
+    local Scmds=()      # all subcommands
15
+    local parser=__${Meta}__scparse    # parse util function
16
+    local asker=__${Meta}__scask    # util function to ask Saturnin
17
+    local comptext      # compgen result text
18
+    mapfile -t Scmds <<<"$("$Meta" --saturnin-get-subcommands)"
9 19
     COMPREPLY=()
10
-    cur="${COMP_WORDS[COMP_CWORD]}"
11
-    sopts="-D -V -d -h -v"
12
-    opts="--full-debug --help --verbose --debug --version --version-semver"
13
-    case "$cur" in
14
-        -*)
15
-            COMPREPLY=(
16
-                $(compgen -W "$sopts $opts" -- "${cur}")
17
-            )
18
-            ;;
19
-        --*)
20
-            COMPREPLY=(
21
-                $(compgen -W "$opts" -- "${cur}")
22
-            )
23
-            ;;
24
-        *)
25
-            COMPREPLY=(
26
-                $(compgen -W "$(%s --saturnin-get-subcommands)" "${cur}")
27
-            )
20
+    if $parser HAS; then
21
+        COMP_WORDBREAKS=" "
22
+        mapfile -t ScmdWords <<<"$($parser WORDS)"
23
+        comptext=$(compgen -W "$($asker)" -- "$Partial")
24
+    else
25
+        case $Partial in
26
+            -*)
27
+                comptext=$(
28
+                    compgen -W "'"$__SATURNIN_COMPLETE_M_OPTS"'" -- "$Partial"
29
+                )
30
+                ;;
31
+            *)
32
+                comptext=$(compgen -W "${Scmds[*]}" "$Partial")
33
+        esac
34
+    fi
35
+    case $comptext in
36
+        "") COMPREPLY=() ;;
37
+        *)  mapfile -t COMPREPLY <<<"$comptext" ;;
38
+    esac
39
+    {
40
+        declare -p Meta
41
+        declare -p Partial
42
+        declare -p Previous
43
+        declare -p ScmdWords
44
+        declare -p comptext
45
+        declare -p COMPREPLY
46
+    } | "__${Meta}__debug"
47
+}
48
+
49
+__'"$__SATURNIN_COMPLETE_CMDNAME"'__debug() {
50
+    #
51
+    # Send stdin to debug file, or /dev/null if debug is off
52
+    #
53
+    local dfile=/dev/null
54
+    if test "$__SATURNIN_COMPLETE_DEBUG" == true; then
55
+        dfile=/tmp/__saturnin_complete-'"$__SATURNIN_COMPLETE_CMDNAME"'.debug
56
+    fi
57
+    cat >"$dfile"
58
+}
59
+
60
+__'"$__SATURNIN_COMPLETE_CMDNAME"'__scask() {
61
+    #
62
+    # Ask and pass args from function plus all the filtered words
63
+    #
64
+    "$Meta" --saturnin-sccompgen "$Meta" "$Partial" "$Previous" "${ScmdWords[@]}"
65
+}
66
+
67
+__'"$__SATURNIN_COMPLETE_CMDNAME"'__scparse() {
68
+    local what=$1
69
+    set -- "${COMP_WORDS[@]}"
70
+    test "$1" == "$Meta" || echo "__${Meta}__scparse(): completion error" >&2
71
+    shift
72
+    local scswgaps=" ${Scmds[*]} "
73
+    while true; do
74
+        test -n "$1" || return 1
75
+        test "${1#-}" == "$1" || { shift; continue; }
76
+        test "${scswgaps/ $1 /}" == "$scswgaps" && { shift; continue; }
77
+        break
78
+    done
79
+    case $what in
80
+        HAS)    : ;;
81
+        WORDS)  echo "$1"
82
+                shift
83
+                while test $# -gt 0; do
84
+                    echo "$1"
85
+                    shift
86
+                done
87
+                ;;
28 88
     esac
29
-}'
30
-
31
-eval "$(
32
-    #shellcheck disable=SC2059
33
-    printf "$__SATURNIN_COMPLETE_CODETMPL" \
34
-        $__SATURNIN_COMPLETE_CMDNAME \
35
-        $__SATURNIN_COMPLETE_CMDNAME
36
-)"
89
+    return 0
90
+}
91
+'
92
+
93
+eval "$__SATURNIN_COMPLETE_CODE"
37 94
 
38 95
 complete -F "__$__SATURNIN_COMPLETE_CMDNAME" "$__SATURNIN_COMPLETE_CMDNAME"

+ 8
- 0
src/complete/install.sh 查看文件

@@ -0,0 +1,8 @@
1
+#!/bin/bash
2
+
3
+_saturnin__sccompgen_handle() {
4
+    case $_SATURNIN_SCCOMPGEN__POS:$_SATURNIN_SCCOMPGEN__PREVIOUS in
5
+        0:install) : ;;
6
+        *:-)      : ;;
7
+    esac
8
+}