-
-
Save bombsimon/e09b6147dd747671ee6b785d7e44fafb to your computer and use it in GitHub Desktop.
Wrapper around `just` to help finding the right recipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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