Skip to content

コマンドランナー just

Published: at 23:00

今年からアサインされたプロジェクトで,Makefileをタスクランナーとして使っていた。 Makefileなんて円がなかったからCとかのビルドコマンドを書いたもの。程度の認識しかなかったし, ここで初めてタスクランナーというものをしった。
かっこいいじゃん。使ってみようと思って調べるといくつの種類が出回っているようだ

最近個人的にRustを勉強しているのもあるのでJustを使ってみよう。

インストール

大体のlinuxディストロでは普通にパッケージインストールできると思う。

sudo apt install just

とかで。

2025/04時点でUbuntu 24.04.2 LTSでは1.21.0がインストールされた。 この段階でのgithubの公式リポジトリでは1.40.0が最新だった。後述するが1.21.0はおすすめしない。

使い方

justfileを任意の場所に配置。 このとき

コマンドサンプルは

# just実行時に何も指定しないときに実行されるデフォルト
default:
  @just -l

# リポジトリのフェッチ
fetch-repo-all:
    @echo "fetching foo"
    git -C ~/repo/projects/foo fetch --prune
    @echo "fetching bar"
    git -C ~/repo/projects/bar fetch --prune
    echo "fetch complete !!"

# docker ps を完結に
dp:
  @docker ps --format 'table {{ "{{.Names}}" }}\t{{ "{{.Status}}" }}\t{{ "{{.Ports}}" }}'

# docker ps -a を完結に
dpa:
  @docker ps -a --format 'table {{ "{{.Names}}" }}\t{{ "{{.Status}}" }}\t{{ "{{.Ports}}" }}'


# 変数使用のサンプル
create-log date:
	echo "📝 Creating log file for {{date}}"
	@touch "log_{{date}}.txt"

# 引数付きレシピ
greet name:
  echo "Hello, {{name}}!"

# 他のレシピを内部で呼び出す(引数を渡す)
greet-today name:
  just greet {{name}}
  echo "Hope you have a great day, {{name}}!"

justを引数なしで実行するとjustfile中の一番上のコマンドが実行される。 ただしdefaultコマンドを設定していると引数未指定の場合はそれが実行される。 事故るとやなのでdefaultjust -lコマンドの一覧を呼ぶコマンドを設定している。

justの実行結果は

$ just
Available recipes:
    create-log date  # 変数使用のサンプル
    default          # just実行時に何も指定しないときに実行されるデフォルト
    dp               # docker ps を完結に
    dpa              # docker ps -a を完結に
    fetch-repo-all   # リポジトリのフェッチ
    greet name       # 引数付きレシピ
    greet-today name # 他のレシピを内部で呼び出す(引数を渡す)

のようになる。

dp,dpaのように{{}}がある場合はエスケープする必要がある。 {{}}は変数展開に使用されるので。

あとは変数や, コマンドからコマンドを呼ぶときは上記のサンプルのような形で呼ぶ。

注意

記事執筆現在aptでインストールされるのは1.21.0であるが, このバージョン付近にはなぜかグローバルファイルを参照するオプション-gが無い。

just --help 
just 1.21.0
- Please see https://github.com/casey/just for more information.

USAGE:
    just [FLAGS] [OPTIONS] [--] [ARGUMENTS]...

FLAGS:
        --changelog           Print changelog
        --check               Run `--fmt` in 'check' mode. Exits with 0 if justfile is formatted correctly. Exits with 1 and
                              prints a diff if formatting is required.
        --choose              Select one or more recipes to run using a binary chooser. If `--chooser` is not passed the
                              chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`
        --clear-shell-args    Clear shell arguments
    -n, --dry-run             Print what just would do without doing it
        --dump                Print justfile
    -e, --edit                Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`
        --evaluate            Evaluate and print all variables. If a variable name is given as an argument, only print that
                              variable's value.
        --fmt                 Format and overwrite justfile
        --highlight           Highlight echoed recipe lines in bold
        --init                Initialize new justfile in project root
    -l, --list                List available recipes and their arguments
        --no-dotenv           Don't load `.env` file
        --no-highlight        Don't highlight echoed recipe lines in bold
    -q, --quiet               Suppress all output
        --shell-command       Invoke <COMMAND> with the shell used to run recipe lines and backticks
        --summary             List names of available recipes
    -u, --unsorted            Return list and summary entries in source order
        --unstable            Enable unstable features
        --variables           List names of variables
    -v, --verbose             Use verbose output
        --yes                 Automatically confirm all recipes.
    -h, --help                Print help information
    -V, --version             Print version information

