Skip to content

Commit

Permalink
✨FishCompletionsに対応いたしましたわ❗❗❗ #74 (#77)
Browse files Browse the repository at this point in the history
* add fish

* fix

* readme

* fix

* fix

* fix

* comment

* fix

* fix

* fix 1.x
  • Loading branch information
jiro4989 authored Aug 9, 2022
1 parent a171791 commit ae72600
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
matrix:
go:
- '1.18'
- '1.x'
# - '1.x'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
Expand Down
7 changes: 7 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ $ ojosama -completions bash | sudo tee /usr/share/bash-completion/completions/oj
$ ojosama -completions zsh | sudo tee /usr/share/zsh/functions/Completion/_ojosama
----

==== Fish

[source,bash]
----
$ ojosama -completions fish | tee $HOME/.config/fish/completions/ojosama.fish
----

== 注意事項

=== 変換結果について
Expand Down
27 changes: 23 additions & 4 deletions cmd/ojosama/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
)

var (
paramCharCodes = "utf8 sjis"
paramCompletions = "bash zsh fish"

completionsBash = strings.ReplaceAll(`# {{APPNAME}}(1) completion -*- shell-script -*-
_{{APPNAME}}_module() {
Expand All @@ -23,11 +26,11 @@ _{{APPNAME}}_module() {
COMPREPLY=($(compgen -f -- "${cur}"))
;;
-charcode)
local opts="utf8 sjis"
local opts="`+paramCharCodes+`"
COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
;;
-completions)
local opts="bash zsh"
local opts="`+paramCompletions+`"
COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
;;
esac
Expand All @@ -50,10 +53,10 @@ _{{APPNAME}}() {
case "$state" in
charcode)
_values 'charcode' utf8 sjis
_values 'charcode' `+paramCharCodes+`
;;
completions)
_values 'completions' bash zsh
_values 'completions' `+paramCompletions+`
;;
etc)
# nothing to do
Expand All @@ -65,9 +68,25 @@ compdef _{{APPNAME}} {{APPNAME}}
# vim: ft=zsh`, "{{APPNAME}}", appName)

// -x 引数を受け取るけれどファイルを指定できない
// -r 引数としてファイルを指定する
// -a 入力可能な文字列を指定する
// -o 古いロングオプション(-helpとか)を指定
completionsFish = strings.ReplaceAll(`complete -c {{APPNAME}} -r
complete -c {{APPNAME}} -o h -d '`+helpMsgHelp+`'
complete -c {{APPNAME}} -o help -d '`+helpMsgHelp+`'
complete -c {{APPNAME}} -o t -x -d '`+helpMsgText+`'
complete -c {{APPNAME}} -o o -r -d '`+helpMsgOutFile+`'
complete -c {{APPNAME}} -o charcode -x -a '`+paramCharCodes+`' -d '`+helpMsgCharCode+`'
complete -c {{APPNAME}} -o v -d '`+helpMsgVersion+`'
complete -c {{APPNAME}} -o completions -x -a '`+paramCompletions+`' -d '`+helpMsgCompletions+`'`,
"{{APPNAME}}", appName)

completionsMap = map[string]string{
"bash": completionsBash,
"zsh": completionsZsh,
"fish": completionsFish,
}
)

Expand Down

0 comments on commit ae72600

Please sign in to comment.