---
title: "ターミナルがダサいとモテない。bash command-line framework rerun編 | grasys blog"
url: "https://blog.grasys.io/post/yusukeh/terminal-rerun/"
description: "bashのmodule型command-line framework rerun Photo by Alejandro Escamilla on Unsplash 恵比寿でIT企業をやっているとモテると聞いて創業しましたが早いことありがたいことに10年目に突入した長谷川です。 まだモテる成果は出ていません、、、これか…"
---

# ターミナルがダサいとモテない。bash command-line framework rerun編

-   ![](/_astro/noicon.CTHOhNiB_1HMs6A.webp)[yusukeh](/authors/yusukeh/)
-   公開日：2025年10月15日
-   カテゴリー：[Tech](/categories/tech/)
-   タグ：[#Rerun](/tags/rerun/)[#シリーズ: ターミナル環境](/tags/シリーズ-ターミナル環境/)

![ターミナルがダサいとモテない。bash command-line framework rerun編](/_astro/ogp.BwAlVjyH_2tJOjr.webp)

bashのmodule型command-line framework rerun

![ターミナルがダサいとモテない。bash command-line framework rerun編](/_astro/01-0-Dp-ytdkAFtL-vvIw-659f9000.C-baccSa_Z1k7BJy.webp)

Photo by [Alejandro Escamilla](https://unsplash.com/@alejandroescamilla?utm_source=medium&utm_medium=referral) on [Unsplash](https://unsplash.com/?utm_source=medium&utm_medium=referral)

恵比寿でIT企業をやっているとモテると聞いて創業しましたが早いことありがたいことに10年目に突入した長谷川です。

まだモテる成果は出ていません、、、これからです！（もうめんどくさいのでカウントやめました😆）

もともと[argc](https://github.com/sigoden/argc)を書いていたのですが、[rerun](https://rerun.github.io/rerun/)を書いていて長くなりすぎるので分割しました😅

## rerun

[](https://rerun.github.io/rerun/?source=post_page-----def30cfa7dd0---------------------------------------)[rerun](https://rerun.github.io/rerun/?source=post_page-----def30cfa7dd0---------------------------------------)

> rerun — Take your shell scripts and turn them into powerful full featured management utilities with no extra programming.

と書かれているようにめちゃくちゃパワフルです。

ModuleとCommandに分かれているため、独立した形でModuleを作れば、配布することもできます。

RERUN\_MODULE\_DIRで設定したDirectoryをModuleを読み込み利用できるようにすることができます。

InstallとSetupはこちらをみてください。[](https://github.com/rerun/rerun/wiki/Installation?source=post_page-----def30cfa7dd0---------------------------------------)

[Installation](https://github.com/rerun/rerun/wiki/Installation?source=post_page-----def30cfa7dd0---------------------------------------)

![rerunの画面（1）](/_astro/02-1-iITAdX51p_X-DI-zmjfIig-e24b8179.BRxvQ6QA_Z11RHC9.webp)

これは実際の自分のrerun modulesです。

![rerunの画面（2）](/_astro/03-1-6fx6KQMb-rWFtabnNMxKEA-e97cc168.0Xwz3wiy_3y7ar.webp)

以下のようなtreeで保存していて、macの構成や何か良くする作業などのcommandをまとめています。

例えばmodule installの中はこのようになっています。

![rerunの画面（3）](/_astro/04-1-m2TwIYQYFWxKibl2hY76mg-6468bace.DqfACmwR_1wazN9.webp)

最近ではpyenvは使わなくなったし、ryeもuvに移行したので使わなくなりました。  
極稀にですが、InstallされたあとのDirecoryを綺麗にしたくなる衝動に駆られるため、Install用のcommandをまとめています。

## Get yusuke’s stories in your inbox

Join Medium for free to get updates from this writer.Subscribe

例えばmodule weztermの中にはunsplashというコマンドがあります。

![Get yusuke’s stories in your inboxの画面](/_astro/05-1-BffpN_zYWmLBcC1oKW5GEw-f9f95ab1.BXxRlmCW_17w40s.webp)

weztermの背景をunsplashのAPIで変えるためのコマンドです。

## rerun wezterm: unsplash

このscriptは内容も軽いので今回はこれを紹介します。

## stubb: add-module

rerunにはstubというhelper moduleがあります。[](https://github.com/rerun/rerun/tree/master/modules/stubbs?source=post_page-----def30cfa7dd0---------------------------------------)

[rerun/modules/stubbs at master · rerun/rerun](https://github.com/rerun/rerun/tree/master/modules/stubbs?source=post_page-----def30cfa7dd0---------------------------------------)

Plain textcontent\_copy

```
rerun stubbs:
 Available commands in module, "stubbs":
 add-command: "add command to module"
    --command|-c <  >: "the command name"
    --description <  >: "the brief description"
    --module|-m <  >: "the module name"
   [ --overwrite < false >]: "should overwrite?"
   [ --generate-help < true >]: "generate help usage option? (-?|--help)"
 add-module: "add a new module"
    --description <  >: "the brief description"
    --module|-m <  >: "the module name"
   [ --template <  >]: "the template name or path"
 add-option: "add a command option"
   [ --arg < true >]: "option takes argument?"
    --command|-c <  >: "the command name"
   [ --default|-d <  >]: "default value"
    --description <  >: "the brief description"
   [ --export < false >]: "export variable?"
   [ --long <  >]: "long option name"
    --module|-m <  >: "the module name"
    --option|-o <  >: "the option name"
   [ --required < false >]: "option required?"
   [ --short <  >]: "short option name"
 archive: "build an archive of rerun and modules"
   [ --file|-f <  >]: "file name"
   [ --format|-f < sh >]: "output format"
    --modules < "'*'" >: "modules glob pattern"
   [ --release < 1 >]: "the archive release number"
   [ --version < 1.0.0 >]: "the archive version number"
   [ --template <  >]: "the template name or path"
 docs: "generate the docs"
   [ --dir <  >]: "the directory path"
    --module|-m <  >: "the module name"
 edit: "edit a command script"
    --command|-c <  >: "the command name"
    --module|-m <  >: "the module name"
 migrate: "Migrate 0.9 modules to the 1.0 module format"
    --module|-m <  >: "the module name"
 rm-command: "remove a command"
    --command|-c <  >: "the command name"
    --module|-m <  >: "the module name"
 rm-option: "remove a command option"
    --command|-c <  >: "the command name"
    --module|-m <  >: "the module name"
    --option|-o <  >: "the option name"
 test: "run module test scripts"
   [ --answers <  >]: "option answer file"
    --module|-m <  >: "the module name"
   [ --plan|-p <  >]: "the test plan"
```

これを使ってModuleを作成します。

Plain textcontent\_copy

```
rerun stubbs: add-module --module wezterm --description "for wezterm"
```

これで空のmodule weztermができました。

## stubbs: add-command

Plain textcontent\_copy

```
rerun stubbs: add-command --module wezterm \
  --command unsplash \
  --description "Change the background of wezterm using the unsplash API"
```

そうすると${RERUN\_MODULE\_DIR}/wezterm/commands/unsplashに3個のファイルが生成されます。

-   metadata
    
-   options.sh
    
-   script
    

ここではscriptを使います。

Plain textcontent\_copy

```
vi ${RERUN_MODULE_DIR}/wezterm/commands/unsplash/script
```

以下の行の下に実際のscriptを書いていくイメージです。

Plain textcontent\_copy

```
# Command implementation
# ----------------------
xxxxxxxxx
xxxxxx
xxxxxx
```

Plain textcontent\_copy

```
# Command implementation
# ----------------------
declare -A unsplash=(
  # unsplash ramdom API
  ["url"]="https://api.unsplash.com/photos/random"
  # unsplash access key
  ["access_key"]="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  ["response_json"]="${HOME}/.config/wezterm/unsplash.json"
  # 実際のdownloadされるunsplashのが画像
  ["download_file"]="${HOME}/.config/wezterm/unsplash.jpg"
  # weztermのconfig directory
  ["cwd"]="${HOME}/.config/wezterm"
)
```

Plain textcontent\_copy

```
echo "request api: ${unsplash["url"]}?client_id=${unsplash["access_key"]}&query=${QUERY}"
echo "response json: ${unsplash["response_json"]}"
curl -s -o ${unsplash["response_json"]} \
  "${unsplash["url"]}?client_id=${unsplash["access_key"]}&query=${QUERY}"
declare image_url=$(cat ${unsplash["response_json"]} | jq -r .urls.full)
echo "image url: ${image_url}"
echo "download: ${unsplash["download_file"]}"
curl -s -o ${unsplash["download_file"]} ${image_url}
wezterm imgcat --height=50% ${unsplash["download_file"]}
```

## stubbs: add-option

rerunのcommandにはoptionを追加できます。

ここではunsplash APIの[query parameter](https://unsplash.com/documentation#get-a-random-photo)だけ可変できるようにしました。  
default値はgalaxyにしてます。

Plain textcontent\_copy

```
rerun stubbs: add-option \
  --module wezterm \
  --command unsplash \
  --arg true \
  --default galaxy \
  --export true \
  --required false \
  --long query \
  --option query \
  --short q \
  --description "unsplash API query parameter"
```

実際に実行すると・・・

![stubbs: add-optionの画面（1）](/_astro/06-1-kJ7sYlMrOoQuqvptIKdSIQ-dc618ee2.BBqyXHM3_HncBB.webp)

unsplash APIのaccess keyが入ってるので😎してます。

query optionにforestを入れると以下のようになります。

![stubbs: add-optionの画面（2）](/_astro/07-1-GXJzvpoWefGrBrrRbFVong-3af3fd84.BP5cub1m_Z1QWl3E.webp)

## wezterm config

あとは${HOME}/.config/wezterm/wezterm.luaに以下のような設定をいれればファイルを差し替えるだけで背景画像が変わります😁

Plain textcontent\_copy

```
-------------------------------------------------------------------------------
-- background
config.background = {
 {
  source = { File = wezterm.config_dir .. "/unsplash.jpg" },
  height = "Cover",
  --width = "Cover",
  hsb = {
   brightness = 0.3,
   hue = 0.2,
   saturation = 0.2,
  },
  opacity = 0.2,
 },
}
```

変える必要があるのかという野暮なツッコミは受けません🤣

[rerun](https://rerun.github.io/rerun/)はModule型になっているため、そのModuleだけを配布することで簡単に各種scriptを配布できるのがメリットです。

自分はmacosのセットアップやメンテナンス、会社で必要な確認コマンドなどをまとめて管理しています。

これらをmacosの入れ替えのタイミングなどでgit化しておけば、cloneするだけで一通りの作業を開始できる環境を構成できます。

昔はAppleのtimecupsuleが便利でtimemachineも使ってたけど、NASを配置しなきゃいけない、最近のmacbook proはSDカードスロットが無いなどでやめてしまいました。

新しいmacbook proはSDカードスロットが復活しましたね  
オレのはまだ旧型のmacbook pro 13inchなので😅  
新型に交換したらまた管理手法がちょっと変わるかもしれないです。

ターミナル環境について他の記事も書いているので、よろしければこちらもご覧ください！  
[『ターミナルがダサいとモテない』シリーズ一覧](https://blog.grasys.io/tags/series-terminal-update)

転載：[ターミナルがダサいとモテない。bash command-line framework rerun編](https://medium.com/@yusuke_h/%E3%82%BF%E3%83%BC%E3%83%9F%E3%83%8A%E3%83%AB%E3%81%8C%E3%83%80%E3%82%B5%E3%81%84%E3%81%A8%E3%83%A2%E3%83%86%E3%81%AA%E3%81%84-bash-command-line-framework-rerun%E7%B7%A8-def30cfa7dd0)

## この記事を書いた人

[![](/_astro/yusukeh.BvUd2yKE_1mQ6Fp.webp)](/authors/yusukeh/)

### [yusukeh](/authors/yusukeh/)

Fly high. Think deep. Move fast. Go far.🦅

-   [Medium](https://medium.com/@yusukeh "Medium")

[プロフィールと記事一覧](/authors/yusukeh/)