diff --git a/config.go b/config.go index c7da319..cee1a10 100644 --- a/config.go +++ b/config.go @@ -2,9 +2,12 @@ package main import ( "fmt" + "log" "os" "os/exec" + "os/user" "path" + "path/filepath" "strings" "gopkg.in/yaml.v2" @@ -67,6 +70,19 @@ func EditConfig(path string) error { func setTmuxOptions(tmuxOpts *TmuxOptions, c Config) { tmuxOpts.SocketName = c.SocketName tmuxOpts.SocketPath = c.SocketPath + + if c.ConfigFile != "" { + usr, err := user.Current() + if err != nil { + log.Fatalf("cannot expand user home dir: %s", err) + } + path := c.ConfigFile + if strings.HasPrefix(path,"~") { + path = filepath.Join(usr.HomeDir, path[1:]) + } + + tmuxOpts.ConfigFile = path + } } func GetConfig(path string, settings map[string]string, tmuxOpts *TmuxOptions) (*Config, error) { diff --git a/config_test.go b/config_test.go index b9da74d..3083dd9 100644 --- a/config_test.go +++ b/config_test.go @@ -12,7 +12,8 @@ session: ${session} sendkeys_timeout: 200 tmux_options: socket_name: foo - socket_path: /foo/bar + socket_path: /path/to/socket + config_file: /path/to/tmux_config windows: - layout: tiled commands: @@ -36,7 +37,8 @@ windows: Env: make(map[string]string), TmuxOptions: TmuxOptions{ SocketName: "foo", - SocketPath: "/foo/bar", + SocketPath: "/path/to/socket", + ConfigFile: "/path/to/tmux_config", }, Windows: []Window{ { diff --git a/tmux.go b/tmux.go index a910ea7..bb7b7e0 100644 --- a/tmux.go +++ b/tmux.go @@ -23,6 +23,9 @@ type TmuxOptions struct { // Default socket path, overrides SocketName SocketPath string `yaml:"socket_path"` + + // tmux config file + ConfigFile string `yaml:"config_file"` } type Tmux struct { @@ -48,6 +51,11 @@ func (tmux Tmux) cmd(args ...string) *exec.Cmd { } else if tmux.SocketName != "" { tmuxCmd = append(tmuxCmd, "-L", tmux.SocketName) } + + if tmux.ConfigFile != "" { + tmuxCmd = append(tmuxCmd, "-f", tmux.ConfigFile) + } + tmuxCmd = append(tmuxCmd, args...) return exec.Command(tmuxCmd[0], tmuxCmd[1:]...)