Skip to content

Commit

Permalink
Add more document and handle no first window
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrebodin committed Jul 9, 2018
1 parent b663c64 commit d95d48e
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 23 deletions.
File renamed without changes.
6 changes: 6 additions & 0 deletions __examples__/simple.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name="simple-session"
dir="~/"
select-window=""
select-pane=1
clear-panes=true
window-scripts=["ls"]
6 changes: 6 additions & 0 deletions __examples__/single-window.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name="single-window-session"
dir="~/Desktop"

[[windows]]
name="window-one"
dir="~/"
29 changes: 14 additions & 15 deletions builder/session.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package builder

import (
"errors"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -53,20 +52,21 @@ func (sess *Session) Start() error {
}

if len(sess.Windows) == 0 {
return errors.New("session has no window")
}
_, err = tmux.Exec("new-session", "-d", "-s", sess.Name, "-c", sess.Dir, "-x", width, "-y", height)
} else {

firstWindow := sess.Windows[0]
_, err = tmux.Exec("new-session", "-d", "-s", sess.Name, "-c", sess.Dir, "-n", firstWindow.Name, "-x", width, "-y", height)
if err != nil {
return fmt.Errorf("starting session: %v", err)
}

if firstWindow.Dir != sess.Dir {
cdCmd := fmt.Sprintf("cd %s", firstWindow.Dir)
err := tmux.SendKeys(sess.Name+":"+firstWindow.Name, cdCmd)
firstWindow := sess.Windows[0]
_, err = tmux.Exec("new-session", "-d", "-s", sess.Name, "-c", sess.Dir, "-n", firstWindow.Name, "-x", width, "-y", height)
if err != nil {
return fmt.Errorf("moving window to dir %s: %v", firstWindow.Dir, err)
return fmt.Errorf("starting session: %v", err)
}

if firstWindow.Dir != sess.Dir {
cdCmd := fmt.Sprintf("cd %s", firstWindow.Dir)
err := tmux.SendKeys(firstWindow.Target, cdCmd)
if err != nil {
return fmt.Errorf("moving window to dir %s: %v", firstWindow.Dir, err)
}
}
}

Expand All @@ -80,9 +80,8 @@ func (sess *Session) Start() error {
}

for _, win := range sess.Windows {

for _, script := range sess.WindowScripts {
err := tmux.SendKeys(sess.Name+":"+win.Name, script)
err := tmux.SendKeys(win.Target, script)
if err != nil {
return err
}
Expand Down
6 changes: 0 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"errors"
"fmt"
"io"

Expand Down Expand Up @@ -49,11 +48,6 @@ var (
)

func checkValid(conf Session) error {
// check at least one window
if len(conf.Windows) == 0 {
return errors.New("you must declare at least on window (0 provided)")
}

// check select-window and select-pane exist
if conf.SelectWindow != "" {
var win Window
Expand Down
2 changes: 1 addition & 1 deletion docs/01-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Installation
---

You can install Tmuxctl with on of the methods bellow.
You can install Tmuxctl with one of the methods bellow.

The recommended method is to run the following command, which installs `tmuxctl` in ./bin/tmuxctl by default.
```
Expand Down
6 changes: 5 additions & 1 deletion docs/02-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
title: Getting started
---

Tmuxctl uses config files to start a session.

Start by creating a toml config file (by default `tmuxctl` will look for a `.tmuxctlrc` in the current dir, up the parent directories)

```toml
name="azdaz"

[[windows]]
name="win-1"
```
```

You can see more examples in the [examples](https://github.com/alexandrebodin/tmuxctl/tree/master/__examples__) folder
163 changes: 163 additions & 0 deletions docs/03-configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
---
title: Configuration
---

Tmuxctl works with configuration files. Here is the list of possible options

## name

You can set a session name

```toml
name="session-name"
```

## dir

You can set a base directory for your windows

```toml
dir="~/zad"
```

## select-window

You can choose which window to attach to on start

```toml
select-window="window-name"
```

## select-pane

You can choose which pane to attach to on start (the index of the pane in the window starting from 1)

```toml
select-pane=2
```

## clear-panes

You can clear the panes (C-l) after initialisation

```toml
clear-panes=true
```

## window-scripts

You can run scripts in every window (runs before anything else in a window)

```toml
window-scripts=[
"cd folder",
"ls -larth"
]
```

## [[windows]]

You can add windows like follow

```toml
name="session-name"

[[windows]]

[[windows]]

[[windows]]
```

## name

You can give a name to a window

```toml
name="window-name"
```

## dir

You can start a window in a directory (every pane in this window will start there by default)

```toml
dir="/some-dir"
```

## scripts

You can run scripts in the window before it is splitted in panes (they will run once)

```toml
scripts=[
"do sth"
]
```

## pane-scripts

You can run scripts in every pane of a window if needed

```toml
pane-scripts=[
"do sth"
]
```

## sync

You can synchronize all the panes of a window

```toml
sync=true
```

## [[windows.panes]]

You can declare all the paes you want to have in a window

```toml
name="session-name"

[[windows]]
name="window-name"

[[windows.panes]]

[[windows.panes]]

[[windows.panes]]
```

## dir

You can start a pane in a specific dir

```toml
dir="/some-dir"
```

## scripts

You can run a list of scripts in a specific pane

```toml
scripts=["do stuff"]
```

## split

You can specify the split options to setup a pane size. See [the docs](https://www.systutorials.com/docs/linux/man/1-tmux/) for split-window options

```toml
split="-f -h"
```

## zoom

You can set a pane as zoomed (only visible pane in the window) on startup

```toml
zoom=true
```

0 comments on commit d95d48e

Please sign in to comment.