ライブデモをサポートするdoitliveを試してみる
doitlive
doitliveというライブデモをサポートするツールがあったので試してみる。 コマンドを記述したファイルを読み込み、適当にキーボードを打つとあたかも正しくタイプしているかのようにコマンドが入力されていくようだ(自動で入力されていくわけではない)。
インストール
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.
使い方
基本
使い方の流れは以下の通り。
- コマンドを記述した
session.sh
を作成(実際はファイル名は適当でよい) doitlive play session.sh
を実行- 適当にキーボードを叩きまくる
まずはデモを試してみる。
$ doitlive demo
doitlive
が起動した状態で適当にキーボードを打つと、あたかも正しくタイプしているようにコマンドが入力されていく。echo "Greetings"
のように最後まで入力した後はリターンキーを押すと次の命令に進む。
デモと同じ内容をファイルに記述して実行する場合は、下記コマンドを記述した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
で確認可能。
-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
を実行するとまず説明が表示される。
その後、コマンドを実行してstop
で終了する。
実際に記録されたファイルは下記。
# 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)) ```