OPTIONS:
        --chooser <CHOOSER>                        Override binary invoked by `--choose`
        --color <COLOR>
            Print colorful output [default: auto]  [possible values: auto, always, never]

    -c, --command <COMMAND>
            Run an arbitrary command with the working directory, `.env`, overrides, and exports set

        --command-color <COMMAND-COLOR>
            Echo recipe lines in <COMMAND-COLOR> [possible values: black, blue, cyan, green, purple, red, yellow]

        --completions <SHELL>
            Print shell completion script for <SHELL> [possible values: zsh, bash, fish, powershell, elvish]

        --dotenv-filename <DOTENV-FILENAME>        Search for environment file named <DOTENV-FILENAME> instead of `.env`
        --dotenv-path <DOTENV-PATH>                Load environment file at <DOTENV-PATH> instead of searching for one
        --dump-format <FORMAT>
            Dump justfile as <FORMAT> [default: just]  [possible values: just, json]

    -f, --justfile <JUSTFILE>                      Use <JUSTFILE> as justfile
        --list-heading <TEXT>                      Print <TEXT> before list
        --list-prefix <TEXT>                       Print <TEXT> before each list item
        --set <VARIABLE> <VALUE>                   Override <VARIABLE> with <VALUE>
        --shell <SHELL>                            Invoke <SHELL> to run recipes
        --shell-arg <SHELL-ARG>...                 Invoke shell with <SHELL-ARG> as an argument
    -s, --show <RECIPE>                            Show information about <RECIPE>
    -d, --working-directory <WORKING-DIRECTORY>    Use <WORKING-DIRECTORY> as working directory. --justfile must also be set

ARGS:
    <ARGUMENTS>...    Overrides and recipe(s) to run, defaulting to the first recipe in the justfile

これより古い1.16.0とか新しい1.40.0とかだとある。 どこで消えてどこで復活しているのかは調べてないからわからない。

just 1.40.0だと

🤖 Just a command runner - https://github.com/casey/just

Usage: just [OPTIONS] [ARGUMENTS]...

Arguments:
  [ARGUMENTS]...  Overrides and recipe(s) to run, defaulting to the first recipe in the justfile

