<commit_before>tmux-agent - tmux initial action agent
==========

- [Background](#background)
- [Overview](#overview)
- [Installation](#installation)
- [Zsh completion enhancement](#zsh-completion-enhancement)
- [Usage](#usage)
- [Additional Functions](#additional-functions)
- [File Format](#file-format)
    - [Keys](#keys)
    - [Variables](#variables)
    - [Comment](#comment)
    - [Indentation](#indentation)
    - [Blank line](#blank-line)
- [Sample Initial Action Files](#sample-initial-action-files)
- [Test Environment](#test-environment)

Background
----------

tmux is a very useful multifunctional terminal multiplexer.
I use tmux habitually, and like tmux's behavior basically. 
But initial actions that are creations of windows/panes, layouts sets, movements between directories, ssh to remote servers and so on become troublesome as tmux is used for various works.

A simple solution of that is coding scripts with tmux commands. However the coding is troublesome, too.

The tmux-agent loads simple format files that present initial actions, and acts according to the contents. It may make some tmux users more happy.

Overview
----------

tmux-agent is a simple bash script. It depends on bash, tmux, and basic Linux/BSD commands. 

A loaded file is comma separated format (key:value). Examples are as follows.

- Open 2 windows and ssh app1, app2 servers. Then hostname command on remote servers are executed.

        # file: app-ssh-windows
        session: app-ssh-windows
          window-command: ssh ${window}
          window-command: hostname
          window: app{1,2}

- Open 1 window and 3 panes. Then ssh web1 -- web3 servers. Then logs of the web servers are displayed by tail command. At last, the panes are synchronized.

        # file: web-log-sync-ssh-panes
        session: web-log-sync-ssh-panes
          pane-command: ssh ${pane}
          pane-command: tail -f /var/log/httpd/access_log
          pane-sync:
          pane: web{1..3}

- Target hosts are specified by command line arguments. And layout is set to "even-horizontal".

        # file: sync-ssh-panes
        session: ${file}_${id}_${argv}
          pane-command: ssh -l moya ${pane}
          pane-sync:
          pane-layout: even-horizontal
          pane: ${argv}

The files are expected to be located a certain directory (default: `~/.tmux-agent/`).

tmux-agent is used as follows. 

    $ tmux-agent app-ssh-windows

![app-ssh-windows Appearance Image](images/app-ssh-windows.png "app-ssh-windows Appearance Image")

    $ tmux-agent web-log-sync-ssh-panes

![web-log-sync-ssh-panes Appearance Image](images/web-log-sync-ssh-panes.png "web-log-sync-ssh-panes Appearance Image")

    $ tmux-agent sync-ssh-panes dev{1,2} stg

![sync-ssh-panes Appearance Image](images/sync-ssh-panes.png "sync-ssh-panes Appearance Image")

Installation
----------

Installation example is as follows.
In this example, tmux-agent is installed in `~/bin` (The directory is expected to be included in PATH environment variable)

    $ git clone git://github.com/mo-ya/tmux-agent.git

If git is not available in your system, download a zip file from https://github.com/mo-ya/tmux-agent and extract that.

    $ cd tmux-agent
    
    $ cp bin/tmux-agent.sh ~/bin/tmux-agent
    
    $ chmod 755 ~/bin/tmux-agent
    
    $ cp -r init-action-files.sample ~/.tmux-agent

Please test as follows.

    $ tmux-agent install-test

"install-test" session will start. Please check each window.

If the checks pass, installation is completed. 

If you use Zsh, the usability could be increaced more. Please read next section. There are the usage description and the detail of file format below that.

Zsh completion enhancement
----------

Please move the directory where tmux-agent is downloaded. Then, copy "zshrc.tmux" to your home directory.

    $ cp zsh.completion/zshrc.tmux ~/.zshrc.tmux

Then add a following description into ~/.zshrc under `autoload -U compinit ; compinit` description.

    ZSHRC=${HOME}/.zshrc.tmux
    [ -f ${ZSHRC} ] && source ${ZSHRC}

Setting is completed. After .zshrc is reloaded, input tmux-agent <TAB>. As a result, initial action files (and attached/detached sessions) are complemented as follows.

    $ tmux-agent <TAB>

    multi-ssh-windows   -- init-action
    multi-ssh-windows0  -- attached
    multi-ssh-windows1  -- detached
    no-title            -- init-action
    no-title0           -- detached
    sync-ssh-panes      -- init-action
    tail-webservs-log   -- init-action
    tail-webservs-log   -- attached


Usage
----------

Use tmux-agent as following steps.

1.  Prepare your initial action file. See [File Format](#file-format) and [Samples](./init-action-files.sample) for reference.

2.  Locate the file in `~/.tmux-agent/`.

3.  Execute `tmux-agent <file>` (If you use ${argv}, execute `tmux-agent <file> [arguments ..]`)

4.  Do the initial actions fulfill your expectation?
    
    If you are not satisfied, please modify the initial action file.
    <commit_msg>Modify some descriptions.<commit_after>tmux-agent - tmux initial action agent
==========

- [Background](#background)
- [Overview](#overview)
- [Installation](#installation)
- [Zsh completion enhancement](#zsh-completion-enhancement)
- [Usage](#usage)
- [Additional Functions](#additional-functions)
- [File Format](#file-format)
    - [Keys](#keys)
    - [Variables](#variables)
    - [Comment](#comment)
    - [Indentation](#indentation)
    - [Blank line](#blank-line)
- [Sample Initial Action Files](#sample-initial-action-files)
- [Test Environment](#test-environment)

Background
----------

tmux is a very useful multifunctional terminal multiplexer.
I use tmux habitually, and like tmux's behavior basically. 
But initial actions that are creations of windows/panes, layouts sets, movements between directories, ssh to remote servers and so on become troublesome as tmux is used for various works.

A simple solution of that is coding scripts with tmux commands. However the coding is troublesome, too.

The tmux-agent loads simple format files that present initial actions, and acts according to the contents. It may make some tmux users more happy.

Overview
----------

tmux-agent is a simple bash script. It depends on bash, tmux, and basic Linux/BSD commands. 

A loaded file is comma separated format (key:value). Examples are as follows.

- Open 2 windows and ssh app1, app2 servers. Then hostname command on remote servers are executed.

        # file: app-ssh-windows
        session: app-ssh-windows
          window-command: ssh ${window}
          window-command: hostname
          window: app{1,2}

- Open 1 window and 3 panes. Then ssh web1 -- web3 servers. Then logs of the web servers are displayed by tail command. At last, the panes are synchronized.

        # file: web-log-sync-ssh-panes
        session: web-log-sync-ssh-panes
          pane-command: ssh ${pane}
          pane-command: tail -f /var/log/httpd/access_log
          pane-sync:
          pane: web{1..3}

- Target hosts are specified by command line arguments. And layout is set to "even-horizontal".

        # file: sync-ssh-panes
        session: ${file}_${id}_${argv}
          pane-command: ssh -l moya ${pane}
          pane-sync:
          pane-layout: even-horizontal
          pane: ${argv}

The files are expected to be located a certain directory (default: `~/.tmux-agent/`).

tmux-agent is used as follows. 

    $ tmux-agent app-ssh-windows

![app-ssh-windows Appearance Image](images/app-ssh-windows.png "app-ssh-windows Appearance Image")

    $ tmux-agent web-log-sync-ssh-panes

![web-log-sync-ssh-panes Appearance Image](images/web-log-sync-ssh-panes.png "web-log-sync-ssh-panes Appearance Image")

    $ tmux-agent sync-ssh-panes dev{1,2} stg

![sync-ssh-panes Appearance Image](images/sync-ssh-panes.png "sync-ssh-panes Appearance Image")

Installation
----------

Installation example is as follows.
In this example, tmux-agent is installed in `~/bin` (The directory is expected to be included in PATH environment variable)

    $ git clone git://github.com/mo-ya/tmux-agent.git

If git is not available in your system, download a zip file from https://github.com/mo-ya/tmux-agent and extract that.

    $ cd tmux-agent
    
    $ cp bin/tmux-agent.sh ~/bin/tmux-agent
    
    $ chmod 755 ~/bin/tmux-agent
    
    $ cp -r init-action-files.sample ~/.tmux-agent

Please test as follows.

    $ tmux-agent install-test

"install-test" session will start. Please check each window. (Messages may be displayed redundantly. That is not an elegant expression. But that is an expected behavior.)

If the checks pass, the installation is completed. 

If you use Zsh, the usability could be increaced more. Please read next section. There are the usage description and the detail of file format below that.

Zsh completion enhancement
----------

Please move the directory where tmux-agent is downloaded. Then, copy "zshrc.tmux" to your home directory.

    $ cp zsh.completion/zshrc.tmux ~/.zshrc.tmux

Then add a following description into ~/.zshrc under `autoload -U compinit ; compinit` description.

    ZSHRC=${HOME}/.zshrc.tmux
    [ -f ${ZSHRC} ] && source ${ZSHRC}

After .zshrc is reloaded, input tmux-agent &lt;TAB&gt;. As a result, initial action files (and attached/detached sessions) are complemented as follows.

    $ tmux-agent <TAB>

    multi-ssh-windows   -- init-action
    multi-ssh-windows0  -- attached
    multi-ssh-windows1  -- detached
    no-title            -- init-action
    no-title0           -- detached
    sync-ssh-panes      -- init-action
    tail-webservs-log   -- init-action
    tail-webservs-log   -- attached


Usage
----------

Use tmux-agent as following steps.

1.  Prepare your initial action file. See [File Format](#file-format) and [Samples](./init-action-files.sample) for reference.

2.  Locate the file in `~/.tmux-agent/`.

3.  Execute `tmux-agent <file>` (If you use ${argv}, execute `tmux-agent <file> [arguments ..]`)

4.  Do the initial actions fulfill your expectation?
    
    If you are not satisfied, please modify the initial action file.
    
{'fraction_non_alphanumeric': 0.11408534176214935, 'fraction_numerical': 0.004543658632951403, 'mean_word_length': 2.959718420023465, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5225961', 'n_tokens_mistral': 3167, 'n_tokens_neox': 2967, 'n_words': 1067}