• Stars
    star
    135
  • Rank 269,297 (Top 6 %)
  • Language
    Shell
  • License
    MIT License
  • Created almost 12 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create default configurations for your named tmux sessions

tmuxstart

Tmuxstart can be used to create reusable configurations for named tmux sessions. To use tmuxstart add a binding to your .tmux.conf file like:

bind S command-prompt -p "Make/attach session:" "new-window 'tmuxstart \'%%\''"

With the above binding, pressing <PREFIX> S will prompt you for a session name. <PREFIX> is CTRL-b by default.

Installation

Just copy the tmuxstart file to one of the directories in your $PATH. I suggest either /usr/bin, /usr/local/bin, or ~/bin.

Session Files

To create a default configuration for a named session create a file named after the session under the directory ~/.tmuxstart. These session files will have the shell variable $session available to them.

Session files are just sourced shell scripts. This makes them more flexible than tmuxinator sessions. There are no dependencies for tmuxstart so it can easily be used on any machine with tmux installed.

Helper functions

To make the process of writing session files easier some helper functions are included in the tmuxstart script. The available helper functions are:

new_session

new_session creates a new auto-named session. This should usually be the first command called in a session file. This function accepts the same arguments as tmux new-session. Examples:

new_session  # Just create the session
new_session -n top htop  # Initial window named "top" running htop

new_window

new_window creates a new window in the new session. This function accepts the same arguments as tmux new-window. Examples:

new_window  # Just create a new window
new_window -n edit emacs  # Create a new window named "edit" running emacs

rename

rename renames an existing window. This function accepts the same arguments as tmux rename-window.

send_keys

send_keys sends keys to a given window number in the new session. This function accepts the same arguments as tmux send-keys. Examples:

send_keys 1 "echo hello" "Enter"  # Run "echo hello" in window 1
send_keys 2 C-c  # Send Ctrl-C key combination to window 2

send_line

send_line sends a line of input to a given window number in the session. This function accepts the same arguments as send_keys but adds "Enter" as an additional argument to each call. Examples:

send_line 1 "echo hello"  # Same as example above, but no need for "Enter"

select_window

select_window selects the given window number in the new session. This function accepts the same arguments as tmux select-window. Example:

select_window 1  # Select window 1

select_pane

select_pane selects the given window and pane number in the new session. This function accepts the same arguments as tmux select-pane. Examples:

select_pane 2.1  # Select pane 1 in window 2
select_pane 1.2  # Select pane 2 in window 1

select_layout

select_layout applies a given layout to the selected window. This function accepts the same arguments as tmux select-layout. Example:

select_layout 2 main-vertical # Arrange window 2 in the main-vertical layout

kill_window

kill_window kills the given window number in the new session. This function accepts the same arguments as tmux kill-window. Example:

kill_window 1  # Kills window 1

set_env

set_env sets an environment variable for the new session. This function accepts the same arguments as tmux set-environment. Example:

set_env EDITOR acme  # Set EDITOR environment variable to "acme"

set_path

set_path sets the default working directory for new panes in the new session. This function access the same arguments as tmux default-path. Example:

set_path ~/repos/personal/my_project

split

split splits the given window or pane based on the arguments given. This function accepts the same arguments as tmux split-window. Example:

split 2 -h  # Split window 2 horizontally
split 2.1 -l 2  # Split pane 1 in window 2 vertically using 2 text lines
split 1 -p -v "10%"  # Split window 1 vertically using 10% of given space

swap

swap swaps the given pane with another pane. This function accepts the same arguments as tmux swap-pane. Example:

swap 2.1 -D  # Swap pane 1 in window 2 with the next pane
swap 3.2 -U  # Swap pane 2 in window 3 with the previous pane
swap 4.3 -s 2.1  # Swap pane 3 in window 4 with pane 1 in window 2

Example session files

The following session file will create a window called "htop" which will run the htop command and then create a window containing a shell which will be selected when the session starts:

new_session -n htop htop
new_window

This session file will start a session with a Django server in the first window and open a vim browser and Django shell in the second window. Virtualenvwrapper is used via the workon command for virtualenv management:

# Go to the Django repository directory and start the session
cd "$HOME/repos/$session"
new_session -n server

# Run the Django server in the first window
send_keys 1 "workon $session" "Enter"
send_keys 1 "python manage.py runserver" "Enter"

# Create a second window with a vim file browser open
new_window -n edit "vim ."

