Last active
August 24, 2021 07:58
-
-
Save BradenM/47b295649654e72c6d59c9f93285249b to your computer and use it in GitHub Desktop.
Bash Install Script Utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Some Generic Bash Utils | |
# Credit ==> https://natelandau.com/bash-scripting-utilities/ | |
# | |
#Set Colors | |
# | |
bold=$(tput bold) | |
underline=$(tput sgr 0 1) | |
reset=$(tput sgr0) | |
purple=$(tput setaf 171) | |
magenta=$(tput setaf 5) | |
cyan=$(tput setaf 6) | |
red=$(tput setaf 1) | |
green=$(tput setaf 76) | |
tan=$(tput setaf 3) | |
blue=$(tput setaf 38) | |
# Spinner loader | |
show_spinner() { | |
local info="$1" | |
local pid=$! | |
local delay=0.75 | |
local spinstr='|/-\' | |
while kill -0 $pid 2> /dev/null; do | |
local temp=${spinstr#?} | |
printf " [%c] $info" "$spinstr" | |
local spinstr=$temp${spinstr%"$temp"} | |
sleep $delay | |
local reset="\b\b\b\b\b\b" | |
for ((i=1; i<=$(echo $info | wc -c); i++)); do | |
reset+="\b" | |
done | |
printf $reset | |
done | |
printf " \b\b\b\b" | |
} | |
# | |
# Headers and Logging | |
# | |
e_header() { printf "\n${bold}${purple}========== %s ==========${reset}\n" "$@" | |
} | |
e_arrow() { printf "➜ $@\n" | |
} | |
e_divider() { | |
printf "\n${bold}${purple}::${reset}${bold} $@" | |
} | |
e_success() { printf "${green}✔ %s${reset}\n" "$@" | |
} | |
e_error() { printf "${red}✖ %s${reset}\n" "$@" | |
} | |
e_warning() { printf "${tan}➜ %s${reset}\n" "$@" | |
} | |
e_underline() { printf "${underline}${bold}%s${reset}\n" "$@" | |
} | |
e_bold() { printf "${bold}%s${reset}\n" "$@" | |
} | |
e_title() { printf "${bold}%s${reset}\n" "$(e_divider "$@")" | |
} | |
e_note() { printf "${underline}${bold}${blue}Note:${reset} ${blue}%s${reset}\n" "$@" | |
} | |
# Utils | |
# Check if command exists | |
type_exists() { | |
if [ $(type -P $1) ]; then | |
return 0 | |
fi | |
return 1 | |
} | |
# Check OS | |
is_os() { | |
if [[ "${OSTYPE}" == $1* ]]; then | |
return 0 | |
fi | |
return 1 | |
} | |
# Check if running as Root | |
is_root() { | |
if [ $(whoami) != "root" ]; then | |
return 1 | |
fi | |
return 0 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment