No new posts available
dpc's avatar
(Professional)1d#

My latest Unix tooling abuse/creation.

I’m defining a alias command for Jujutsu:

parent-add = ["util", "exec", "--", "bash", "-c", '''
set -euo pipefail

source <(
nix run nixpkgs#argc -- --argc-eval /dev/stdin "$@" << EOF
# @option -r=@     Commit to modify
# @option -d       Parent to add
# @arg parent      Parent to add (positional version)
EOF
)

commit=${argc_r}
new_parent=${argc_d:-${argc_parent:-}}

if [ -z ${commit:-} ]; then
  >&2 echo "Must provide a commit to rebase"
  exit 1
fi

if [ -z ${new_parent:-} ]; then
  >&2 echo "Must provide a new parent"
  exit 1
fi

jj rebase -s "${commit}" -d "${commit}-" -d "${new_parent}"
''', ""]

which is like an shell script wrapped in a toml config file. Since the alias is executed as bash -c <...> it does not have an usable $0. So I’m using a heredoc passed via /dev/stdin 🤷 .

This works:

> jj parent-remove -h
USAGE: stdin [OPTIONS] [PARENT]

ARGS:
  [PARENT]  Parent to remove (positional version)

OPTIONS:
  -r <R>         Commit to modify [default: @]
  -d <D>         Parent to remove
  -h,  -help     Print help
  -V,  -version  Print version