Skip to content

Commit

Permalink
Merge pull request #129 from rsteube/add-chsh
Browse files Browse the repository at this point in the history
added chsh
  • Loading branch information
rsteube authored Sep 10, 2020
2 parents 979023b + e5be076 commit 45e1160
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions carapace/cmd/completers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
chmod "github.com/rsteube/carapace-bin/completers/chmod_completer/cmd"
chown "github.com/rsteube/carapace-bin/completers/chown_completer/cmd"
chroot "github.com/rsteube/carapace-bin/completers/chroot_completer/cmd"
chsh "github.com/rsteube/carapace-bin/completers/chsh_completer/cmd"
cksum "github.com/rsteube/carapace-bin/completers/cksum_completer/cmd"
comm "github.com/rsteube/carapace-bin/completers/comm_completer/cmd"
cp "github.com/rsteube/carapace-bin/completers/cp_completer/cmd"
Expand Down Expand Up @@ -102,6 +103,7 @@ var completers = []string{
"chmod",
"chown",
"chroot",
"chsh",
"cksum",
"comm",
"cp",
Expand Down Expand Up @@ -204,6 +206,8 @@ func executeCompleter(completer string) {
chown.Execute()
case "chroot":
chroot.Execute()
case "chsh":
chsh.Execute()
case "cksum":
cksum.Execute()
case "comm":
Expand Down
39 changes: 39 additions & 0 deletions completers/chsh_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cmd

import (
"os/exec"
"strings"

"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "chsh",
Short: "Change your login shell",
Run: func(cmd *cobra.Command, args []string) {},
}

func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()

rootCmd.Flags().BoolP("help", "u", false, "display this help")
rootCmd.Flags().BoolP("list-shells", "l", false, "print list of shells and exit")
rootCmd.Flags().StringP("shell", "s", "", "specify login shell")
rootCmd.Flags().BoolP("version", "v", false, "display version")

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"shell": ActionShells(),
})
}

func ActionShells() carapace.Action {
if output, err := exec.Command("chsh", "--list-shells").Output(); err != nil {
return carapace.ActionMessage(err.Error())
} else {
return carapace.ActionValues(strings.Split(string(output), "\n")...)
}
}
7 changes: 7 additions & 0 deletions completers/chsh_completer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/rsteube/carapace-bin/completers/chsh_completer/cmd"

func main() {
cmd.Execute()
}

0 comments on commit 45e1160

Please sign in to comment.