mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2026-08-24 02:34:19 -05:00
fix(cli): get config path from session
This commit is contained in:
committed by
Jan De Dobbeleer
parent
2c8e0bb35b
commit
9c897ab042
@@ -29,7 +29,6 @@ You can export, migrate or edit the config (via the editor specified in the envi
|
||||
|
||||
switch args[0] {
|
||||
case "edit":
|
||||
// TODO: fetch the config from the session cache
|
||||
cache.Init(os.Getenv("POSH_SHELL"), false)
|
||||
if configPath, OK := cache.Get[string](cache.Session, config.SourceKey); OK {
|
||||
exitcode = editFileWithEditor(configPath)
|
||||
|
||||
@@ -3,9 +3,11 @@ package cli
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/cache"
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/config"
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/runtime/path"
|
||||
|
||||
@@ -40,6 +42,15 @@ Exports the current config to "~/new_config.omp.json" (in JSON format).`,
|
||||
return
|
||||
}
|
||||
|
||||
cache.Init(os.Getenv("POSH_SHELL"), false)
|
||||
|
||||
err := setConfigFlag()
|
||||
if err != nil {
|
||||
exitcode = 666
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cfg := config.Load(configFlag, false)
|
||||
|
||||
validateExportFormat := func() error {
|
||||
|
||||
@@ -2,6 +2,7 @@ package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/cache"
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/cli/image"
|
||||
@@ -49,6 +50,15 @@ Exports the config to an image file ~/mytheme.png.
|
||||
Exports the config to an image file using customized output settings.`,
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(_ *cobra.Command, _ []string) {
|
||||
cache.Init(os.Getenv("POSH_SHELL"), false)
|
||||
|
||||
err := setConfigFlag()
|
||||
if err != nil {
|
||||
exitcode = 666
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cfg := config.Load(configFlag, false)
|
||||
|
||||
flags := &runtime.Flags{
|
||||
@@ -60,8 +70,6 @@ Exports the config to an image file using customized output settings.`,
|
||||
env := &runtime.Terminal{}
|
||||
env.Init(flags)
|
||||
|
||||
cache.Init(shellName, false)
|
||||
|
||||
template.Init(env, cfg.Var, cfg.Maps)
|
||||
|
||||
defer func() {
|
||||
@@ -135,3 +143,17 @@ func init() {
|
||||
|
||||
exportCmd.AddCommand(imageCmd)
|
||||
}
|
||||
|
||||
func setConfigFlag() error {
|
||||
if configFlag != "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
configPath, OK := cache.Get[string](cache.Session, config.SourceKey)
|
||||
if !OK {
|
||||
return fmt.Errorf("no config found in session cache, please provide a config using the --config flag")
|
||||
}
|
||||
|
||||
configFlag = configPath
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/cache"
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/config"
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
|
||||
|
||||
@@ -39,6 +41,15 @@ Migrates 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.`,
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(_ *cobra.Command, _ []string) {
|
||||
cache.Init(os.Getenv("POSH_SHELL"), false)
|
||||
|
||||
err := setConfigFlag()
|
||||
if err != nil {
|
||||
exitcode = 666
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cfg := config.Load(configFlag, true)
|
||||
|
||||
flags := &runtime.Flags{
|
||||
|
||||
@@ -2,7 +2,9 @@ package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/cache"
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/config"
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
|
||||
|
||||
@@ -34,6 +36,15 @@ Migrates the ~/myconfig.omp.json config file's glyphs and writes the result to y
|
||||
A backup of the current config can be found at ~/myconfig.omp.json.bak.`,
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(_ *cobra.Command, _ []string) {
|
||||
cache.Init(os.Getenv("POSH_SHELL"), false)
|
||||
|
||||
err := setConfigFlag()
|
||||
if err != nil {
|
||||
exitcode = 666
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cfg := config.Load(configFlag, false)
|
||||
|
||||
flags := &runtime.Flags{
|
||||
|
||||
Reference in New Issue
Block a user