2022-03-12 22:43:32 -08:00
|
|
|
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-05-05 02:26:20 -07:00
|
|
|
|
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
|
|
|
},
|
2022-05-05 02:26:20 -07:00
|
|
|
Args: NoArgsOrOneValidArg,
|
2022-03-12 13:04:08 -08:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2022-03-20 22:41:04 -07:00
|
|
|
if len(args) == 0 {
|
|
|
|
_ = cmd.Help()
|
|
|
|
return
|
|
|
|
}
|
2022-03-16 00:47:39 -07:00
|
|
|
env := &environment.ShellEnvironment{
|
|
|
|
Version: cliVersion,
|
2022-09-22 23:39:27 -07:00
|
|
|
CmdFlags: &environment.Flags{
|
|
|
|
Shell: shellName,
|
|
|
|
},
|
2022-03-16 00:47:39 -07:00
|
|
|
}
|
2022-05-07 01:12:22 -07:00
|
|
|
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":
|
2022-05-28 15:28:51 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-08-04 23:33:02 -07:00
|
|
|
func init() { //nolint:gochecknoinits
|
2022-11-02 03:48:19 -07:00
|
|
|
RootCmd.AddCommand(getCmd)
|
2022-09-23 01:16:19 -07:00
|
|
|
getCmd.Flags().StringVar(&shellName, "shell", "", "the shell to print for")
|
2022-03-12 13:04:08 -08:00
|
|
|
}
|