master
Ivan Klymenchenko 3 years ago
parent 73c8669d80
commit 6695015ad0

@ -4,7 +4,7 @@ Inspired by [tmuxinator](https://github.com/tmuxinator/tmuxinator) and [tmuxp](h
## Usage
`tmux <command> <project>[:window name] [-w window name]`
`tmux <command> <project>[:window name] [-w window name]`.
## Examples
@ -14,7 +14,7 @@ To start/stop a project and all windows, run:
`$ smug stop project`
When you already have a started session, and you want to start only some windows from the configuration file, you can do something like this:
When you already have a running session, and you want to create only some windows from the configuration file, you can do something like this:
`$ smug start project:window1`
@ -26,7 +26,7 @@ When you already have a started session, and you want to start only some windows
## Configuration
Configuration files stored in the `~/.config/smug` directory in the `YAML` format, e.g `~/config/smug/your_project.yml`.
Configuration files are stored in the `~/.config/smug` directory in the `YAML` format, e.g `~/.config/smug/your_project.yml`.
Example:

@ -17,12 +17,16 @@ func (c DefaultCommander) Exec(cmd *exec.Cmd) (string, error) {
output, err := cmd.CombinedOutput()
if err != nil {
return "", err
return "", &ShellError{strings.Join(cmd.Args, " "), err}
}
return strings.TrimSuffix(string(output), "\n"), nil
}
func (c DefaultCommander) ExecSilently(cmd *exec.Cmd) error {
return cmd.Run()
err := cmd.Run()
if err != nil {
return &ShellError{strings.Join(cmd.Args, " "), err}
}
return nil
}

@ -37,14 +37,13 @@ type Smug struct {
func (smug Smug) execShellCommands(commands []string, path string) error {
for _, c := range commands {
args := strings.Split(c, " ")
cmd := exec.Command(args[0], args[1:]...)
cmd := exec.Command("/bin/sh", "-c", c)
cmd.Dir = path
_, err := smug.commander.Exec(cmd)
if err != nil {
return &ShellError{c, err}
return err
}
}
return nil

@ -20,8 +20,8 @@ var startSessionTestTable = []struct {
},
[]string{
"tmux has-session -t ses",
"command1",
"command2",
"/bin/sh -c command1",
"/bin/sh -c command2",
"tmux new -Pd -s ses",
"tmux kill-window -t ses:0",
"tmux move-window -r",

@ -3,7 +3,6 @@ package main
import (
"os"
"os/exec"
"strings"
)
const (
@ -17,13 +16,7 @@ type Tmux struct {
func (tmux Tmux) NewSession(name string) (string, error) {
cmd := exec.Command("tmux", "new", "-Pd", "-s", name)
session, err := tmux.commander.Exec(cmd)
if err != nil {
return "", &ShellError{strings.Join(cmd.Args, " "), err}
}
return session, nil
return tmux.commander.Exec(cmd)
}
func (tmux Tmux) SessionExists(name string) bool {
@ -47,7 +40,10 @@ func (tmux Tmux) NewWindow(target string, name string, root string, commands []s
}
for _, c := range commands {
tmux.SendKeys(window, c)
err = tmux.SendKeys(window, c)
if err != nil {
return "", err
}
}
return window, nil
@ -93,13 +89,16 @@ func (tmux Tmux) SplitWindow(target string, splitType string, root string, comma
}
for _, c := range commands {
tmux.SendKeys(pane, c)
err = tmux.SendKeys(pane, c)
if err != nil {
return "", err
}
}
return pane, nil
}
func (tmux Tmux) StopSession(target string) (string, error) {
cmd := exec.Command("tmux", "stop-session", "-t", target)
cmd := exec.Command("tmux", "kill-session", "-t", target)
return tmux.commander.Exec(cmd)
}

Loading…
Cancel
Save