diff --git a/config.go b/config.go index 841cd93..92894e1 100644 --- a/config.go +++ b/config.go @@ -55,22 +55,22 @@ func EditConfig(path string) error { return cmd.Run() } -func GetConfig(path string, settings map[string]string) (Config, error) { +func GetConfig(path string, settings map[string]string) (*Config, error) { f, err := ioutil.ReadFile(path) if err != nil { - return Config{}, err + return nil, err } config := string(f) c, err := ParseConfig(config, settings) if err != nil { - return Config{}, err + return nil, err } addDefaultEnvs(&c, path) - return c, err + return &c, err } diff --git a/main.go b/main.go index e004004..d5c9a4f 100644 --- a/main.go +++ b/main.go @@ -59,7 +59,7 @@ func newLogger(path string) *log.Logger { func main() { options, err := ParseOptions(os.Args[1:]) if err == ErrHelp { - fmt.Fprintf(os.Stdout, usage) + fmt.Fprint(os.Stdout, usage) os.Exit(0) } @@ -100,7 +100,7 @@ func main() { } config, err := GetConfig(configPath, options.Settings) if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprint(os.Stderr, err.Error()) os.Exit(1) } @@ -118,25 +118,25 @@ func main() { } config, err := GetConfig(configPath, options.Settings) if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprint(os.Stderr, err.Error()) os.Exit(1) } err = smug.Stop(config, options, context) if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprint(os.Stderr, err.Error()) os.Exit(1) } case CommandNew, CommandEdit: err := EditConfig(configPath) if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprint(os.Stderr, err.Error()) os.Exit(1) } case CommandList: configs, err := ListConfigs(userConfigDir) if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprint(os.Stderr, err.Error()) os.Exit(1) } @@ -144,13 +144,13 @@ func main() { case CommandPrint: config, err := smug.GetConfigFromSession(options, context) if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprint(os.Stderr, err.Error()) os.Exit(1) } d, err := yaml.Marshal(&config) if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprint(os.Stderr, err.Error()) os.Exit(1) } diff --git a/smug.go b/smug.go index 0f87743..90aa96b 100644 --- a/smug.go +++ b/smug.go @@ -77,7 +77,7 @@ func (smug Smug) switchOrAttach(target string, attach bool, insideTmuxSession bo return nil } -func (smug Smug) Stop(config Config, options *Options, context Context) error { +func (smug Smug) Stop(config *Config, options *Options, context Context) error { windows := options.Windows if len(windows) == 0 { sessionRoot := ExpandPath(config.Root) @@ -100,7 +100,7 @@ func (smug Smug) Stop(config Config, options *Options, context Context) error { return nil } -func (smug Smug) Start(config Config, options *Options, context Context) error { +func (smug Smug) Start(config *Config, options *Options, context Context) error { var sessionName string var err error @@ -210,11 +210,17 @@ func (smug Smug) Start(config Config, options *Options, context Context) error { } if !options.InsideCurrentSession { - smug.tmux.KillWindow(sessionName + defaultWindowName) - smug.tmux.RenumberWindows(sessionName) + err := smug.tmux.KillWindow(sessionName + defaultWindowName) + if err != nil { + return err + } + err = smug.tmux.RenumberWindows(sessionName) + if err != nil { + return err + } } - if len(windows) == 0 && len(config.Windows) > 0 && options.Detach == false { + if len(windows) == 0 && len(config.Windows) > 0 && !options.Detach { return smug.switchOrAttach(sessionName+config.Windows[0].Name, attach, context.InsideTmuxSession) } @@ -236,7 +242,7 @@ func (smug Smug) GetConfigFromSession(options *Options, context Context) (Config } for _, w := range tmuxWindows { - tmuxPanes, err := smug.tmux.ListPanes(options.Project + ":" + w.Id) + tmuxPanes, err := smug.tmux.ListPanes(options.Project + ":" + w.ID) if err != nil { return Config{}, err } diff --git a/smug_test.go b/smug_test.go index 4eab1cf..3684a70 100644 --- a/smug_test.go +++ b/smug_test.go @@ -9,7 +9,7 @@ import ( ) var testTable = map[string]struct { - config Config + config *Config options *Options context Context startCommands []string @@ -17,7 +17,7 @@ var testTable = map[string]struct { commanderOutputs []string }{ "test with 1 window": { - Config{ + &Config{ Session: "ses", Root: "~/root", BeforeStart: []string{"command1", "command2"}, @@ -48,7 +48,7 @@ var testTable = map[string]struct { []string{"ses", "win1"}, }, "test with 1 window and Detach: true": { - Config{ + &Config{ Session: "ses", Root: "root", BeforeStart: []string{"command1", "command2"}, @@ -78,7 +78,7 @@ var testTable = map[string]struct { []string{"xyz"}, }, "test with multiple windows and panes": { - Config{ + &Config{ Session: "ses", Root: "root", Windows: []Window{ @@ -125,7 +125,7 @@ var testTable = map[string]struct { []string{"ses", "ses", "win1", "1"}, }, "test start windows from option's Windows parameter": { - Config{ + &Config{ Session: "ses", Root: "root", Windows: []Window{ @@ -157,7 +157,7 @@ var testTable = map[string]struct { []string{"xyz"}, }, "test attach to the existing session": { - Config{ + &Config{ Session: "ses", Root: "root", Windows: []Window{ @@ -176,7 +176,7 @@ var testTable = map[string]struct { []string{""}, }, "test start a new session from another tmux session": { - Config{ + &Config{ Session: "ses", Root: "root", }, @@ -194,7 +194,7 @@ var testTable = map[string]struct { []string{"xyz"}, }, "test switch a client from another tmux session": { - Config{ + &Config{ Session: "ses", Root: "root", Windows: []Window{ @@ -213,7 +213,7 @@ var testTable = map[string]struct { []string{""}, }, "test create new windows in current session with same name": { - Config{ + &Config{ Session: "ses", Root: "root", Windows: []Window{ @@ -236,7 +236,7 @@ var testTable = map[string]struct { []string{"ses", ""}, }, "test create new windows in current session with different name": { - Config{ + &Config{ Session: "ses", Root: "root", Windows: []Window{ diff --git a/tmux.go b/tmux.go index e00750f..82b48e3 100644 --- a/tmux.go +++ b/tmux.go @@ -13,9 +13,6 @@ const ( const ( EvenHorizontal = "even-horizontal" - EvenVertical = "even-vertical" - MainHorizontal = "main-horizontal" - MainVertical = "main-vertical" Tiled = "tiled" ) @@ -24,7 +21,7 @@ type Tmux struct { } type TmuxWindow struct { - Id string + ID string Name string Layout string Root string @@ -146,7 +143,7 @@ func (tmux Tmux) ListWindows(target string) ([]TmuxWindow, error) { for _, w := range windowsList { windowInfo := strings.Split(w, ";") window := TmuxWindow{ - Id: windowInfo[0], + ID: windowInfo[0], Name: windowInfo[1], Layout: windowInfo[2], Root: windowInfo[3],