mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-27 20:09:39 -08:00
8978038a3c
On Windows, when in the registry, os.Getwd() returns the previous path rather than the registry location. Settings PWD as an environment variable might seem hacky but it's the only way to resolve this. Resolves #40
66 lines
1.1 KiB
Go
Executable file
66 lines
1.1 KiB
Go
Executable file
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
)
|
|
|
|
type args struct {
|
|
ErrorCode *int
|
|
PrintConfig *bool
|
|
Config *string
|
|
Shell *string
|
|
PWD *string
|
|
}
|
|
|
|
func main() {
|
|
args := &args{
|
|
ErrorCode: flag.Int(
|
|
"error",
|
|
0,
|
|
"Error code of previously executed command"),
|
|
PrintConfig: flag.Bool(
|
|
"print-config",
|
|
false,
|
|
"Config prints the current settings in json format"),
|
|
Config: flag.String(
|
|
"config",
|
|
"",
|
|
"Add the path to a configuration you wish to load"),
|
|
Shell: flag.String(
|
|
"shell",
|
|
"",
|
|
"Override the shell you are working in"),
|
|
PWD: flag.String(
|
|
"pwd",
|
|
"",
|
|
"the path you are working in"),
|
|
}
|
|
flag.Parse()
|
|
env := &environment{
|
|
args: args,
|
|
}
|
|
settings := GetSettings(env)
|
|
if *args.PrintConfig {
|
|
theme, _ := json.MarshalIndent(settings, "", " ")
|
|
fmt.Println(string(theme))
|
|
return
|
|
}
|
|
colorWriter := &Renderer{
|
|
Buffer: new(bytes.Buffer),
|
|
}
|
|
shell := env.getShellName()
|
|
if *args.Shell != "" {
|
|
shell = *args.Shell
|
|
}
|
|
colorWriter.init(shell)
|
|
engine := &engine{
|
|
settings: settings,
|
|
env: env,
|
|
renderer: colorWriter,
|
|
}
|
|
engine.render()
|
|
}
|