oh-my-posh/src/cli/get.go

62 lines
1.2 KiB
Go
Raw Normal View History

package cli
2022-03-12 13:04:08 -08:00
import (
"fmt"
2022-05-22 10:26:46 -07:00
"oh-my-posh/color"
2022-03-12 13:04:08 -08:00
"oh-my-posh/environment"
"time"
2022-05-22 10:26:46 -07:00
color2 "github.com/gookit/color"
2022-03-12 13:04:08 -08:00
"github.com/spf13/cobra"
)
// getCmd represents the get command
var getCmd = &cobra.Command{
2022-05-22 10:26:46 -07:00
Use: "get [shell|millis|accent]",
2022-03-19 11:32:40 -07:00
Short: "Get a value from oh-my-posh",
Long: `Get a value from oh-my-posh.
2022-03-12 13:04:08 -08:00
This command is used to get the value of the following variables:
- shell
2022-05-22 10:26:46 -07:00
- millis
- accent`,
2022-03-12 13:04:08 -08:00
ValidArgs: []string{
"millis",
"shell",
2022-05-22 10:26:46 -07:00
"accent",
2022-03-12 13:04:08 -08:00
},
Args: NoArgsOrOneValidArg,
2022-03-12 13:04:08 -08:00
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
_ = cmd.Help()
return
}
env := &environment.ShellEnvironment{
Version: cliVersion,
}
env.Init()
2022-03-12 13:04:08 -08:00
defer env.Close()
switch args[0] {
case "millis":
fmt.Print(time.Now().UnixNano() / 1000000)
case "shell":
fmt.Println(env.Shell())
2022-05-22 10:26:46 -07:00
case "accent":
rgb, err := color.GetAccentColor(env)
2022-05-22 10:26:46 -07:00
if err != nil {
fmt.Println("error getting accent color:", err.Error())
return
}
accent := color2.RGB(rgb.R, rgb.G, rgb.B)
fmt.Println("#" + accent.Hex())
2022-03-19 11:48:37 -07:00
default:
_ = cmd.Help()
2022-03-12 13:04:08 -08:00
}
},
}
func init() { // nolint:gochecknoinits
2022-03-19 11:32:40 -07:00
rootCmd.AddCommand(getCmd)
2022-03-12 13:04:08 -08:00
}