diff --git a/app/bin/just/.gitignore b/app/bin/just/.gitignore new file mode 100644 index 0000000..ceddaa3 --- /dev/null +++ b/app/bin/just/.gitignore @@ -0,0 +1 @@ +.cache/ diff --git a/app/bin/just/choose.sh b/app/bin/just/choose.sh index eec0dad..29738a3 100755 --- a/app/bin/just/choose.sh +++ b/app/bin/just/choose.sh @@ -9,9 +9,9 @@ function preview() { 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 + hash_highlight "$(just_wrapper --list $recipe)" "conf" else - just_wrapper --show $recipe | highlight --out-format xterm256 --syntax sh + hash_highlight "$(just_wrapper --show $recipe)" "sh" fi } @@ -33,7 +33,19 @@ function choose_truncate() { function choose_list() { just_wrapper -l --no-aliases --list-heading="" | awk '{$1=$1};1' } - +function hash_highlight() { + cache_dir="$(dirname ${BASH_SOURCE[0]})/.cache" + hash=$(echo $1 | md5sum | cut -d ' ' -f1) + file="$cache_dir/$hash" + if [[ -e $file ]]; then + cat $file + else + mkdir -p $cache_dir + data=$(printf "$1" | highlight --out-format xterm256 --syntax "$2") + printf "$data" + printf "$data" > $file + fi +} case "$action" in *choose) choose;; *preview) preview;;