Skip to content

Instantly share code, notes, and snippets.

@siberex
Last active December 1, 2022 07:11
Show Gist options
  • Save siberex/34b5027da910fe2c447164f86756dd04 to your computer and use it in GitHub Desktop.
Save siberex/34b5027da910fe2c447164f86756dd04 to your computer and use it in GitHub Desktop.
Generic bash script stuff
#!/usr/bin/env bash
# Exit script when command fails
set -o errexit
# Exit when script tries to use undeclared variable
set -o nounset
# Exit if piped command fails
set -o pipefail
# aka:
# set -euo pipefail
BASEDIR="$( cd "$(dirname "$0")" ; pwd -P )"
MY_CMDNAME=${0##*/}
echoerr() { echo "$@" 1>&2; }
CPU_CORES=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || 1)
TMP_OUTPUT_FILE="$(mktemp)"
TMP_OUTPUT_DIR="$(mktemp -d)"
function cleanup() {
rm -f "$TMP_OUTPUT_FILE"
rm -rf "$TMP_OUTPUT_DIR"
}
trap cleanup SIGINT
trap cleanup ERR
# Fancy colors
blu="\e[94m" # Light Blue
red="\e[1;91m" # Bold Red
clr="\e[0m" # Reset
function printok() {
printf "✅ ${blu}%s${clr}\n" "$*"
}
function printerr() {
printf "❌ ${red}%s${clr}\n" "$*"
}
printok "OMENS ARE GOOD 😀"
printerr "Weather is bad :-("
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment