mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-28 11:31:04 -08:00
feat: initialize shell with default remote config
This commit is contained in:
parent
d11c39b620
commit
75e90329f4
|
@ -35,6 +35,7 @@ Exports the ~/myconfig.omp.json config file to toml and writes the result to yo
|
|||
A backup of the current config can be found at ~/myconfig.omp.json.bak.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
env := &environment.ShellEnvironment{
|
||||
Version: cliVersion,
|
||||
CmdFlags: &environment.Flags{
|
||||
Config: config,
|
||||
},
|
||||
|
|
|
@ -41,6 +41,7 @@ You can tweak the output by using additional flags:
|
|||
- background-color: the background color of the image`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
env := &environment.ShellEnvironment{
|
||||
Version: cliVersion,
|
||||
CmdFlags: &environment.Flags{
|
||||
Config: config,
|
||||
Shell: "shell",
|
||||
|
|
|
@ -29,7 +29,9 @@ This command is used to get the value of the following variables:
|
|||
},
|
||||
Args: cobra.OnlyValidArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
env := &environment.ShellEnvironment{}
|
||||
env := &environment.ShellEnvironment{
|
||||
Version: cliVersion,
|
||||
}
|
||||
env.Init(false)
|
||||
defer env.Close()
|
||||
switch args[0] {
|
||||
|
|
|
@ -40,6 +40,7 @@ Migrates the ~/myconfig.omp.json config file to toml and writes the result to y
|
|||
A backup of the current config can be found at ~/myconfig.omp.json.bak.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
env := &environment.ShellEnvironment{
|
||||
Version: cliVersion,
|
||||
CmdFlags: &environment.Flags{
|
||||
Config: config,
|
||||
Migrate: true,
|
||||
|
|
|
@ -43,6 +43,7 @@ func init() { // nolint:gochecknoinits
|
|||
|
||||
func runInit(shell string) {
|
||||
env := &environment.ShellEnvironment{
|
||||
Version: cliVersion,
|
||||
CmdFlags: &environment.Flags{
|
||||
Shell: shell,
|
||||
Config: config,
|
||||
|
|
|
@ -45,6 +45,7 @@ var printCmd = &cobra.Command{
|
|||
Args: cobra.OnlyValidArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
env := &environment.ShellEnvironment{
|
||||
Version: cliVersion,
|
||||
CmdFlags: &environment.Flags{
|
||||
Config: config,
|
||||
PWD: pwd,
|
||||
|
|
|
@ -207,6 +207,7 @@ const (
|
|||
|
||||
type ShellEnvironment struct {
|
||||
CmdFlags *Flags
|
||||
Version string
|
||||
cwd string
|
||||
cmdCache *commandCache
|
||||
fileCache *fileCache
|
||||
|
@ -219,12 +220,9 @@ func (env *ShellEnvironment) Init(debug bool) {
|
|||
if env.CmdFlags == nil {
|
||||
env.CmdFlags = &Flags{}
|
||||
}
|
||||
if len(env.CmdFlags.Config) == 0 {
|
||||
env.CmdFlags.Config = env.Getenv("POSH_THEME")
|
||||
}
|
||||
env.fileCache = &fileCache{}
|
||||
env.fileCache.Init(env.CachePath())
|
||||
env.ResolveConfigPath()
|
||||
env.resolveConfigPath()
|
||||
env.cmdCache = &commandCache{
|
||||
commands: newConcurrentMap(),
|
||||
}
|
||||
|
@ -234,27 +232,12 @@ func (env *ShellEnvironment) Init(debug bool) {
|
|||
}
|
||||
}
|
||||
|
||||
func (env *ShellEnvironment) getConfigPath(location string) {
|
||||
cfg, err := env.HTTPRequest(location, 5000)
|
||||
if err != nil {
|
||||
return
|
||||
func (env *ShellEnvironment) resolveConfigPath() {
|
||||
if len(env.CmdFlags.Config) == 0 {
|
||||
env.CmdFlags.Config = env.Getenv("POSH_THEME")
|
||||
}
|
||||
configPath := filepath.Join(env.CachePath(), "config.omp.json")
|
||||
out, err := os.Create(configPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer out.Close()
|
||||
_, err = io.Copy(out, bytes.NewReader(cfg))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
env.CmdFlags.Config = configPath
|
||||
}
|
||||
|
||||
func (env *ShellEnvironment) ResolveConfigPath() {
|
||||
if env.CmdFlags == nil || len(env.CmdFlags.Config) == 0 {
|
||||
return
|
||||
if len(env.CmdFlags.Config) == 0 {
|
||||
env.CmdFlags.Config = fmt.Sprintf("https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/v%s/themes/jandedobbeleer.omp.json", env.Version)
|
||||
}
|
||||
location, err := url.ParseRequestURI(env.CmdFlags.Config)
|
||||
if err == nil {
|
||||
|
@ -279,6 +262,24 @@ func (env *ShellEnvironment) ResolveConfigPath() {
|
|||
env.CmdFlags.Config = filepath.Clean(configFile)
|
||||
}
|
||||
|
||||
func (env *ShellEnvironment) getConfigPath(location string) {
|
||||
cfg, err := env.HTTPRequest(location, 5000)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
configPath := filepath.Join(env.CachePath(), "config.omp.json")
|
||||
out, err := os.Create(configPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer out.Close()
|
||||
_, err = io.Copy(out, bytes.NewReader(cfg))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
env.CmdFlags.Config = configPath
|
||||
}
|
||||
|
||||
func (env *ShellEnvironment) trace(start time.Time, function string, args ...string) {
|
||||
if !env.debug {
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue