もた日記

くだらないことを真面目にやる

ライブデモをサポートするdoitliveを試してみる

doitlive

github.com

doitliveというライブデモをサポートするツールがあったので試してみる。 コマンドを記述したファイルを読み込み、適当にキーボードを打つとあたかも正しくタイプしているかのようにコマンドが入力されていくようだ(自動で入力されていくわけではない)。

f:id:wonder-wall:20171011214004g:plain


インストール

pipでインストールできるので下記コマンドを実行。

$ pip install doitlive

macOSならHomebrewでインストールできる。

$ brew update
$ brew install doitlive

ヘルプメッセージ

$ doitlive --version
doitlive, version 2.8.0
$ doitlive --help
Usage: doitlive [OPTIONS] COMMAND [ARGS]...

  doitlive: A tool for "live" presentations in the terminal

  Basic:
      1. Create a file called session.sh. Fill it with bash commands.
      2. Run "doitlive play session.sh".
      3. Type like a madman.

  Press Ctrl-C at any time to exit a session. To see a demo session, run
  "doitlive demo".

  You can use --help to get help with subcommands.

  Example: doitlive play --help

Options:
  -v, --version  Show the version and exit.
  -h, --help     Show this message and exit.

Commands:
  demo    Run a demo doitlive session.
  play    Play a session file.
  record  Record a session file.
  themes  Preview the available prompt themes.


使い方

基本

使い方の流れは以下の通り。

  1. コマンドを記述したsession.shを作成(実際はファイル名は適当でよい)
  2. doitlive play session.shを実行
  3. 適当にキーボードを叩きまくる

まずはデモを試してみる。

$ doitlive demo

doitliveが起動した状態で適当にキーボードを打つと、あたかも正しくタイプしているようにコマンドが入力されていく。echo "Greetings"のように最後まで入力した後はリターンキーを押すと次の命令に進む。

f:id:wonder-wall:20171011203440g:plain

デモと同じ内容をファイルに記述して実行する場合は、下記コマンドを記述したsession.shファイルを作成。

echo "Greetings"
echo "This is just a demo session"
echo "For more info, check out the home page..."
echo "http://doitlive.readthdocs.io"

そしてplayコマンドを実行する。

$ doitlive play session.sh


オプション

サブコマンドのヘルプで指定可能なオプションが確認できる。

$ doitlive play --help
Usage: doitlive play [OPTIONS] SESSION_FILE

  Play a session file.

Options:
  -e, --commentecho            Echo non-magic comments.
  -p, --prompt <prompt_theme>  Prompt theme.  [default: default]
  -s, --speed <int>            Typing speed.  [default: 1]
  -S, --shell <shell>          The shell to use.  [default: /bin/bash]
  -q, --quiet                  Suppress startup message.
  -h, --help                   Show this message and exit.

-pでテーマを指定できる(図は-p sorin)。利用可能なテーマはdoitlive themesで確認可能。

f:id:wonder-wall:20171011205425p:plain

-sでタイピングスピードを指定できる。デフォルトではキーボードを1回打つと1文字ずつ入力されるが、-s 3のようにすれば1回打つと3文字入力されるようになる。

$ doitlive play session.sh -s 3

--shellを指定すればZshなども使えるようだ。

$ doitlive play session.sh --shell /bin/zsh


recordコマンド

recordコマンドを使うと操作した結果をsession.shファイルに記録することができる。

$ doitlive record --help
Usage: doitlive record [OPTIONS] [SESSION_FILE]

  Record a session file. If no argument is passed, commands are written to
  ./session.sh.

  When you are finished recording, run the "stop" command.

Options:
  -e, --envvar <envvar>        Adds a session variable.
  -a, --alias <alias>          Add a session alias.
  -p, --prompt <prompt_theme>  Prompt theme.  [default: default]
  -S, --shell <shell>          The shell to use.  [default: /bin/bash]
  -h, --help                   Show this message and exit.

doitlive recordを実行するとまず説明が表示される。

f:id:wonder-wall:20171011212246p:plain

その後、コマンドを実行してstopで終了する。

f:id:wonder-wall:20171011212548p:plain

実際に記録されたファイルは下記。

# Recorded with the doitlive recorder
#doitlive shell: /bin/bash
#doitlive prompt: default

echo "test"

pwd

date


Pythonコンソール

Pythonコンソールもサポートしており```pythonでPythonコンソールに入れる。```ipythonとすればIPythonもできるようだ。

    echo "And now for something completely different"

    ```python
    list = [2, 4, 6, 8]
    sum = 0
    for num in list:
        sum = sum + num

    print("The sum is: {sum}".format(sum=sum))
    ```

f:id:wonder-wall:20171011211348p:plain