Skip to content

Commit

Permalink
set custom tmux config file
Browse files Browse the repository at this point in the history
Signed-off-by: blob42 <[email protected]>
  • Loading branch information
blob42 committed Jun 15, 2024
1 parent 81bc3ed commit 625a22b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
16 changes: 16 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package main

import (
"fmt"
"log"
"os"
"os/exec"
"os/user"
"path"
"path/filepath"
"strings"

"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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{
{
Expand Down
8 changes: 8 additions & 0 deletions tmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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:]...)
Expand Down

0 comments on commit 625a22b

Please sign in to comment.