# Create 20% split at bottom of window 2 and run Django shell in it
split 2 -v -p "20"
send_keys 2.2 "workon $session" "Enter"
send_keys 2.2 "python manage.py shell" "Enter"

# Select pane 1 in window 2
select_pane 2.1

CLI usage

Arguments
$ tmuxstart session_name

Will search for a session file called "session_name" in $TMUXSTART_DIR if set, otherwise in ~/.tmuxstart and load it. If no such file is found, it will start a new tmux session named "session_name".

$ tmuxstart -h

Show help dialog.

$ tmuxstart -l

List all available session files.

$ tmuxstart -v

Print tmuxstart version number.

Contributing & Help

Feel free to contribute new helper functions, features/bug fixes, documentation, or usage examples. Pull requests are welcome.

If you need help please open an issue, or comment on my tmuxstart announcement if you find a bug or you need help with tmuxstart.

License

Tmuxstart is provided under an MIT license: http://th.mit-license.org/2012

Related Projects

Inspirations and similar projects:

More Repositories

1

names

Random name generator
Python
452
star
2

resume

LaTeX resume format
TeX
241
star
3

invoices

Simple LaTeX invoice format
84
star
4

dramatic

Display all Python process output character-by-character
Python
47
star
5

django-email-log

Django email backend that logs all emails
Python
40
star
6

editorconfig-tools

Experimental: Tools for verifying/fixing code style based on EditorConfig file (not completed yet)
Python
37
star
7

custom-bootstrap-example

Example of using a custom Bootstrap build with bootstrap-sass and bower
CSS
36
star
8

dotfiles

My dotfiles
Vim Script
34
star
9

countdown-cli

Full-screen countdown timer, centered in the terminal window
Python
25
star
10

http-tui

HTTP API Client TUI
Python
25
star
11

ember-deploy-ssh-index

ember-deploy index-adapter for SSH
JavaScript
23
star
12

undataclass

Turn dataclasses into not-dataclasses
Python
22
star
13

pseudorandom.name

Random name generator website
Python
22
star
14

python-oddities

Yes this repository will be renamed soon...
21
star
15

jquery-formrestrict

jQuery plugin to restrict form input (includes replacement for AlphaNumeric plugin)
JavaScript
18
star
16

django-relatives

Utilities for linking to related objects in Django admin
Python
18
star
17

disallow-import-star

Stop your users from using "import *"
Python
15
star
18

pep438

Check packages in your requirements.txt file for good PEP 438 usage
Python
14
star
19

utf-cli

Search Unicode characters from your terminal
Python
8
star
20

exercism-python

Python Exercism problems
Python
6
star
21

jquery-django-formset

jQuery plugin for dynamically adding/removing forms from Django formsets
JavaScript
6
star
22

python-oddities-talk

Python Oddities Explained talk #pythonoddity
JavaScript
6
star
23

treyhunner.github.com

My blog
HTML
5
star
24

django-skeleton-app

Tips for creating an open source Django project
Python
3
star
25

SandTrap

Identify malicious website spidering bots and block them from accessing PHP pages.
PHP
3
star
26

readability-counts

25 minute talk on writing readable code
JavaScript
3
star
27

detect-charset

Detect character set of file
JavaScript
2
star
28

loop-better

JavaScript
2
star
29

mentoring

Meaningful Mentoring Moments talk
JavaScript
2
star
30

ingress-inventory-counter

Ingress Item Counter
CSS
2
star
31

Arclight

Modified version of Arclight theme for MythTV
2
star
32

editorconfig-python-validator

Validators .editorconfig against text files found (only checks indentation on .py files)
Python
1
star
33

django-dependency

Git fork of django-dependency
Python
1
star
34

jQuery.dotdotdot-plugin

version 1.5.2 of the jQuery dotdotdot plugin
JavaScript
1
star
35

audio-scripts

Collection of scripts useful for managing music collections
Shell
1
star
36

project-euler

My solutions to Project Euler problems
Haskell
1
star
37

databundles

Data Bundles are packages of data that simplify the process of finding, cleaning, transforming and loading popular datasets. http://clarinova.com/bundles
Python
1
star
38

CurrentTime

Twitter bot that tweets the current time
Python
1
star
39

lazy-looping

Lazy Looping: The Next Iteration (talk slides)
JavaScript
1
star
40

talk-talk

Give a lightning talk
JavaScript
1
star
41

patchio

Python monkey patching utilities
Python
1
star
42

magic-djv-file-example

A djv file format including both a Django template and a view that uses it in the same file (you probably shouldn't do this...)
Python
1
star