From 7895d3cd8e39be38c7a538f04f4754406d54a709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Lindh=C3=A9?= Date: Wed, 25 Oct 2023 17:07:59 +0200 Subject: [PATCH] Add bbb: a smart wraper around base64 -d --- terminal/README.md | 1 + terminal/bbb.sh | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100755 terminal/bbb.sh diff --git a/terminal/README.md b/terminal/README.md index 4502d84..5d914fc 100644 --- a/terminal/README.md +++ b/terminal/README.md @@ -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. diff --git a/terminal/bbb.sh b/terminal/bbb.sh new file mode 100755 index 0000000..870560c --- /dev/null +++ b/terminal/bbb.sh @@ -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