2022-03-12 13:04:08 -08:00
|
|
|
/*
|
|
|
|
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
|
|
|
|
|
|
|
*/
|
2022-03-12 22:43:32 -08:00
|
|
|
package cli
|
2022-03-12 13:04:08 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"oh-my-posh/environment"
|
2022-03-21 23:41:36 -07:00
|
|
|
"oh-my-posh/shell"
|
2022-03-12 13:04:08 -08:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
print bool
|
|
|
|
|
|
|
|
initCmd = &cobra.Command{
|
|
|
|
Use: "init [bash|zsh|fish|powershell|pwsh|cmd] --config ~/.mytheme.omp.json",
|
|
|
|
Short: "Initialize your shell and configuration",
|
|
|
|
Long: `Allows to initialize your shell and configuration.
|
|
|
|
See the documentation to initialize your shell: https://ohmyposh.dev/docs/prompt.`,
|
|
|
|
ValidArgs: []string{
|
|
|
|
"bash",
|
|
|
|
"zsh",
|
|
|
|
"fish",
|
|
|
|
"powershell",
|
|
|
|
"pwsh",
|
|
|
|
"cmd",
|
|
|
|
},
|
|
|
|
Args: cobra.OnlyValidArgs,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
runInit(args[0])
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() { // nolint:gochecknoinits
|
|
|
|
initCmd.Flags().BoolVarP(&print, "print", "p", false, "print the init script")
|
|
|
|
_ = initCmd.MarkPersistentFlagRequired("config")
|
|
|
|
promptCmd.AddCommand(initCmd)
|
|
|
|
}
|
|
|
|
|
2022-03-21 23:41:36 -07:00
|
|
|
func runInit(shellName string) {
|
2022-03-12 13:04:08 -08:00
|
|
|
env := &environment.ShellEnvironment{
|
2022-03-16 00:47:39 -07:00
|
|
|
Version: cliVersion,
|
2022-03-12 13:04:08 -08:00
|
|
|
CmdFlags: &environment.Flags{
|
2022-03-21 23:41:36 -07:00
|
|
|
Shell: shellName,
|
2022-03-12 13:04:08 -08:00
|
|
|
Config: config,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
env.Init(false)
|
|
|
|
defer env.Close()
|
|
|
|
if print {
|
2022-03-21 23:41:36 -07:00
|
|
|
init := shell.PrintInit(env)
|
2022-03-12 13:04:08 -08:00
|
|
|
fmt.Print(init)
|
|
|
|
return
|
|
|
|
}
|
2022-03-21 23:41:36 -07:00
|
|
|
init := shell.Init(env)
|
2022-03-12 13:04:08 -08:00
|
|
|
fmt.Print(init)
|
|
|
|
}
|