An open API service indexing awesome lists of open source software.

https://github.com/mooerslab/tmux-bashed

Bash function to automate the setting up of tmux sessions, windows, and panes.
https://github.com/mooerslab/tmux-bashed

automation bash-scripting daily-setup tmux workflow

Last synced: about 1 year ago
JSON representation

Bash function to automate the setting up of tmux sessions, windows, and panes.

Awesome Lists containing this project

README

          

![Version](https://img.shields.io/static/v1?label=tmux-bashed&message=0.2&color=brightcolor)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

# Automated opening of iterm2 tabs and the setup of tmux sessions, windows, and panes

## The problem

Save the time lost to rebuilding the same tmux sessions.
The bash function in the script above takes about two minutes to run.
The manual building of my setup may take ten to 20 minutes.
The time savings are significant.
May I do something significant with my freed time!

## The solution

A bash function called `wf`, **w**ork **f**low.
Enter `wf` and go get some coffee while your computer prepares your workflow for the day.
This approach could save 50-200 keystrokes per day.

## Usage

```bash
chmod +x tmux.sh
source ./tmux.sh # add to your .zshrc file eventually.
wf
```

## Precaution

This supplied function serves as a template.
It will not work entirely on your system because it calls aliases or functions defined elsewhere.

## Requirements

- Willingness to customize for your workflow.
- Mac OS but adaptable to other platforms.
- iterm2
- `advanced-tmux.config` from the [MooersLab/tmux-rocks](https://github.com/MooersLab/tmux-rocks) repo.
- Current version of tmux (install with home brew).
- Current version of tmux-plugin-manager.
- AppleScript
- A text editor to customize the `tmux.sh`.

## Example of autogenerated ten tmux windows in one iterm2 tab

![10windowsWeather](https://github.com/user-attachments/assets/8a649d6f-aaf6-455e-a78a-ab66606035f9)

Five iterm2 tabs were created and populated with five tmux sessions.
The current window is the highlighted tmux tab.
There is a ten-window limit per iterm2 tab.
The color scheme is imposed by the selected profile in iterm2.

## Tab titles
The default tab title in iterm2 will be `tmux`. If you have ten iterm2 tabs open, this row of ten `tmux` is not helpful.
After pasting the following code in your `.zshrc` file, you can change the title of an iterm2 tab by entering `tt`.
I modified the bash function by adding a `tt` command to each call of applescript to create a new tab.

```zsh
DISABLE_AUTO_TITLE="true"
tt () {
echo -e "\033];$@\007"
}
```

## Coloring the iterm2 tabs

Coloring the iterm2 tab can also enhance your identification of the tab of interest.
The following code assigns a random color for the tab each time a new tab is opened.
Add this code to your zshrc file.

```zsh
# randomly color new tabs.
PRELINE="\r\033[A"

function random {
echo -e "\033]6;1;bg;red;brightness;$((1 + $RANDOM % 255))\a"$PRELINE
echo -e "\033]6;1;bg;green;brightness;$((1 + $RANDOM % 255))\a"$PRELINE
echo -e "\033]6;1;bg;blue;brightness;$((1 + $RANDOM % 255))\a"$PRELINE
}

function color {
case $1 in
green)
echo -e "\033]6;1;bg;red;brightness;57\a"$PRELINE
echo -e "\033]6;1;bg;green;brightness;197\a"$PRELINE
echo -e "\033]6;1;bg;blue;brightness;77\a"$PRELINE
;;
red)
echo -e "\033]6;1;bg;red;brightness;270\a"$PRELINE
echo -e "\033]6;1;bg;green;brightness;60\a"$PRELINE
echo -e "\033]6;1;bg;blue;brightness;83\a"$PRELINE
;;
orange)
echo -e "\033]6;1;bg;red;brightness;227\a"$PRELINE
echo -e "\033]6;1;bg;green;brightness;143\a"$PRELINE
echo -e "\033]6;1;bg;blue;brightness;10\a"$PRELINE
;;
*)
random
esac
}

color
```

With `tt` and random coloring enabled, my iterm2 terminal has been enhanced (see image below).
The opened tab is indicated by the white line under the tab.
The tabs labeled `zsh` are not tmux sessions or were intended tmux sessions,
but a bug in the script failed to launch a tmux session in the iterm2 tab.
The `updates` tab had the following command passed, 'brew update && brew upgrade && msu'.
This runs brew update and then an alias to a series of macports commands to update macports and clean up.

Screenshot 2024-11-30 at 8 12 46 AM

## Passing commands to applescript
The `tt` commands were added to the calls to applescript to open new iterm2 tabs with specified titles.
The

## Update history

|Version | Changes | Date |
|:------------|:------------------------------------------------------------------------------------------------------------------------------------------|:---------------------|
| Version 0.1 | Added badges, funding, and update table. Initial commit. | 2024 November 19 |
| Version 0.2 | Added code for adding titles to iterm2 tabs and randomly coloring the iterm2 tabs. Added updates tmux session. Changed function namne from twf to wf. | 2024 November 30 |

## Sources of funding

- NIH: R01 CA242845
- NIH: R01 AI088011
- NIH: P30 CA225520 (PI: R. Mannel)
- NIH: P20 GM103640 and P30 GM145423 (PI: A. West)