From 483da4574994aa7efc8f7b6b1831e31ced708348 Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Tue, 26 Jul 2022 11:01:11 -0400 Subject: [PATCH] refactor: demo.sh clean up --- README.md | 2 ++ examples/demo.sh | 62 +++++++++++------------------------------------- 2 files changed, 16 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 13524e0..4ea0b48 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ A tool for building glamorous shell scripts. Shell running the ./demo.sh script +The above example is running from a single shell script ([view source](./examples/demo.sh)). + ## Tutorial Gum provides highly configurable, ready-to-use utilities to help you write diff --git a/examples/demo.sh b/examples/demo.sh index 577ae56..9a7c3ca 100755 --- a/examples/demo.sh +++ b/examples/demo.sh @@ -1,75 +1,41 @@ #!/bin/bash -gum style --border normal \ - --margin "1" \ - --padding "1 2" \ - --border-foreground 212 \ - "Hello, there! Welcome to $(gum style --foreground 212 'Gum')." - +gum style --border normal --margin "1" --padding "1 2" --border-foreground 212 "Hello, there! Welcome to $(gum style --foreground 212 'Gum')." NAME=$(gum input --placeholder "What is your name?") echo -e "Well, it is nice to meet you, $(gum style --foreground 212 "$NAME")." -sleep 2 - -clear +sleep 2; clear echo -e "Can you tell me a $(gum style --italic --foreground 99 'secret')?\n" gum write --placeholder "I'll keep it to myself, I promise!" > /dev/null # we keep the secret to ourselves -clear +clear; echo "What should I do with this information?"; sleep 1 -echo "What should I do with this information?" - -sleep 1 - -READ="Read" -THINK="Think" -DISCARD="Discard" +READ="Read"; THINK="Think"; DISCARD="Discard" ACTIONS=$(gum choose --cursor-prefix "[ ] " --selected-prefix "[✓] " --no-limit "$READ" "$THINK" "$DISCARD") -clear +clear; echo "One moment, please." -echo "One moment, please." +grep -q "$READ" <<< "$ACTIONS" && gum spin -s line --title "Reading the secret..." -- sleep 1 +grep -q "$THINK" <<< "$ACTIONS" && gum spin -s pulse --title "Thinking about your secret..." -- sleep 1 +grep -q "$DISCARD" <<< "$ACTIONS" && gum spin -s monkey --title " Discarding your secret..." -- sleep 2 -if grep -q "$READ" <<< "$ACTIONS"; then - gum spin -s line --title "Reading the secret..." -- sleep 1 -fi - -if grep -q "$THINK" <<< "$ACTIONS"; then - gum spin -s pulse --title "Thinking about your secret..." -- sleep 1 -fi - -if grep -q "$DISCARD" <<< "$ACTIONS"; then - gum spin -s monkey --title " Discarding your secret..." -- sleep 2 -fi - -sleep 1 - -clear +sleep 1; clear echo "What's your favorite $(gum style --foreground 212 "Gum") flavor?" - GUM=$(echo -e "Cherry\nGrape\nLime\nOrange" | gum filter) - echo "I'll keep that in mind!" -sleep 1 - -clear +sleep 1; clear echo "Do you like $(gum style --foreground "#04B575" "Bubble Gum?")" - sleep 1 CHOICE=$(gum choose --item.foreground 250 "Yes" "No" "It's complicated") -if [ "$CHOICE" == "Yes" ]; then - echo "I thought so, $(gum style --bold "Bubble Gum") is the best." -else - echo "I'm sorry to hear that." -fi +[[ "$CHOICE" == "Yes" ]] && echo "I thought so, $(gum style --bold "Bubble Gum") is the best." || echo "I'm sorry to hear that." sleep 1 @@ -77,6 +43,6 @@ gum spin --title "Chewing some $(gum style --foreground "#04B575" "$GUM") bubble clear -gum join --horizontal \ - "$(gum style --height 5 --width 25 --padding '1 3' --border double --border-foreground 57 "Well, it was nice meeting you, $(gum style --foreground 212 "$NAME"). Hope to see you soon!")" \ - "$(gum style --width 25 --padding '1 3' --border double --border-foreground 212 "Don't forget to chew some $(gum style --foreground "#04B575" "$GUM") bubble gum.")" +NICE_MEETING_YOU=$(gum style --height 5 --width 25 --padding '1 3' --border double --border-foreground 57 "Well, it was nice meeting you, $(gum style --foreground 212 "$NAME"). Hope to see you soon!") +CHEW_BUBBLE_GUM=$(gum style --width 25 --padding '1 3' --border double --border-foreground 212 "Don't forget to chew some $(gum style --foreground "#04B575" "$GUM") bubble gum.") +gum join --horizontal "$NICE_MEETING_YOU" "$CHEW_BUBBLE_GUM"