Compare commits

..

No commits in common. "main" and "v1.0.0" have entirely different histories.
main ... v1.0.0

9 changed files with 53 additions and 109 deletions

View file

@ -33,6 +33,7 @@ _release:
echo "❗User Error: Please specify a version number (e.g. make _release v0.0.5)"; \ echo "❗User Error: Please specify a version number (e.g. make _release v0.0.5)"; \
exit 1; \ exit 1; \
fi fi
@echo ""
$(eval VERSION := $(filter-out $@,$(MAKECMDGOALS))) $(eval VERSION := $(filter-out $@,$(MAKECMDGOALS)))
@if [ "$$(git branch --show-current)" != "main" ]; then \ @if [ "$$(git branch --show-current)" != "main" ]; then \
echo "❗User Error: Releases can only be made from the main branch"; \ echo "❗User Error: Releases can only be made from the main branch"; \
@ -44,15 +45,15 @@ _release:
fi; \ fi; \
$(MAKE) build $(MAKE) build
@echo "" @echo ""
@sed -i '' "s/# Version: .*/# Version: $(VERSION)/" $(OUTPUT); \ sed -i '' "s/# Version: .*/# Version: $(VERSION)/" $(OUTPUT); \
sed -i '' -E "s/v[0-9]+\.[0-9]+\.[0-9]+/$(VERSION)/" $(README) sed -i '' -E "s/v[0-9]+\.[0-9]+\.[0-9]+/$(VERSION)/" $(README); \
@git add $(OUTPUT) $(README); \ git add $(OUTPUT) $(README); \
git commit -m "Release $(VERSION)"; \ git commit -m "Release $(VERSION)"; \
git tag -a "$(VERSION)" -m "Release $(VERSION)" git tag -a "$(VERSION)" -m "Release $(VERSION)"
@echo "" @echo ""
@git push --follow-tags git push --follow-tags
@echo "" @echo ""
@gh release create "$(VERSION)" --generate-notes --title "$(VERSION)" "$(OUTPUT)#beddu.sh" 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 "\n\033[32m✔\033[0m Release complete: \033[32m$(VERSION)\033[0m"
# Get the last version tag and increment the appropriate part # Get the last version tag and increment the appropriate part

View file

@ -1,4 +1,4 @@
# Beddu 💅🏻 # Beddu
A lightweight bash framework for interactive scripts with pretty output. A lightweight bash framework for interactive scripts with pretty output.
@ -26,10 +26,10 @@ And you will easily be able to build things like:
**Beddu** is meant to be sourced in your own script. **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: 1. Download the latest release (currently: **v1.0.0**) of `beddu.sh` to your project:
```bash ```bash
$ curl -O https://raw.githubusercontent.com/mjsarfatti/beddu/refs/tags/v1.1.0/dist/beddu.sh $ curl -O https://raw.githubusercontent.com/mjsarfatti/beddu/refs/tags/v1.0.0/dist/beddu.sh
``` ```
2. Source the `beddu.sh` file in your script: 2. Source the `beddu.sh` file in your script:
@ -78,15 +78,10 @@ pen "This is $(pen yellow "yellow"), and this is $(pen bold "bold")"
### Interactive Functions ### Interactive Functions
```bash ```bash
# Kindly ask for input (empty answer is accepted) # Ask for input
seek name "What's your name?" ask name "What's your name?"
pen "Hello, $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") # Yes/no confirmation (defaults to "yes")
if confirm "Continue?"; then if confirm "Continue?"; then
pen green "Continuing..." pen green "Continuing..."
@ -136,8 +131,7 @@ check "Task completed!" # We can directly `check`, `warn`, or `throw` after a `s
### User Interaction ### User Interaction
- `seek [retval] PROMPT` - Get (optional) text input from user, saves the answer in `$retval` - `ask [retval] PROMPT` - Get 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`
- `confirm [OPTIONS] PROMPT` - Get yes/no input - `confirm [OPTIONS] PROMPT` - Get yes/no input
- `--default-yes` - Set default answer to "yes" (default behavior) - `--default-yes` - Set default answer to "yes" (default behavior)
- `--default-no` - Set default answer to "no" - `--default-no` - Set default answer to "no"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 210 KiB

Before After
Before After

View file

@ -2,17 +2,20 @@
. beddu.sh . 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") "Get my IP")
run --out IP curl ipinfo.io/ip run --out ip curl ipinfo.io/ip
pen "Your IP is $IP" line; pen "Your IP is $ip"
;; ;;
"Get my LOCATION") "Get my location")
run --out LOCATION curl -s ipinfo.io/loc run --out location curl -s ipinfo.io/loc
pen "Your coordinates are $LOCATION" line; pen "Your coordinates are $location"
;; ;;
esac esac

View file

@ -102,7 +102,7 @@ demo() {
pen $_pink italic "-- Interactive functions --" pen $_pink italic "-- Interactive functions --"
line line
request name "How can I call you?" ask name "How can I call you?"
pen "Hello, $(pen bold cyan "${name:?}")" pen "Hello, $(pen bold cyan "${name:?}")"
line line

62
dist/beddu.sh vendored
View file

@ -2,7 +2,7 @@
# shellcheck disable=all # shellcheck disable=all
# #
# beddu.sh - A lightweight bash framework for interactive scripts and pretty output # beddu.sh - A lightweight bash framework for interactive scripts and pretty output
# Version: v1.1.0 # Version: v1.0.0
# #
# Copyright © 2025 Manuele Sarfatti # Copyright © 2025 Manuele Sarfatti
# Licensed under the MIT license # Licensed under the MIT license
@ -190,6 +190,29 @@ warn() {
pen italic "$@" 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() { choose() {
local -n outvar="$1" local -n outvar="$1"
local prompt local prompt
@ -286,40 +309,3 @@ confirm() {
esac esac
done 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"
}

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC1091 # 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 [[ $BEDDU_ASK_LOADED ]] && return
readonly BEDDU_ASK_LOADED=true 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/../01.core/pen.sh"
source "$SCRIPT_DIR/../02.ui/warn.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: # Usage:
# request outvar text # ask outvar text
# Example: # Example:
# request name "What is your name?" # ask name "What is your name?"
# echo "Hello, $name!" # echo "Hello, $name!"
request() { ask() {
local -n outvar="$1" # Declare nameref local -n outvar="$1" # Declare nameref
local prompt local prompt
local answer local answer

View file

@ -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"
}