Website/app/bin/just/choose.sh
Snoweuph 37a63c29cc
Some checks failed
Quality Check / Check (push) Failing after 3s
#1: Restructure
2024-07-13 12:30:13 +02:00

43 lines
1 KiB
Bash
Executable file

#!/bin/bash
justfile=$1
action=$2
content=$3
function preview() {
source "$(dirname ${BASH_SOURCE[0]})/colors.sh"
recipe=$(choose_truncate $content)
if [[ -z "$recipe" ]] || echo $recipe | grep -q "^\["; then
printf "${RED_FG}Select this to Exit${CLEAR}"
elif [[ "$content" == *" ..." ]]; then
just_wrapper --list $recipe | highlight --out-format xterm256 --syntax conf
else
just_wrapper --show $recipe | highlight --out-format xterm256 --syntax sh
fi
}
function choose() {
script_path="$(pwd)/${BASH_SOURCE[0]}"
choice=$( choose_truncate $(choose_list | fzf --tac --cycle --preview "$script_path $justfile preview {}" ))
if [[ -z "$choice" ]] || echo $choice | grep -q "^\["; then
exit
else
just_wrapper $choice
fi
}
function just_wrapper() {
just --justfile $justfile $@
}
function choose_truncate() {
echo $1 | cut -d ' ' -f1
}
function choose_list() {
just_wrapper -l --no-aliases --list-heading="" | awk '{$1=$1};1'
}
case "$action" in
*choose) choose;;
*preview) preview;;
esac