All Projects → RobusGauli → mx.sh

RobusGauli / mx.sh

Licence: MIT license
Lean and opinionated tmux session manager.

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to mx.sh

drop-in
Remote workspace
Stars: ✭ 47 (+135%)
Mutual labels:  tmux
magpie
Dotfiles of my minimal Unix system geared for media, programming & writing
Stars: ✭ 37 (+85%)
Mutual labels:  tmux
SpringSecurityInEasySteps
Learn Spring Security step by step
Stars: ✭ 13 (-35%)
Mutual labels:  session-management
dotfiles
shell, git, vim, tmux .etc dotfiles, managed via gnu stow
Stars: ✭ 20 (+0%)
Mutual labels:  tmux
dotfiles
My dot files and dev environment using bash, tmux and vim
Stars: ✭ 61 (+205%)
Mutual labels:  tmux
tools
Little codes here and there to automate some of my boring daily routines and configurations
Stars: ✭ 82 (+310%)
Mutual labels:  tmux
muxnect
Send input to just about any interactive command-line tool through a local web server
Stars: ✭ 23 (+15%)
Mutual labels:  tmux
tmux-base16-statusline
Tmux Base16 Statusline
Stars: ✭ 24 (+20%)
Mutual labels:  tmux
dotfiles
🏡 Personal dotfiles configuration
Stars: ✭ 73 (+265%)
Mutual labels:  tmux
tdab
Create side and top bars in tmux easily, along with a "devour" style command.
Stars: ✭ 14 (-30%)
Mutual labels:  tmux
dotfiles
🏎 my dotfiles for macOS
Stars: ✭ 33 (+65%)
Mutual labels:  tmux
dotfiles
My dotfiles and some scripts
Stars: ✭ 34 (+70%)
Mutual labels:  tmux
dotfiles
My work setup
Stars: ✭ 14 (-30%)
Mutual labels:  tmux
configuration
Config files
Stars: ✭ 12 (-40%)
Mutual labels:  tmux
dotfiles
All my dotfiles (vim, zsh, tmux, etc.) in a single place
Stars: ✭ 42 (+110%)
Mutual labels:  tmux
dotfiles
A place to store config files so I can revert when my entire system crashes from entering the wrong character
Stars: ✭ 25 (+25%)
Mutual labels:  tmux
dotfiles
My dotfiles
Stars: ✭ 204 (+920%)
Mutual labels:  tmux
appear
reveal terminal programs in the gui
Stars: ✭ 29 (+45%)
Mutual labels:  tmux
dotfiles
PJ's dotfiles - There are many like it but this one is mine
Stars: ✭ 24 (+20%)
Mutual labels:  tmux
dotfiles
Configuration files for my development environment.
Stars: ✭ 14 (-30%)
Mutual labels:  tmux

MIT License


Logo

Manage tmux sessions with simple configuration. Lean and opinionated.

mx.sh

Why another tmux session manager?

  • It has to work out of box without any bloats.
  • Because, I didn't want runtime dependency such as Ruby interpreter just to manage my tmux sessions.
  • Shell scripting is free and native, lets do more of that.

Requirements

  • bash >= 4.x

Installation

Copy paste this in your terminal

curl https://raw.githubusercontent.com/RobusGauli/mx.sh/v0.6.1-alpha/install.sh | bash

This will install mx script in your path. Run mx to verify the installation.

Getting Started

Below steps assumes that you have a working knowledge of tmux and you understand the concepts of windows, panes and sessions in tmux. Also, you are able to attach and detach to tmux session. If you think you are rusty around these topics, you could reach out to man page or this awesome quick tour blog.

1. Generate configuration template

mx template --json --session euler

2. Start the session 🚀

mx up

3. Attach to the session

mx attach

Congratulations!!

To destroy the session

Note: You need to detach from the current tmux session before you can destroy.

mx down --session euler

Learn more

Below is the configuration template that is created when you run mx template --session euler. This will create a json configuration file called mxconf.json in your directory where you ran the command . mx looks for this file for managing your tmux sesssion.

You could use yaml instead of json for managing your configuration file by adding --yaml flag during template generation.

mx template --yaml --session novaproject

However, you need to pip install pyyaml to enable yaml support.

NOTE: The value of workdir is the path that where you ran mx template. For example, mx template command ran on /home/euler/sessions path.

