Skip to content

Commit

Permalink
Add bbb: a smart wraper around base64 -d
Browse files Browse the repository at this point in the history
  • Loading branch information
lindhe committed Oct 25, 2023
1 parent 66bb144 commit 7895d3c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions terminal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
Terminal helper programs.

* `copy.sh`: Copy the contents of a file to the clipboard.
* `bbb.sh`: A smart wrapper for base64 decoding.
36 changes: 36 additions & 0 deletions terminal/bbb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# A smart wrapper for base64 decoding.

set -euo pipefail

stderr() {
echo "${@}" 1>&2
}

fail() {
stderr "${1}"
stderr ""
stderr "Exiting …"
exit "${2:-1}"
}

missing_dependencies=false
declare -r dependencies=(
base64
)
for dep in "${dependencies[@]}"; do
if ! command -v "${dep}" &> /dev/null; then
stderr "❌ ERROR: Missing dependency ${dep}"
missing_dependencies=true
fi
done
if ${missing_dependencies}; then
fail 'Please install the missing dependencies!'
fi

if [[ $# -eq 0 ]]; then
# no args => stdin
base64 -d ; echo
else
echo -n "${*}" | base64 -d ; echo
fi

0 comments on commit 7895d3c

Please sign in to comment.