Skip to content

Instantly share code, notes, and snippets.

@bombsimon
Last active April 23, 2024 06:45
Show Gist options
  • Save bombsimon/e09b6147dd747671ee6b785d7e44fafb to your computer and use it in GitHub Desktop.
Save bombsimon/e09b6147dd747671ee6b785d7e44fafb to your computer and use it in GitHub Desktop.
Wrapper around `just` to help finding the right recipe
#!/usr/bin/env sh
set -eu
_get_user_input() {
editor=${EDITOR:-vi}
tempfile=$(mktemp)
echo "$@" > "$tempfile"
"$editor" "$tempfile"
args=$(cat "$tempfile")
rm "$tempfile"
}
available_justfiles=${JUSTFILES:-}
jf_flags=
if [ -n "$available_justfiles" ]; then
jf=$(echo "$available_justfiles" | tr ' ' '\n' | fzf)
jf_flags="--justfile=$jf/justfile"
fi
rule=$(just "$jf_flags" | awk 'NR>1 {gsub(/^ +/, ""); print}' | fzf)
args=$(echo "$rule" | awk -F'#' '{print $1}')
if [ "$(echo "$args" | awk '{print $2}')" != "" ]; then
_get_user_input "$args"
fi
# Let's `eval` the command to account for `$args` containing quoted values with
# spaces, f.ex. `some-recipe arg='value with spaces'`.
eval exec just "$*" "$jf_flags" "$args"
# vim: set ts=2 sw=2 et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment