// Package fish provides fish completion
package fish import ( shlex ) // Snippet creates the fish completion script. func ( *cobra.Command) string { return SnippetSingle(.Name(), false) } // SnippetMulti creates a multi-completer fish completion script. func ( []string, string, string) string { := make([]string, 0, len()*2) for , := range { := shlex.Quote(, shlex.Fish) = append(, fmt.Sprintf(`complete -e %[2]v`, , ), fmt.Sprintf(`complete -c %[2]v -f -a '(_%[1]v_completer %[2]v)' -r`, , ), ) } return fmt.Sprintf(`%[4]vfunction _%[1]v_completer set --local data IFS='' set data (echo (commandline -cp)'' | sed "s/ \$/ ''/" | xargs %[2]v $argv[1] _carapace fish 2>/dev/null) if [ $status -eq 1 ] IFS='' set data (echo (commandline -cp)"'" | sed "s/ \$/ ''/" | xargs %[2]v $argv[1] _carapace fish 2>/dev/null) if [ $status -eq 1 ] IFS='' set data (echo (commandline -cp)'"' | sed "s/ \$/ ''/" | xargs %[2]v $argv[1] _carapace fish 2>/dev/null) end end echo $data end %v `, , shlex.Quote(uid.Executable(), shlex.Fish), strings.Join(, "\n"), ) } // SnippetSingle creates a single-command fish completion script. // When explicitCommand is true, the command name is included in the invocation // (for multi-completer subcommands). When false, the executable is invoked // without an explicit command (standalone mode). func ( string, bool) string { := fmt.Sprintf("%v _carapace fish", shlex.Quote(uid.Executable(), shlex.Fish)) if { = fmt.Sprintf("%v %v _carapace fish", shlex.Quote(uid.Executable(), shlex.Fish), shlex.Quote(, shlex.Fish)) } return fmt.Sprintf(`function _%[1]v_completion set --local data IFS='' set data (echo (commandline -cp)'' | sed "s/ \$/ ''/" | xargs %[2]v 2>/dev/null) if [ $status -eq 1 ] IFS='' set data (echo (commandline -cp)"'" | sed "s/ \$/ ''/" | xargs %[2]v 2>/dev/null) if [ $status -eq 1 ] IFS='' set data (echo (commandline -cp)'"' | sed "s/ \$/ ''/" | xargs %[2]v 2>/dev/null) end end echo $data end complete -e %[3]v complete -c %[4]v -f -a '(_%[1]v_completion)' -r `, , , shlex.Quote(, shlex.Fish), shlex.Quote(, shlex.Fish)) }