Options:
      --alias-style <ALIAS_STYLE>              Set list command alias display style [env: JUST_ALIAS_STYLE=] [default: right]
                                               [possible values: left, right, separate]
      --check                                  Run `--fmt` in 'check' mode. Exits with 0 if justfile is formatted correctly.
                                               Exits with 1 and prints a diff if formatting is required.
      --chooser <CHOOSER>                      Override binary invoked by `--choose` [env: JUST_CHOOSER=]
      --clear-shell-args                       Clear shell arguments
      --color <COLOR>                          Print colorful output [env: JUST_COLOR=] [default: auto] [possible values:
                                               always, auto, never]
      --command-color <COMMAND-COLOR>          Echo recipe lines in <COMMAND-COLOR> [env: JUST_COMMAND_COLOR=] [possible
                                               values: black, blue, cyan, green, purple, red, yellow]
      --dotenv-filename <DOTENV-FILENAME>      Search for environment file named <DOTENV-FILENAME> instead of `.env`
  -E, --dotenv-path <DOTENV-PATH>              Load <DOTENV-PATH> as environment file instead of searching for one
  -n, --dry-run                                Print what just would do without doing it [env: JUST_DRY_RUN=]
      --dump-format <FORMAT>                   Dump justfile as <FORMAT> [env: JUST_DUMP_FORMAT=] [default: just] [possible
                                               values: json, just]
      --explain                                Print recipe doc comment before running it [env: JUST_EXPLAIN=]
  -g, --global-justfile                        Use global justfile
      --highlight                              Highlight echoed recipe lines in bold [env: JUST_HIGHLIGHT=]
  -f, --justfile <JUSTFILE>                    Use <JUSTFILE> as justfile [env: JUST_JUSTFILE=]
      --list-heading <TEXT>                    Print <TEXT> before list [env: JUST_LIST_HEADING=] [default: "Available
                                               recipes:\n"]
      --list-prefix <TEXT>                     Print <TEXT> before each list item [env: JUST_LIST_PREFIX=] [default: "    "]
      --list-submodules                        List recipes in submodules [env: JUST_LIST_SUBMODULES=]
      --no-aliases                             Don't show aliases in list [env: JUST_NO_ALIASES=]
      --no-deps                                Don't run recipe dependencies [env: JUST_NO_DEPS=]
      --no-dotenv                              Don't load `.env` file [env: JUST_NO_DOTENV=]
      --no-highlight                           Don't highlight echoed recipe lines in bold [env: JUST_NO_HIGHLIGHT=]
      --one                                    Forbid multiple recipes from being invoked on the command line [env: JUST_ONE=]
  -q, --quiet                                  Suppress all output [env: JUST_QUIET=]
      --allow-missing                          Ignore missing recipe and module errors [env: JUST_ALLOW_MISSING=]
      --set <VARIABLE> <VALUE>                 Override <VARIABLE> with <VALUE>
      --shell <SHELL>                          Invoke <SHELL> to run recipes
      --shell-arg <SHELL-ARG>                  Invoke shell with <SHELL-ARG> as an argument
      --shell-command                          Invoke <COMMAND> with the shell used to run recipe lines and backticks
      --timestamp                              Print recipe command timestamps [env: JUST_TIMESTAMP=]
      --timestamp-format <TIMESTAMP-FORMAT>    Timestamp format string [env: JUST_TIMESTAMP_FORMAT=] [default: %H:%M:%S]
  -u, --unsorted                               Return list and summary entries in source order [env: JUST_UNSORTED=]
      --unstable                               Enable unstable features [env: JUST_UNSTABLE=]
  -v, --verbose...                             Use verbose output [env: JUST_VERBOSE=]
  -d, --working-directory <WORKING-DIRECTORY>  Use <WORKING-DIRECTORY> as working directory. --justfile must also be set [env:
                                               JUST_WORKING_DIRECTORY=]
      --yes                                    Automatically confirm all recipes. [env: JUST_YES=]
  -h, --help                                   Print help
  -V, --version                                Print version

Commands:
      --changelog             Print changelog
      --choose                Select one or more recipes to run using a binary chooser. If `--chooser` is not passed the
                              chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`
  -c, --command <COMMAND>...  Run an arbitrary command with the working directory, `.env`, overrides, and exports set
      --completions <SHELL>   Print shell completion script for <SHELL> [possible values: bash, elvish, fish, nushell,
                              powershell, zsh]
      --dump                  Print justfile
  -e, --edit                  Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`
      --evaluate              Evaluate and print all variables. If a variable name is given as an argument, only print that
                              variable's value.
      --fmt                   Format and overwrite justfile
      --groups                List recipe groups
      --init                  Initialize new justfile in project root
  -l, --list [<MODULE>...]    List available recipes in <MODULE> or root if omitted
      --man                   Print man page
  -s, --show <PATH>...        Show recipe at <PATH>
      --summary               List names of available recipes
      --variables             List names of variables

となっていて-g, --global-justfileオプションが存在している。 いれるなら個人的には-gオプションがあるバージョンのほうがいいと思う。