Skip to content

Commit

Permalink
feat: Stop-within-session without name
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Yanke <ben@benyanke.com>
  • Loading branch information
ivaaaan and benyanke committed Jun 24, 2022
1 parent f6060cc commit ec05ffe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
19 changes: 17 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ windows:

expected := Config{
Session: "test",
Env: make(map[string]string),
Windows: []Window{
{
Layout: "tiled",
Expand Down
7 changes: 7 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"errors"
"os"
"strings"

"github.com/spf13/pflag"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ec05ffe

Please sign in to comment.