mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 21:27:31 +00:00
cmd/tailscale: add shell tab-completion
The approach is lifted from cobra: `tailscale completion bash` emits a bash script for configuring the shell's autocomplete: . <( tailscale completion bash ) so that typing: tailscale st<TAB> invokes: tailscale completion __complete -- st RELNOTE=tailscale CLI now supports shell tab-completion Fixes #3793 Signed-off-by: Paul Scott <paul@tailscale.com>
This commit is contained in:
42
tempfork/spf13/cobra/gen.go
Normal file
42
tempfork/spf13/cobra/gen.go
Normal file
@@ -0,0 +1,42 @@
|
||||
//go:build gen
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
for _, name := range []string{"comp.bash", "comp.zsh", "comp.fish", "comp.ps1"} {
|
||||
err := compress(name)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "compressing "+name+":", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func compress(name string) error {
|
||||
src, err := os.Open(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
dst, err := os.Create(name + ".gz")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer dst.Close()
|
||||
|
||||
z := gzip.NewWriter(dst)
|
||||
_, err = io.Copy(z, src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return z.Close()
|
||||
}
|
Reference in New Issue
Block a user