feat: Stop-within-session without name

Co-authored-by: Ben Yanke <ben@benyanke.com>
master
Ivan 2 years ago committed by GitHub
parent f6060cc6b4
commit ec05ffef1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -36,6 +36,11 @@ type Config struct {
RebalanceWindowsThreshold int `yaml:"rebalance_panes_after"`
}
func addDefaultEnvs(c *Config, path string) {
c.Env["SMUG_SESSION"] = c.Session
c.Env["SMUG_SESSION_NAME"] = c.Session
}
func EditConfig(path string) error {
editor := os.Getenv("EDITOR")
if editor == "" {
@ -58,7 +63,15 @@ func GetConfig(path string, settings map[string]string) (Config, error) {
config := string(f)
return ParseConfig(config, settings)
c, err := ParseConfig(config, settings)
if err != nil {
return Config{}, err
}
addDefaultEnvs(&c, path)
return c, err
}
func ParseConfig(data string, settings map[string]string) (Config, error) {
@ -74,7 +87,9 @@ func ParseConfig(data string, settings map[string]string) (Config, error) {
return v
})
c := Config{}
c := Config{
Env: make(map[string]string),
}
err := yaml.Unmarshal([]byte(data), &c)
if err != nil {

@ -28,6 +28,7 @@ windows:
expected := Config{
Session: "test",
Env: make(map[string]string),
Windows: []Window{
{
Layout: "tiled",

@ -2,6 +2,7 @@ package main
import (
"errors"
"os"
"strings"
"github.com/spf13/pflag"
@ -135,6 +136,12 @@ func ParseOptions(argv []string) (*Options, error) {
return nil, err
}
// If config file flag is not set, and env is, use the env
val, ok := os.LookupEnv("SMUG_SESSION_CONFIG_PATH")
if *config == "" && ok {
*config = val
}
var project string
if *config == "" {
if errors.Is(cmdErr, ErrCommandNotFound) {

Loading…
Cancel
Save