RASH command line interface

Search interface

rash show

usage: rash show [-h] command_history_id [command_history_id ...]

Show detailed command history by its ID.

positional arguments:
  command_history_id  Integer ID of command history.

optional arguments:
  -h, --help          show this help message and exit

rash isearch

usage: rash isearch [-h] [--query QUERY] [--query-template QUERY_TEMPLATE]
                    [--caret CARET]
                    [base_query [base_query ...]]

Interactive history search that updated as you type.

The query for this program is the same as the one for
``rash search`` command.

You need percol_ to use this command.

_percol: https://github.com/mooz/percol

If you use zsh, you can setup a keybind like this to quickly
launch iserch and execute the result.::

  # Type `Ctrl-x r` to start isearch
  bindkey "^Xr" rash-zle-isearch

If you like command or you are not using zsh, you can add
something like the following in your rc file to start and
execute the chosen command.

  rash-isearch(){
    eval "$(rash isearch)"
  }

To pass long and complex query, give them after "--",
like this.::

  rash isearch -- \
    --cwd . \
    --exclude-pattern "*rash *" \
    --include-pattern "*test*" \
    --include-pattern "tox*" \
    --include-pattern "make *test*"

positional arguments:
  base_query            The part of query that is not shown in UI and is
                        impossible to rewrite in this session. Useful for
                        putting long and complex query. (default: None)

optional arguments:
  -h, --help            show this help message and exit
  --query QUERY, -q QUERY
                        default query (default: None)
  --query-template QUERY_TEMPLATE
                        Transform default query using Python string format.
                        (default: None)
  --caret CARET         caret position (default: None)

System setup interface

rash init

usage: rash init [-h] [--shell SHELL] [--no-daemon]
                 [--daemon-opt DAEMON_OPTIONS]
                 [--daemon-outfile DAEMON_OUTFILE]

Configure your shell.

Add the following line in your shell RC file and then you are
ready to go::

  eval $(rash init)

To check if your shell is supported, simply run::

  rash init --no-daemon

If you want to specify shell other than $SHELL, you can give
--shell option::

  eval $(rash init --shell zsh)

By default, this command also starts daemon in background to
automatically index shell history records.  To not start daemon,
use --no-daemon option like this::

  eval $(rash init --no-daemon)

To see the other methods to launch the daemon process, see
``rash daemon --help``.

optional arguments:
  -h, --help            show this help message and exit
  --shell SHELL         name of shell you are using. directory before the last
                        / is discarded. It defaults to $SHELL. (default:
                        /bin/bash)
  --no-daemon           Do not start daemon. By default, daemon is started if
                        there is no already running daemon. (default: False)
  --daemon-opt DAEMON_OPTIONS
                        Add options given to daemon. See "rash daemon --help"
                        for available options. It can be specified many times.
                        Note that --no-error is always passed to the daemon
                        command. (default: [])
  --daemon-outfile DAEMON_OUTFILE
                        Path to redirect STDOUT and STDERR of daemon process.
                        This is mostly for debugging. (default: /dev/null)

rash daemon

usage: rash daemon [-h] [--no-error] [--restart] [--record-path RECORD_PATH]
                   [--keep-json] [--check-duplicate] [--use-polling]
                   [--log-level {CRITICAL,ERROR,WARNING,INFO,DEBUG}]

Run RASH index daemon.

This daemon watches the directory ``~/.config/rash/data/record``
and translate the JSON files dumped by ``record`` command into
sqlite3 DB at ``~/.config/rash/data/db.sqlite``.

``rash init`` will start RASH automatically by default.
But there are alternative ways to start daemon.

If you want to organize background process in one place such
as supervisord_, it is good to add `--restart` option to force
stop other daemon process if you accidentally started it in
other place.  Here is an example of supervisord_ setup::

  [program:rash-daemon]
  command=rash daemon --restart

.. _supervisord: http://supervisord.org/

Alternatively, you can call ``rash index`` in cron job to
avoid using daemon.  It is useful if you want to use RASH
on NFS, as it looks like watchdog does not work on NFS.::

  # Refresh RASH DB every 10 minutes
  */10 * * * * rash index

optional arguments:
  -h, --help            show this help message and exit
  --no-error            Do nothing if a daemon is already running. (default:
                        False)
  --restart             Kill already running daemon process if exist.
                        (default: False)
  --record-path RECORD_PATH
                        specify the directory that has JSON records. (default:
                        None)
  --keep-json           Do not remove old JSON files. It turns on --check-
                        duplicate. (default: False)
  --check-duplicate     do not store already existing history in DB. (default:
                        False)
  --use-polling         Use polling instead of system specific notification.
                        This is useful, for example, when your $HOME is on NFS
                        where inotify does not work. (default: False)
  --log-level {CRITICAL,ERROR,WARNING,INFO,DEBUG}
                        logging level. (default: None)

rash locate

usage: rash locate [-h] [--no-newline] [--output OUTPUT]
                   {base,config,db,daemon_pid,daemon_log}

Print location of RASH related file.

positional arguments:
  {base,config,db,daemon_pid,daemon_log}
                        Name of file to show the path (e.g., config).

optional arguments:
  -h, --help            show this help message and exit
  --no-newline, -n      do not output the trailing newline. (default: False)
  --output OUTPUT       Output file to write the results in. Default is
                        stdout. (default: -)

rash version

usage: rash version [-h]

Print version number.

optional arguments:
  -h, --help  show this help message and exit

Low level commands

rash record

usage: rash record [-h] [--record-type {command,init,exit}]
                   [--command COMMAND] [--cwd CWD] [--exit-code EXIT_CODE]
                   [--pipestatus PIPESTATUS [PIPESTATUS ...]] [--start START]
                   [--stop STOP] [--session-id SESSION_ID]
                   [--print-session-id]

Record shell history.

optional arguments:
  -h, --help            show this help message and exit
  --record-type {command,init,exit}
                        type of record to store. (default: command)
  --command COMMAND     command that was ran. (default: None)
  --cwd CWD             Like $PWD, but callee can set it to consider command
                        that changes directory (e.g., cd). (default: None)
  --exit-code EXIT_CODE
                        exit code $? of the command. (default: None)
  --pipestatus PIPESTATUS [PIPESTATUS ...]
                        $pipestatus (zsh) / $PIPESTATUS (bash) (default: None)
  --start START         the time COMMAND is started. (default: None)
  --stop STOP           the time COMMAND is finished. (default: None)
  --session-id SESSION_ID
                        RASH session ID generated by --print-session-id. This
                        option should be used with `command` or `exit`
                        RECORD_TYPE. (default: None)
  --print-session-id    print generated session ID to stdout. This option
                        should be used with `init` RECORD_TYPE. (default:
                        False)

rash index

usage: rash index [-h] [--keep-json] [--check-duplicate] [record_path]

Convert raw JSON records into sqlite3 DB.

Normally RASH launches a daemon that takes care of indexing.
See ``rash daemon --help``.

positional arguments:
  record_path        specify the directory that has JSON records. (default:
                     None)

optional arguments:
  -h, --help         show this help message and exit
  --keep-json        Do not remove old JSON files. It turns on --check-
                     duplicate. (default: False)
  --check-duplicate  do not store already existing history in DB. (default:
                     False)

ZSH functions

rash-zle-isearch

To setup Ctrl-x r to start rash isearch, add this to your .zshrc:

bindkey "^Xr" rash-zle-isearch