@ -23,8 +23,8 @@ type Tmux struct {
commander Commander
commander Commander
}
}
func ( tmux Tmux ) NewSession ( name string ) ( string , error ) {
func ( tmux Tmux ) NewSession ( name string , root string , windowName string ) ( string , error ) {
cmd := exec . Command ( "tmux" , "new" , "-Pd" , "-s" , name )
cmd := exec . Command ( "tmux" , "new" , "-Pd" , "-s" , name , "-n" , windowName , "-c" , root )
return tmux . commander . Exec ( cmd )
return tmux . commander . Exec ( cmd )
}
}
@ -40,22 +40,10 @@ func (tmux Tmux) KillWindow(target string) error {
return err
return err
}
}
func ( tmux Tmux ) NewWindow ( target string , name string , root string , commands [ ] string ) ( string , error ) {
func ( tmux Tmux ) NewWindow ( target string , name string , root string ) ( string , error ) {
cmd := exec . Command ( "tmux" , "neww" , "-Pd" , "-t" , target , "-n" , name , "-c" , root )
cmd := exec . Command ( "tmux" , "neww" , "-Pd" , "-t" , target , "-n" , name , "-c" , root )
window , err := tmux . commander . Exec ( cmd )
return tmux . commander . Exec ( cmd )
if err != nil {
return "" , err
}
for _ , c := range commands {
err = tmux . SendKeys ( window , c )
if err != nil {
return "" , err
}
}
return window , nil
}
}
func ( tmux Tmux ) SendKeys ( target string , command string ) error {
func ( tmux Tmux ) SendKeys ( target string , command string ) error {
@ -65,7 +53,7 @@ func (tmux Tmux) SendKeys(target string, command string) error {
}
}
func ( tmux Tmux ) Attach ( target string , stdin * os . File , stdout * os . File , stderr * os . File ) error {
func ( tmux Tmux ) Attach ( target string , stdin * os . File , stdout * os . File , stderr * os . File ) error {
cmd := exec . Command ( "tmux" , "attach" , "- t", target )
cmd := exec . Command ( "tmux" , "attach" , "- d", "- t", target )
cmd . Stdin = stdin
cmd . Stdin = stdin
cmd . Stdout = stdout
cmd . Stdout = stdout
@ -74,7 +62,7 @@ func (tmux Tmux) Attach(target string, stdin *os.File, stdout *os.File, stderr *
return tmux . commander . ExecSilently ( cmd )
return tmux . commander . ExecSilently ( cmd )
}
}
func ( tmux Tmux ) RenumberWindows ( ) error {
func ( tmux Tmux ) RenumberWindows ( target string ) error {
cmd := exec . Command ( "tmux" , "move-window" , "-r" )
cmd := exec . Command ( "tmux" , "move-window" , "-r" )
_ , err := tmux . commander . Exec ( cmd )
_ , err := tmux . commander . Exec ( cmd )
return err
return err
@ -127,3 +115,8 @@ func (tmux Tmux) ListWindows(target string) ([]string, error) {
return strings . Split ( output , "\n" ) , nil
return strings . Split ( output , "\n" ) , nil
}
}
func ( tmux Tmux ) SwitchClient ( target string ) error {
cmd := exec . Command ( "tmux" , "switch-client" , "-t" , target )
return tmux . commander . ExecSilently ( cmd )
}