{
 "session": "euler",
 "windows": [
   {
     "name": "w1",
     "panes": [
       {
         "workdir": "/home/euler/sessions",
         "command": "echo \"Hey from pane 1\""
       },
       {
         "workdir": "/home/euler/sessions",
         "command": "echo \"Hi from pane 2\""
       }
     ]
   },
   {
     "name": "w2",
     "panes": [
       {
         "workdir": "/home/euler/sessions",
         "command": "htop"
       },
       {
         "workdir": "/home/euler/sessions",
         "size": 20,
         "command": "python"
       },
       {
         "workdir": "/home/euler/sessions",
         "command": "cal\ndate"
       }
     ]
   }
 ]
}

The above configuration file defines following resources:

  • Tmux sesssion "euler"
  • 2 Tmux windows "w1" and "w2"
  • 2 Panes in window "w1"
  • 3 Panes in window "w2"
  • Shell command such as htop, cal, date, python, etc to run on different panes.
  • Working directory for each pane.

This will give you a basic overview of how configuration is defined. You could extend this configuration to have as many number of windows and panes as you wish. You could also run multiple commands by delimiting using \n. Typical example would be initiating vpn connection and starting virtual environment for your python development.

Below is the sample configuration using yaml

session: euler
windows:
- name: w1
  panes:
  - workdir: "/home/euler/sessions"
    command: echo "Hey from pane 1"
  - workdir: "/home/euler/sessions"
    command: echo "Hi from pane 2"
- name: w2
  panes:
  - workdir: "/home/euler/sessions"
    command: htop
  - workdir: "/home/euler/sessions"
    size: 20
    command: python
  - workdir: "/home/euler/sessions"
    command: |-
      cal
      date

And, below is my typical configuration that I personally use in managing one of my project.

session: node
windows:
  - name: functions
    panes:
      - workdir: ~/work/sessions/node/function/
        command: nvim # Start neovim session
      - workdir: ~/work/sessions/node/function/
        command: npm version
  - name: api
    panes:
      - workdir: ~/work/sessions/node/node_backend/
        command: nvim
      - workdir: ~/work/sessions/node/node_backend/
        size: 20
        command: |-
          # connect to vpn
          nordvpn connect de507
          # Activate python environment
          source venv/bin/activate
          # Source environment variables
          source env.stage.sh
          # Run the app
          python app/run.py
      - workdir: ~/work/sessions/node/node_backend/
        command: |-
          # Run postman
          postman
  - name: database
    panes:
      - workdir: ~/work/sessions/node/node_backend
        command: |-
          # Connect to vpn
          nordvpn connect de507
          # SSH into bastion hosts
          ssh engineer@ec1*.3*.342.us-west-2.compute.amazonaws.com
          # Run alias command
          alias
      - workdir: ~/work/sessions/node/node_backend/
        size: 20
        command: |-
          # Open sql client
          beekeeper-studio
      - workdir: ~/work/sessions/node/node_backend/
        command: |-
	  # Open firefox browser with my jira tickets
          firefox https://node.atlassian.net/jira/

Starting session

After you have written/edited configuration file according to your requirement, you could start the session simply by running

mx up

This command looks for mxconf.yaml or mxconf.json file in the current directory and provisions a new session for you. This command will start the session but won't automatically attach to it. If you want to attach to session after you start the session, you could run

mx up --attach

If you want to use different session name overriding name of session that is defined in your configuration, you could run

mx up --session bigbang

List sessions

You could verify by running mx list command that will list all active tmux sessions. Below is the output that you can expect from running mx list command.

1 => mxsession: 2 windows (created Mon Oct 26 09:20:10 2020) [190x46]
2 => node: 2 windows (created Mon Oct 26 09:57:06 2020) [80x24]

You can see that there are 2 active tmux sessions running named "mxsession" and "node". If you notice carefully, they are indexed using number 1 and 2 respectively. Number 1 is assigned to session named "mxsession" and number 2 is assigned to "node" session.

Attaching to session

Now to attach to one of the running session(s), you could simple run

mx attach --session mxsession

The above command attaches to session named "mxsession"

You could also use index to attach to "mxsession" session by running

mx attach --index 1

If you think this is just too much typing, run mx attach and it will simply attach to recently created session.

Destroying session

NOTE: In order to destroy the session, you need to detach from the running session.

To destroy the running session, you could run

mx down --session euler

The above command will destroy the session named "euler". If you want to destroy all the active sessions, you could simply run

mx down --all

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

Distributed under the MIT License. See LICENSE for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].