commit cfca4f9a9b4bce37e0c51ecb3f1ad1809353f5b5
parent 17e015a63825b4f7221a17868f623f3c43e9c2b5
Author: Sean Enck <sean@ttypty.com>
Date: Sun, 3 Sep 2023 08:03:06 -0400
use a template parameter and not echo to remove non-list ability
Diffstat:
3 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/internal/app/completions.go b/internal/app/completions.go
@@ -9,16 +9,13 @@ import (
"github.com/enckse/lockbox/internal/config"
)
-const (
- noList = "echo \"\""
-)
-
type (
// Completions handles the inputs to completions for templating
Completions struct {
Options []string
CanClip bool
CanTOTP bool
+ CanList bool
ReadOnly bool
InsertCommand string
TOTPSubCommands []string
@@ -41,6 +38,7 @@ type (
// GenerateCompletions handles creating shell completion outputs
func GenerateCompletions(isBash, defaults bool, exe string) ([]string, error) {
c := Completions{
+ CanList: true,
Executable: exe,
InsertCommand: InsertCommand,
RemoveCommand: RemoveCommand,
@@ -86,8 +84,7 @@ func GenerateCompletions(isBash, defaults bool, exe string) ([]string, error) {
return nil, err
}
if k != nil && k.Interactive() {
- c.DoList = noList
- c.DoTOTPList = noList
+ c.CanList = false
}
}
c.CanClip = isClip
diff --git a/internal/app/doc/bash b/internal/app/doc/bash
@@ -16,10 +16,12 @@ _{{ $.Executable }}() {
opts="{{ $.HelpAdvancedCommand }}"
;;
{{- if not $.ReadOnly }}
+{{- if $.CanList }}
"{{ $.InsertCommand }}" | "{{ $.MultiLineCommand }}" | "{{ $.MoveCommand }}" | "{{ $.RemoveCommand }}")
opts="$opts $({{ $.DoList }})"
;;
{{- end}}
+{{- end}}
{{- if $.CanTOTP }}
"{{ $.TOTPCommand }}")
opts="{{ $.TOTPListCommand }} "
@@ -28,10 +30,13 @@ _{{ $.Executable }}() {
{{- end}}
;;
{{- end}}
+{{- if $.CanList }}
"{{ $.ShowCommand }}" | "{{ $.JSONCommand }}"{{ if $.CanClip }} | "{{ $.ClipCommand }}" {{end}})
opts=$({{ $.DoList }})
;;
+{{- end}}
esac
+{{- if $.CanList }}
else
if [ "$COMP_CWORD" -eq 3 ]; then
case "${COMP_WORDS[1]}" in
@@ -53,6 +58,7 @@ _{{ $.Executable }}() {
{{- end}}
esac
fi
+{{- end}}
fi
if [ -n "$opts" ]; then
# shellcheck disable=SC2207
diff --git a/internal/app/doc/zsh b/internal/app/doc/zsh
@@ -21,6 +21,7 @@ _{{ $.Executable }}() {
fi
;;
{{- if not $.ReadOnly }}
+{{- if $.CanList }}
"{{ $.InsertCommand }}" | "{{ $.MultiLineCommand }}" | "{{ $.RemoveCommand }}")
if [ "$len" -eq 3 ]; then
compadd "$@" $({{ $.DoList }})
@@ -34,12 +35,14 @@ _{{ $.Executable }}() {
esac
;;
{{- end}}
+{{- end}}
{{- if $.CanTOTP }}
"{{ $.TOTPCommand }}")
case "$len" in
3)
compadd "$@" {{ $.TOTPListCommand }}{{ range $key, $value := .TOTPSubCommands }} {{ $value }}{{ end }}
;;
+{{- if $.CanList }}
4)
case $words[3] in
{{- range $key, $value := .TOTPSubCommands }}
@@ -48,14 +51,17 @@ _{{ $.Executable }}() {
;;
{{- end}}
esac
+{{- end}}
esac
;;
{{- end}}
+{{- if $.CanList }}
"{{ $.ShowCommand }}" | "{{ $.JSONCommand }}"{{ if $.CanClip }} | "{{ $.ClipCommand }}" {{end}})
if [ "$len" -eq 3 ]; then
compadd "$@" $({{ $.DoList }})
fi
;;
+{{- end}}
esac
esac
}