oh-my-posh/main.go

92 lines
1.6 KiB
Go
Raw Normal View History

2019-03-13 04:14:30 -07:00
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
)
2020-11-22 06:02:50 -08:00
// Version number of oh-my-posh
var Version = "development"
2020-11-19 16:53:09 -08:00
2019-03-13 04:14:30 -07:00
type args struct {
ErrorCode *int
PrintConfig *bool
2020-11-03 06:07:58 -08:00
PrintShell *bool
2019-03-13 04:14:30 -07:00
Config *string
Shell *string
PWD *string
2020-11-19 16:53:09 -08:00
Version *bool
Debug *bool
2019-03-13 04:14:30 -07:00
}
func main() {
args := &args{
ErrorCode: flag.Int(
"error",
0,
"Error code of previously executed command"),
PrintConfig: flag.Bool(
"print-config",
false,
2020-11-03 06:07:58 -08:00
"Print the current config in json format"),
PrintShell: flag.Bool(
"print-shell",
false,
"Print the current shell name"),
2019-03-13 04:14:30 -07:00
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"),
2020-11-19 16:53:09 -08:00
Version: flag.Bool(
"version",
false,
"Print the current version of the binary"),
Debug: flag.Bool(
"debug",
false,
"Print debug information"),
2019-03-13 04:14:30 -07:00
}
flag.Parse()
env := &environment{
args: args,
}
settings := GetSettings(env)
if *args.PrintConfig {
theme, _ := json.MarshalIndent(settings, "", " ")
fmt.Println(string(theme))
return
}
2020-11-03 06:07:58 -08:00
if *args.PrintShell {
fmt.Println(env.getShellName())
return
}
2020-11-19 16:53:09 -08:00
if *args.Version {
fmt.Println(Version)
2020-11-19 16:53:09 -08:00
return
}
colorWriter := &Renderer{
Buffer: new(bytes.Buffer),
}
shell := env.getShellName()
if *args.Shell != "" {
shell = *args.Shell
}
colorWriter.init(shell)
2019-03-13 04:14:30 -07:00
engine := &engine{
settings: settings,
env: env,
renderer: colorWriter,
2019-03-13 04:14:30 -07:00
}
engine.render()
2019-03-13 04:14:30 -07:00
}