feat(scripts): msgr helper script

This commit is contained in:
2023-09-28 17:13:44 +03:00
parent 10b18e8bcc
commit 0aff4784b1
4 changed files with 229 additions and 158 deletions

View File

@@ -4,6 +4,8 @@
# shellcheck source=shared.sh
source "$HOME/.dotfiles/scripts/shared.sh"
msg "Starting to install pip packages"
! have pip && {
msg_err "Could not find pip, something really terrible is going on." && exit 1
}
@@ -19,7 +21,10 @@ for pkg in "${packages[@]}"; do
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
msg_nested "Installing pip package: $pkg"
python3 -m pip install --user "$pkg"
echo ""
done
msg_yay "Run pip package installation"

View File

@@ -6,145 +6,7 @@
# Helper env variables. Use like this: VERBOSE=1 ./script.sh
: "${VERBOSE:=0}"
# If this file has already been loaded, no need to reload it.
[ "$DOTFILES_SHARED_LOADED" = "yes" ] && return
export DOTFILES_SHARED_LOADED="yes"
# -- Colors -- #
CLR_RED="\033[1;31m"
CLR_YELLOW="\033[1;33m"
CLR_GREEN="\033[1;32m"
CLR_BLUE="\033[1;34m"
CLR_RESET="\033[0m"
# -- Color functions -- #
function __color_red()
{
local MSG="$1"
echo -e "${CLR_RED}${MSG}${CLR_RESET}"
}
function __color_yellow()
{
local MSG="$1"
echo -e "${CLR_YELLOW}${MSG}${CLR_RESET}"
}
function __color_green()
{
local MSG="$1"
echo -e "${CLR_GREEN}${MSG}${CLR_RESET}"
}
function __color_blue()
{
local MSG="$1"
echo -e "${CLR_BLUE}${MSG}${CLR_RESET}"
}
# -- Helpers -- #
function __log_marker()
{
echo -e "${CLR_BLUE}${CLR_RESET}"
}
function __log_marker_ok()
{
echo -e "${CLR_GREEN}${CLR_RESET}"
}
function __log_marker_ok_blue()
{
echo -e "${CLR_BLUE}${CLR_RESET}"
}
function __log_marker_warn()
{
echo -e "${CLR_YELLOW}${CLR_RESET}"
}
function __log_marker_question()
{
echo -e "${CLR_YELLOW}?${CLR_RESET}"
}
function __log_marker_err()
{
echo -e "${CLR_RED}${CLR_RESET}"
}
function __log_indent()
{
echo " "
}
# -- Log -- #
function msg()
{
echo -e "$(__log_marker) $1"
}
function msg_yay()
{
echo -e "🎉 $1"
}
function msg_yay_done()
{
echo -e "🎉 $1 ...$(__log_marker_ok)"
}
function msg_done()
{
echo -e "$(__log_marker) $1 ...$(__log_marker_ok)"
}
function msg_done_suffix()
{
echo -e "$(__log_marker) ...$(__log_marker_ok)"
}
function msg_prompt()
{
echo -e "$(__log_marker_question) $1"
}
function msg_prompt_done()
{
echo -e "$(__log_marker_question) $1 ...$(__log_marker_ok)"
}
function msg_nested()
{
echo -e "$(__log_indent)$(__log_marker) $1"
}
function msg_nested_done()
{
echo -e "$(__log_indent)$(__log_marker) $1 ...$(__log_marker_ok)"
}
function msg_run()
{
echo -e "${CLR_GREEN}$1${CLR_RESET} $2"
}
function msg_run_done()
{
echo -e "${CLR_GREEN}$1${CLR_RESET} $2 ...$(__log_marker_ok)"
}
function msg_ok()
{
echo -e "$(__log_marker_ok) $1"
}
function msg_warn()
{
echo -e "$(__log_marker_warn) $1"
}
function msg_err()
{
echo -e "$(__log_marker_err) $1"
}
source "$DOTFILES/local/bin/msgr"
# -- Menu builder -- #
function menu_section()
@@ -357,20 +219,6 @@ silent()
"$@" >&/dev/null
}
# Create a prompt which you have to answer y/n to continue
ask()
{
while true; do
read -p "$1 ([y]/n) " -r
REPLY=${REPLY:-"y"}
if [[ $REPLY =~ ^[Yy]$ ]]; then
return 1
elif [[ $REPLY =~ ^[Nn]$ ]]; then
return 0
fi
done
}
# Check if a file contains non-ascii characters
nonascii()
{