项目作者: ivaaaan

项目描述 :
A session manager for tmux written in Go
高级语言: Go
项目地址: git://github.com/ivaaaan/smug.git
创建时间: 2020-12-20T13:04:19Z
项目社区:https://github.com/ivaaaan/smug

开源协议:MIT License

下载


Smug - tmux session manager

Actions Status
Go Report Card

Inspired by tmuxinator and tmuxp.

Smug automates your tmux workflow. You can create a single configuration file, and Smug will create all the required windows and panes from it.

gif

The configuration used in this GIF can be found here.

Installation

Download from the releases page

Download the latest version of Smug from the releases page and then run:

  1. mkdir smug && tar -xzf smug_0.1.0_Darwin_x86_64.tar.gz -C ./smug && sudo mv smug/smug /usr/local/bin && rm -rf smug

Don’t forget to replace smug_0.1.0_Darwin_x86_64.tar.gz with the archive that you’ve downloaded.

Prerequisite Tools

Fetch from GitHub

The easiest way is to clone Smug from GitHub and install it using go-cli:

  1. go install github.com/ivaaaan/smug@latest

macOS

On macOS, you can install Smug using MacPorts or Homebrew.

Homebrew

  1. brew install smug

MacPorts

  1. sudo port selfupdate
  2. sudo port install smug

Linux

Arch

There’s AUR with smug.

  1. git clone https://aur.archlinux.org/smug.git
  2. cd smug
  3. makepkg -si

Usage

  1. smug <command> [<project>] [-f, --file <file>] [-w, --windows <window>]... [-a, --attach] [-d, --debug]

Options:

  1. -f, --file A custom path to a config file
  2. -w, --windows List of windows to start. If session exists, those windows will be attached to current session.
  3. -a, --attach Force switch client for a session
  4. -i, --inside-current-session Create all windows inside current session
  5. -d, --debug Print all commands to ~/.config/smug/smug.log
  6. --detach Detach session. The same as `-d` flag in the tmux

Custom settings

You can pass custom settings into your configuration file. Use ${variable_name} syntax in your config and then pass key-value args:

  1. xyz@localhost:~$ smug start project variable_name=value

Examples

To create a new project, or edit an existing one in the $EDITOR:

  1. xyz@localhost:~$ smug new project
  2. xyz@localhost:~$ smug edit project

To start/stop a project and all windows, run:

  1. xyz@localhost:~$ smug start project
  2. xyz@localhost:~$ smug stop project

Also, smug has aliases to the most of the commands:

  1. xyz@localhost:~$ smug project # the same as "smug start project"
  2. xyz@localhost:~$ smug st project # the same as "smug stop project"
  3. xyz@localhost:~$ smug p ses # the same as "smug print ses"

When you already have a running session, and you want only to create some windows from the configuration file, you can do something like this:

  1. xyz@localhost:~$ smug start project:window1
  2. xyz@localhost:~$ smug start project:window1,window2
  3. xyz@localhost:~$ smug start project -w window1
  4. xyz@localhost:~$ smug start project -w window1 -w window2
  5. xyz@localhost:~$ smug stop project:window1
  6. xyz@localhost:~$ smug stop project -w window1 -w window2

Also, you are not obliged to put your files in the ~/.config/smug directory. You can use a custom path in the -f flag:

  1. xyz@localhost:~$ smug start -f ./project.yml
  2. xyz@localhost:~$ smug stop -f ./project.yml
  3. xyz@localhost:~$ smug start -f ./project.yml -w window1 -w window2

Configuration

Configuration files can stored in the ~/.config/smug directory in the YAML format, e.g ~/.config/smug/your_project.yml.
You may also create a file named .smug.yml in the current working directory, which will be used by default.

Examples

Example 1

  1. session: blog
  2. root: ~/Developer/blog
  3. before_start:
  4. - docker-compose -f my-microservices/docker-compose.yml up -d # my-microservices/docker-compose.yml is a relative to `root`
  5. env:
  6. FOO: BAR
  7. stop:
  8. - docker stop $(docker ps -q)
  9. windows:
  10. - name: code
  11. root: blog # a relative path to root
  12. manual: true # you can start this window only manually, using the -w arg
  13. layout: main-vertical
  14. commands:
  15. - docker-compose start
  16. panes:
  17. - type: horizontal
  18. root: .
  19. commands:
  20. - docker-compose exec php /bin/sh
  21. - clear
  22. - name: infrastructure
  23. root: ~/Developer/blog/my-microservices
  24. layout: tiled
  25. panes:
  26. - type: horizontal
  27. root: .
  28. commands:
  29. - docker-compose up -d
  30. - docker-compose exec php /bin/sh
  31. - clear

Example 2

  1. session: blog
  2. root: ~/Code/blog
  3. before_start:
  4. - docker-compose up -d
  5. stop:
  6. - docker-compose stop
  7. windows:
  8. - name: code
  9. layout: main-horizontal
  10. commands:
  11. - $EDITOR app/dependencies.php
  12. panes:
  13. - type: horizontal
  14. commands:
  15. - make run-tests
  16. - name: ssh
  17. commands:
  18. - ssh -i ~/keys/blog.pem ubuntu@127.0.0.1