Teamocil Documentation

repository·master·Indexed 25 days ago

https://github.com/remi/teamocil

Teamocil is a Ruby gem that automates the creation of tmux windows and panes using YAML configuration files. It allows developers to define complex development environments as code, supporting hierarchical configurations for sessions, windows, and panes. The tool includes a CLI for listing, editing, and executing layouts, as well as support for standard and custom tmux layouts.

Tokens
2.6K
Snippets
6
Records
28
Agent score
80%

What's inside teamocil

  1. Use custom tmux layouts in Teamocil

    master

    Teamocil supports standard tmux layout names:

    • even-horizontal
    • even-vertical
    • main-horizontal
    • main-vertical
    • tiled

    You can also use a custom tmux layout string (the format used by tmux list-windows). To get the layout string for your current window, run:

    tmux list-windows -F "#{window_active} #{window_layout}" | grep "^1" | cut -d " " -f 2

    Then, use that string in your YAML file:

    windows:
      - name: sample-two-uneven-panes
        layout: 00c7,158x38,0,0[158x9,0,0,37,158x28,0,10,39]
        panes:
          - echo foo
          - echo bar
  2. Install and set up Teamocil

    master

    To use Teamocil to automate your tmux layouts, follow these steps:

    1. Install the Ruby gem:
      gem install teamocil
    2. Create the configuration directory:
      mkdir ~/.teamocil
    3. Create and edit a new layout file (e.g., sample.yml) using the --edit flag:
      teamocil --edit sample
    4. Launch tmux and run your layout:
      tmux
      teamocil sample
    # Install the `teamocil` Ruby gem
    $ gem install teamocil
    
    # Create your layout directory
    $ mkdir ~/.teamocil
    
    # Edit ~/.teamocil/sample.yml
    $ teamocil --edit sample
    
    # Launch tmux
    $ tmux
    
    # Run your newly-created sample layout
    $ teamocil sample
  3. Enable shell autocompletion for Teamocil

    master

    Zsh

    Add this to your ~/.zshrc:

    compctl -g '~/.teamocil/*(:t:r)' teamocil

    Bash

    Add this to your ~/.bashrc:

    complete -W "$(teamocil --list)" teamocil

    Fish

    Create ~/.config/fish/completions/teamocil.fish with:

    complete -x -c teamocil -a '(teamocil --list)'
  4. Configure Teamocil YAML layouts

    master

    Teamocil layouts are defined in YAML files. The configuration is hierarchical: Session $\rightarrow$ Windows $\rightarrow$ Panes.

    Session Configuration

    • name: The name of the tmux session.
    • windows: An Array of window objects.

    Window Configuration

    Each window object in the windows array can contain:

    • name: The tmux window name (required).
    • root: The directory path where all panes in this window will start.
    • layout: The tmux layout to apply after panes are created (e.g., even-horizontal, tiled).
    • panes: An Array of pane objects.
    • focus: If true, this window will be selected after the layout is executed.
    • options: A Hash of options to be passed to the tmux set-window-option command.

    Pane Configuration

    A pane can be a simple String (treated as a single command) or a Hash for more control:

    • commands: An Array of commands to run when the pane is created.
    • focus: If true, this pane will be selected after the layout is executed.
  5. Create a window with multiple commands per pane

    master

    To run multiple commands in a single pane, use the commands array instead of a string.

    windows:
      - name: sample-three-panes
        root: ~/Code/sample/www
        layout: main-vertical
        panes:
          - vim
          - commands:
            - git pull
            - git status
          - rails server
  6. Create a simple two-pane window layout

    master

    This example demonstrates a window named sample-two-panes that starts in a specific directory, uses an even-horizontal layout, and runs two different commands in separate panes.

    windows:
      - name: sample-two-panes
        root: ~/Code/sample/www
        layout: even-horizontal
        panes:
          - git status
          - rails server
  7. Troubleshoot malformed layout YAML files

    master
    If teamocil encounters a YAML error while parsing a layout file, it raises a Teamocil::Error::InvalidYAMLLayout error. This indicates that the file at the specified path is not a valid YAML document. To resolve this, verify the syntax of your layout file in ~/.teamocil/ or your project's layout directory, ensuring it follows valid YAML formatting rules.
  8. Use the Teamocil CLI

    master

    The Teamocil command line interface follows this pattern: teamocil [options] [layout-name]

    Global options

    • --list: Lists all available layouts stored in ~/.teamocil.

    Layout options

    • --layout <path>: Use a custom file path to a YAML layout file instead of using a name from ~/.teamocil.
    • --here: Uses the current tmux window as the first window in the layout.
    • --edit <name>: Opens the specified layout file with your $EDITOR instead of executing it.
    • --show <name>: Displays the content of the layout file in the terminal instead of executing it.
    $ teamocil [options] [layout-name]
  9. Use Teamocil module methods

    master

    The Teamocil module provides utility methods for interacting with the system and handling errors.

    • Teamocil.bail(*args): Prints an error message prefixed with [teamocil error] and exits the process.
    • Teamocil.puts(*args): Writes output to STDOUT.
    • Teamocil.system(*args): Executes a system command using Kernel.system.
    • Teamocil.query_system(command): Executes a command via the tmux binary and returns the output using backticks (e.g., Teamocil.query_system('list-sessions')).
    • Teamocil.parse_options!(arguments: nil): Parses command-line arguments using OptionParser and stores the result in Teamocil.options.
  10. List available layouts in a directory

    master

    You can retrieve a sorted list of all available layout names within a specific directory using Teamocil::Layout.print_available_layouts.

    This method:

    1. Scans the directory for .yml files.
    2. Strips the .yml extension from the filenames.
    3. Returns the names in alphabetical order.

    It accepts an optional directory argument.

  11. Manage and execute layouts in Teamocil

    master

    The Teamocil::Layout class manages the lifecycle of a layout file (a .yml file). You can interact with layouts through several primary actions:

    • Execute: Runs the commands defined in the layout within a tmux session. If the global debug option is enabled, it prints the shell commands instead of executing them.
    • Show: Prints the raw YAML content of the layout to the terminal.
    • Edit: Opens the layout file in your default editor (defined by the $EDITOR environment variable, defaulting to vi).

    When executing, Teamocil joins commands with ; and prefixes them with tmux to ensure they run within the tmux environment.