diff --git a/Makefile b/Makefile index b1f4812..adf36b9 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,6 @@ OUT_DIR = dist OUTPUT = $(OUT_DIR)/beddu.sh SRC_DIR = src DEMO_DIR = demo -README = README.md YEAR = $(shell date +%Y) IP = $(shell curl -s ipinfo.io/ip) @@ -30,48 +29,35 @@ demo: build _release: @if [ -z "$(filter-out $@,$(MAKECMDGOALS))" ]; then \ - echo "❗User Error: Please specify a version number (e.g. make _release v0.0.5)"; \ + echo "Error: Please specify a version number (e.g. make release v0.0.5)"; \ exit 1; \ fi $(eval VERSION := $(filter-out $@,$(MAKECMDGOALS))) - @if [ "$$(git branch --show-current)" != "main" ]; then \ - echo "❗User Error: Releases can only be made from the main branch"; \ - exit 1; \ - fi @if ! git diff-index --quiet HEAD --; then \ - echo "❗User Error: Git working directory is not clean. Please commit or stash your changes first."; \ + echo "Error: Git working directory is not clean. Please commit or stash your changes first."; \ exit 1; \ fi; \ - $(MAKE) build - @echo "" - @sed -i '' "s/# Version: .*/# Version: $(VERSION)/" $(OUTPUT); \ - sed -i '' -E "s/v[0-9]+\.[0-9]+\.[0-9]+/$(VERSION)/" $(README) - @git add $(OUTPUT) $(README); \ + $(MAKE) build; \ + sed -i '' "s/# Version: .*/# Version: $(VERSION)/" $(OUTPUT); \ + git add $(OUTPUT); \ git commit -m "Release $(VERSION)"; \ git tag -a "$(VERSION)" -m "Release $(VERSION)" - @echo "" - @git push --follow-tags - @echo "" - @gh release create "$(VERSION)" --generate-notes --title "⚡ $(VERSION)" "$(OUTPUT)#beddu.sh" - @echo "\n\033[32m✔︎\033[0m Release complete: \033[32m$(VERSION)\033[0m" + @echo "\nRelease complete: \033[32m$(VERSION)\033[0m" # Get the last version tag and increment the appropriate part release-patch: - @echo "" @LAST_VERSION=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \ NEW_VERSION=$$(echo $$LAST_VERSION | awk -F. '{print $$1"."$$2"."$$3+1}'); \ echo "Bumping patch version from $$LAST_VERSION to $$NEW_VERSION"; \ $(MAKE) _release $$NEW_VERSION release-minor: - @echo "" @LAST_VERSION=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \ NEW_VERSION=$$(echo $$LAST_VERSION | awk -F. '{print $$1"."$$2+1".0"}'); \ echo "Bumping minor version from $$LAST_VERSION to $$NEW_VERSION"; \ $(MAKE) _release $$NEW_VERSION release-major: - @echo "" @LAST_VERSION=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \ NEW_VERSION=$$(echo $$LAST_VERSION | awk -F. '{print "v"$$2+1".0.0"}'); \ echo "Bumping major version from $$LAST_VERSION to $$NEW_VERSION"; \ @@ -81,7 +67,6 @@ release-major: @: $(OUTPUT): $(ALL_SRC_FILES) - @echo "" @mkdir -p $(OUT_DIR) @echo '#!/usr/bin/env bash' > $(OUTPUT) @echo '# shellcheck disable=all' >> $(OUTPUT) @@ -98,9 +83,8 @@ $(OUTPUT): $(ALL_SRC_FILES) grep -v '^\s*#\|^source \|^SCRIPT_DIR=\|^readonly BEDDU_.*_LOADED\|^\[\[ \$$BEDDU_.*_LOADED \]\]' "$$file" | sed '/^[[:space:]]*$$/d' | sed 's/#[a-zA-Z0-9 ]*$$//' >> $(OUTPUT); \ done @chmod +x $(OUTPUT) - @echo "\033[32m✔︎\033[0m Build complete: \033[32m$(OUTPUT)\033[0m" + @echo "\nBuild complete: \033[32m$(OUTPUT)\033[0m" clean: - @echo "" @rm -rf $(OUT_DIR) - @echo "\033[32m✔︎\033[0m Clean up completed." \ No newline at end of file + @echo "\nClean up completed." \ No newline at end of file diff --git a/README.md b/README.md index 9ce4972..facdb86 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Beddu 💅🏻 +# Beddu A lightweight bash framework for interactive scripts with pretty output. @@ -22,17 +22,21 @@ And you will easily be able to build things like: - **Visual Indicators**: Spinners, checkmarks, and error symbols - **Line Manipulation**: Replace previous output for dynamic updates -## Installation and Usage +## Installation -**Beddu** is meant to be sourced in your own script. - -1. Download the latest release (currently: **v1.1.0**) of `beddu.sh` to your project: +Clone the repository or download `beddu.sh` to your project: ```bash -$ curl -O https://raw.githubusercontent.com/mjsarfatti/beddu/refs/tags/v1.1.0/dist/beddu.sh +# Clone the repository +git clone https://github.com/mjsarfatti/beddu.git + +# Or just download the compiled script +curl -O https://raw.githubusercontent.com/mjsarfatti/beddu/main/beddu.sh ``` -2. Source the `beddu.sh` file in your script: +## Usage + +Source the `beddu.sh` file in your script: ```bash #!/usr/bin/env bash @@ -42,18 +46,9 @@ source "/path/to/beddu.sh" pen bold blue "Hello, world!" ``` -## Demo - -To see it in action, clone the repository, then run `make demo`. This will run the same interactive demo that you can see in the video above (please note that a 12MB wikimedia.org random file will be downloaded during the demo to showcase the functionality - a prompt will let you delete it at the end): - -```bash -$ git clone https://github.com/mjsarfatti/beddu.git -$ make demo -``` - ## Examples -More can be seen by looking at the [demo](./demo/demo.sh) file, but here is a quick overview: +More can be seen by looking at the [demo](./beddu.sh) file, but here is a quick overview: ### Text Formatting and Colors @@ -78,15 +73,10 @@ pen "This is $(pen yellow "yellow"), and this is $(pen bold "bold")" ### Interactive Functions ```bash -# Kindly ask for input (empty answer is accepted) -seek name "What's your name?" +# Ask for input +ask name "What's your name?" pen "Hello, $name!" -# Firmly ask for input (empty answer NOT accepted) -request name "No really, what's your name?" -pen "There you go, $name!" - - # Yes/no confirmation (defaults to "yes") if confirm "Continue?"; then pen green "Continuing..." @@ -124,6 +114,14 @@ sleep 1 check "Task completed!" # We can directly `check`, `warn`, or `throw` after a `spin` call - the message will always replace the spin line ``` +## Demo + +To see it in action paste the following command in your terminal: + +```bash +curl -s https://raw.githubusercontent.com/mjsarfatti/beddu/main/demo/demo.sh | bash +``` + ## Function Reference ### Text Formatting @@ -136,8 +134,7 @@ check "Task completed!" # We can directly `check`, `warn`, or `throw` after a `s ### User Interaction -- `seek [retval] PROMPT` - Get (optional) text input from user, saves the answer in `$retval` -- `request [retval] PROMPT` - Like above, but doesn't accept an empty response, saves the answer in `$retval` +- `ask [retval] PROMPT` - Get text input from user, saves the answer in `$retval` - `confirm [OPTIONS] PROMPT` - Get yes/no input - `--default-yes` - Set default answer to "yes" (default behavior) - `--default-no` - Set default answer to "no" diff --git a/demo/asciinema.png b/demo/asciinema.png deleted file mode 100644 index 3e56468..0000000 Binary files a/demo/asciinema.png and /dev/null differ diff --git a/demo/carbon.png b/demo/carbon.png index 1271e27..3e9a4e1 100644 Binary files a/demo/carbon.png and b/demo/carbon.png differ diff --git a/demo/carbon.sh b/demo/carbon.sh index 21723a8..09a425e 100755 --- a/demo/carbon.sh +++ b/demo/carbon.sh @@ -2,17 +2,20 @@ . beddu.sh -pen purple "Hello, I'm your IP helper, here for all your IP needs!" +line +pen purple "Hello, I'm your IP helper, here to help you will all your IP needs." +line -choose ACTION "What would you like to do?" "Get my IP" "Get my location" +choose action "What would you like to do?" "Get my IP" "Get my location" -case "$ACTION" in +case "$action" in "Get my IP") - run --out IP curl ipinfo.io/ip - pen "Your IP is $IP" + run --out ip curl ipinfo.io/ip + line; pen "Your IP is $ip" ;; - "Get my LOCATION") - run --out LOCATION curl -s ipinfo.io/loc - pen "Your coordinates are $LOCATION" + "Get my location") + run --out location curl -s ipinfo.io/loc + line; pen "Your coordinates are $location" ;; esac + diff --git a/demo/demo.sh b/demo/demo.sh index 7467257..b7086e5 100755 --- a/demo/demo.sh +++ b/demo/demo.sh @@ -102,7 +102,7 @@ demo() { pen $_pink italic "-- Interactive functions --" line - request name "How can I call you?" + ask name "How can I call you?" pen "Hello, $(pen bold cyan "${name:?}")" line diff --git a/dist/beddu.sh b/dist/beddu.sh index 9c7ac14..00a24ce 100755 --- a/dist/beddu.sh +++ b/dist/beddu.sh @@ -2,7 +2,7 @@ # shellcheck disable=all # # beddu.sh - A lightweight bash framework for interactive scripts and pretty output -# Version: v1.1.0 +# Version: v0.0.9 # # Copyright © 2025 Manuele Sarfatti # Licensed under the MIT license @@ -190,6 +190,29 @@ warn() { pen italic "$@" } +ask() { + local -n outvar="$1" + local prompt + local answer + prompt=$( + pen -n blue "${_q:-?} " + pen "${2}" + pen -n blue "${_a:-❯} " + ) + show_cursor + while true; do + read -r -p "$prompt" answer + case "$answer" in + "") + echo + warn "Please type your answer." + ;; + *) break ;; + esac + done + outvar="$answer" +} + choose() { local -n outvar="$1" local prompt @@ -286,40 +309,3 @@ confirm() { esac done } - -request() { - local -n outvar="$1" - local prompt - local answer - prompt=$( - pen -n blue "${_q:-?} " - pen "${2}" - pen -n blue "${_a:-❯} " - ) - show_cursor - while true; do - read -r -p "$prompt" answer - case "$answer" in - "") - echo - warn "Please type your answer." - ;; - *) break ;; - esac - done - outvar="$answer" -} - -seek() { - local -n outvar="$1" - local prompt - local answer - prompt=$( - pen -n blue "${_q:-?} " - pen "${2}" - pen -n blue "${_a:-❯} " - ) - show_cursor - read -r -p "$prompt" answer - outvar="$answer" -} diff --git a/images/SCR-20250507-taln.png b/images/SCR-20250507-taln.png new file mode 100644 index 0000000..5924a80 Binary files /dev/null and b/images/SCR-20250507-taln.png differ diff --git a/images/SCR-20250507-tbbw.png b/images/SCR-20250507-tbbw.png new file mode 100644 index 0000000..740e30a Binary files /dev/null and b/images/SCR-20250507-tbbw.png differ diff --git a/src/03.prompt/request.sh b/src/03.prompt/ask.sh similarity index 82% rename from src/03.prompt/request.sh rename to src/03.prompt/ask.sh index 2130412..a7c87cc 100644 --- a/src/03.prompt/request.sh +++ b/src/03.prompt/ask.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # shellcheck disable=SC1091 -# request.sh - Get required text input from the user +# ask.sh - Get free text input from the user [[ $BEDDU_ASK_LOADED ]] && return readonly BEDDU_ASK_LOADED=true @@ -11,14 +11,14 @@ source "$SCRIPT_DIR/../00.utils/movements.sh" source "$SCRIPT_DIR/../01.core/pen.sh" source "$SCRIPT_DIR/../02.ui/warn.sh" -# Ask a question and require a free text answer from the user +# Ask a question and get a free text answer from the user # # Usage: -# request outvar text +# ask outvar text # Example: -# request name "What is your name?" +# ask name "What is your name?" # echo "Hello, $name!" -request() { +ask() { local -n outvar="$1" # Declare nameref local prompt local answer diff --git a/src/03.prompt/seek.sh b/src/03.prompt/seek.sh deleted file mode 100644 index a5e770f..0000000 --- a/src/03.prompt/seek.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -# shellcheck disable=SC1091 -# seek.sh - Get free text input from the user - -[[ $BEDDU_ASK_LOADED ]] && return -readonly BEDDU_ASK_LOADED=true - -SCRIPT_DIR="$(dirname -- "${BASH_SOURCE[0]}")" -source "$SCRIPT_DIR/../00.utils/_symbols.sh" -source "$SCRIPT_DIR/../00.utils/movements.sh" -source "$SCRIPT_DIR/../01.core/pen.sh" -source "$SCRIPT_DIR/../02.ui/warn.sh" - -# Ask a question and get a free text answer from the user -# -# Usage: -# seek outvar text -# Example: -# seek name "What is your name?" -# echo "Hello, $name!" -seek() { - local -n outvar="$1" # Declare nameref - local prompt - local answer - - # Set prompt with default indicator - prompt=$( - pen -n blue "${_q:-?} " - pen "${2}" - pen -n blue "${_a:-❯} " - ) - - show_cursor - - # Get response - read -r -p "$prompt" answer - - # shellcheck disable=SC2034 - outvar="$answer" -}