Skip to content

austinwilcox/disconnected

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Disconnected

Disconnected is a simple tmux session creator. Using JSON you can specify how many windows you want, and what commands to run in each of those windows.

Setup

  1. To setup Disconnected, ensure that you have Deno installed on your machine.
  2. Run the following command
deno compile --allow-read --allow-env --allow-write --allow-run --output ./dist/disconnected index.ts

or you can download the most recent release in the releases.

  1. This will generate a disconnected executable that you can run on your machine. You can add this directory to your path, or toss it in the bin folder with your shell.
cp ./dist/disconnected /usr/local/bin

NOTE: Depending on your user permissions you may need to run this with sudo.

  1. After you have disconnected added to path run
disconnected

or

disconnected init

This will create the necessary folders and files in the ~/.config/disconnected folder so that disconnected can save settings.

  1. Create a new config file with
disconnected new NameOfService

with nameOfService being whatever you would like to call the config file

  1. You'll be presented with a json file in your editor of choice that you can modify and edit to setup your sessions.

Recommended tmux Config

To have new splits open in the current pane's directory, add the following to your ~/.tmux.conf:

bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"

Then reload your config:

tmux source-file ~/.tmux.conf

Build from source

deno compile --allow-read --allow-env --allow-write --allow-run --output ./dist/disconnected index.ts
chmod +x ./dist/disconnected

Commands

Command Description
disconnected init Create config directory and files
disconnected start <name> Start or attach to a tmux session from a config file
disconnected list List all config files
disconnected new <name> Create a new config file (opens in editor)
disconnected edit <name> Edit an existing config file
disconnected rm <name> Delete a config file
disconnected capture <session> [outputName] Capture a running tmux session into a config file

The Config File

Here is the sample config file that is generated for you

{
  "name": "SampleBaseConfig",
  "basePath": "~/",
  "startingWindow": "1",
  "windows": [
    {
      "name": "listfiles",
      "basePath": "",
      "commands": ["ls"],
      "shouldCloseAfterCommand": false,
      "concatenateBasePathToGlobalBasePath": false
    },
    {
      "name": "htop",
      "basePath": "",
      "commands": ["htop"],
      "shouldCloseAfterCommand": true,
      "concatenateBasePathToGlobalBasePath": false
    }
  ]
}

name: This will be the name of the tmux session

basePath: This will be the base path for your project you are working in.

startingWindow: The default option is 1, in my tmux config I do 1-9, and I don't use 0. This is my opinionated config for tmux.

windows:

  • name: Name of the tmux window
  • basePath: This may build on the global basePath, so if your basePath is set globally is ~/Software this one could drill down into the tools folder by suppyling tools as the option here. With the concatenateBasePathToGlobalBasePath you now have to specify that value as true if you want to build off the global base path.
  • commands: A series of shell commands that you want run in that window.
  • shouldCloseAfterCommand: tells tmux whether or not to close the window after the commands are complete.
  • concatenateBasePathToGlobalBasePath: determines whether or not to concatenate the global basePath with the window basePath. Default value is false.
  • panes: An optional array of panes to create within the window (see Pane Support below).

Pane Support

Windows can contain panes by adding a panes array to a window config:

{
  "name": "mywindow",
  "basePath": "~/Software/myproject",
  "commands": [],
  "shouldCloseAfterCommand": false,
  "concatenateBasePathToGlobalBasePath": false,
  "panes": [
    {
      "splitDirection": "horizontal",
      "basePath": "",
      "commands": ["npm run dev"],
      "shouldCloseAfterCommand": false
    },
    {
      "splitDirection": "vertical",
      "basePath": "",
      "commands": ["npm run test:watch"],
      "shouldCloseAfterCommand": false
    }
  ]
}

splitDirection accepts "horizontal" or "vertical".

Capture Command

The capture command lets you convert a running tmux session into a disconnected config file:

disconnected capture <session-name> [output-name]

This will inspect the running session, record window names, working directories, pane layouts, and active commands, then save the result as a JSON config file in ~/.config/disconnected. Useful for saving a session you built manually so you can recreate it later.

TODO

  • When I run dsc list it would nice to know which of those sessions are running.
  • Update this so that the name auto defaults to the name of the file.
  • Support panes in the future.
  • Do some name validation here to ensure no spaces are in the name
  • Improve the text validation for attaching to a service that has already been started (currently it's a simple includes)

About

Disconnected is a simple tmux session creator.

Resources

License

Stars

Watchers

Forks

Contributors