commit d698695187c2708cdbc1a50ad852d12c86805a9a
parent 91a2ed3cbcb7507fe733c18cd2ad5d5a589bf351
Author: Sean Enck <sean@ttypty.com>
Date: Sat, 20 Apr 2024 08:31:47 -0400
fish can use common pathway for profile generation
Diffstat:
3 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/internal/app/completions.go b/internal/app/completions.go
@@ -34,6 +34,7 @@ type (
CompletionEnv string
IsYes string
DefaultProfile Profile
+ IsFish bool
}
// Profile is a completion profile
@@ -135,6 +136,7 @@ func GenerateCompletions(completionType, exe string) ([]string, error) {
DoTOTPList: fmt.Sprintf("%s %s %s", exe, TOTPCommand, TOTPListCommand),
DefaultCompletion: fmt.Sprintf("$%s", config.EnvDefaultCompletionKey),
IsYes: config.YesValue,
+ IsFish: completionType == CompletionsFishCommand,
}
using, err := readDoc(fmt.Sprintf("%s.sh", completionType))
diff --git a/internal/app/doc/fish.sh b/internal/app/doc/fish.sh
@@ -26,17 +26,7 @@ end
{{- end}}
function {{ $.Executable }}-completions
- if [ -z "{{ $.DefaultCompletion }}" ] || [ "{{ $.DefaultCompletion }}" != "{{ $.IsYes }}" ]
-{{- range $idx, $prof := $.Profiles }}
-{{- if not $prof.IsDefault }}
- if {{ $prof.Conditional }}
- {{ $prof.Name }}
- return
- end
-{{- end}}
-{{- end}}
- end
- {{ $.DefaultProfile.Name }}
+ {{ $.Shell }}
end
{{ $.Executable }}-completions
diff --git a/internal/app/doc/shell.sh b/internal/app/doc/shell.sh
@@ -1,13 +1,17 @@
+{{- if not $.IsFish }}
_{{ $.Executable }}() {
- if [ -z "{{ $.DefaultCompletion }}" ] || [ "{{ $.DefaultCompletion }}" != "{{ $.IsYes }}" ]; then
+{{- end }}
+ if [ -z "{{ $.DefaultCompletion }}" ] || [ "{{ $.DefaultCompletion }}" != "{{ $.IsYes }}" ]{{ if not $.IsFish }}; then{{ end }}
{{- range $idx, $prof := $.Profiles }}
{{- if not $prof.IsDefault }}
- if {{ $prof.Conditional }}; then
- {{ $prof.Name }}
- return
- fi
+ if {{ $prof.Conditional }}{{ if not $.IsFish }}; then {{ end }}
+ {{ $prof.Name }}
+ return
+ {{ if $.IsFish }}end{{ else }}fi{{ end }}
{{- end }}
{{- end }}
- fi
+ {{ if $.IsFish }}end{{ else }}fi{{ end }}
{{ $.DefaultProfile.Name }}
+{{- if not $.IsFish }}
}
+{{- end }}