feat: Allow stopping smug session without specifying a project

master
Ivan 2 years ago committed by GitHub
parent 73fed621b9
commit 6c4f6e067a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -68,13 +68,6 @@ func main() {
userConfigDir := filepath.Join(ExpandPath("~/"), ".config/smug")
var configPath string
if options.Config != "" {
configPath = options.Config
} else {
configPath = filepath.Join(userConfigDir, options.Project+".yml")
}
var logger *log.Logger
if options.Debug {
logFile, err := os.Create(filepath.Join(userConfigDir, "smug.log"))
@ -90,6 +83,20 @@ func main() {
smug := Smug{tmux, commander}
context := CreateContext()
var configPath string
if options.Config != "" {
configPath = options.Config
} else if options.Project != "" {
configPath = filepath.Join(userConfigDir, options.Project+".yml")
} else {
s, err := tmux.CurrentSession()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
configPath = filepath.Join(userConfigDir, s+".yml")
}
switch options.Command {
case CommandStart:
if len(options.Windows) == 0 {

@ -181,3 +181,14 @@ func (tmux Tmux) ListPanes(target string) ([]TmuxPane, error) {
return panes, nil
}
func (tmux Tmux) CurrentSession() (string, error) {
cmd := exec.Command("tmux", "display-message", "-p", "#S")
sessionName, err := tmux.commander.Exec(cmd)
if err != nil {
return sessionName, err
}
return sessionName, nil
}

Loading…
Cancel
Save