diff --git a/config/alias b/config/alias index 527d71b..2ccc9f1 100755 --- a/config/alias +++ b/config/alias @@ -76,8 +76,8 @@ alias code_scanner='docker run alias zedit='$EDITOR ~/.dotfiles' -have irssi && \ - alias irssi="irssi --config='$IRSSI_CONFIG_FILE' --home='$IRSSI_CONFIG_HOME'" +have irssi \ + && alias irssi="irssi --config='$IRSSI_CONFIG_FILE' --home='$IRSSI_CONFIG_HOME'" if [[ -f "$HOME/.aliases.local" ]]; then # shellcheck disable=SC1091 diff --git a/local/bin/dfm b/local/bin/dfm index 0a175cb..f795b58 100755 --- a/local/bin/dfm +++ b/local/bin/dfm @@ -9,6 +9,7 @@ # Helper variables, override with ENVs like `VERBOSE=1 dfm help` : "${VERBOSE:=0}" : "${DOTFILES:=$HOME/.dotfiles}" +: "${SHARED_SCRIPT:=$DOTFILES/scripts/shared.sh}" : "${INSTALL_SCRIPT:=$DOTFILES/scripts/install-dotfiles.sh}" : "${BREWFILE:=$DOTFILES/Brewfile}" : "${HOSTFILES:=$DOTFILES/hosts}" @@ -18,14 +19,14 @@ SCRIPT=$(basename "$0") VERSION_NVM="v0.39.3" # shellcheck source=./../../scripts/shared.sh -source "$DOTFILES/scripts/shared.sh" +source "$SHARED_SCRIPT" function section_install { - USAGE_PREFIX="$SCRIPT install" + USAGE_PREFIX="$SCRIPT install " MENU=( - "all:Installs macos defaults, antigen, starship, brew, nvm, npm packages and others" + "all:Installs everything in the correct order" "antigen:Updates the antigen.zsh file" "composer:Install composer" "dotenv:Install dotenv-linter" @@ -116,7 +117,7 @@ function section_install function section_brew { - USAGE_PREFIX="$SCRIPT brew" + USAGE_PREFIX="$SCRIPT brew " MENU=( "install:Installs items defined in Brewfile" @@ -154,7 +155,7 @@ function section_brew function section_dotfiles { - USAGE_PREFIX="$SCRIPT dotfiles" + USAGE_PREFIX="$SCRIPT dotfiles " MENU=( "fmt:Run all formatters" @@ -219,13 +220,13 @@ function section_dotfiles function section_check { - USAGE_PREFIX="$SCRIPT check" + USAGE_PREFIX="$SCRIPT check " X_HOSTNAME=$(hostname) X_ARCH=$(uname) MENU=( - "arch :Empty returns current. Exit code 0 when match, 1 when not." - "host :Empty returns current. Exit code 0 when match, 1 when not." + "arch :Empty returns current. Exit code 0=match to current, 1=no match." + "host :Empty returns current. Exit code 0=match to current, 1=no match." ) case "$1" in @@ -246,7 +247,7 @@ function section_check # Secret menu for visual tests function section_tests { - USAGE_PREFIX="$SCRIPT tests" + USAGE_PREFIX="$SCRIPT tests " MENU=( "msg:List all log functions from shared.sh" @@ -277,16 +278,9 @@ function section_tests function usage { - SECTIONS=( - "install" - "reset" - "brew" - "check" - "dotfiles" - ) echo "" - menu_usage_header "Usage: $SCRIPT" "${SECTIONS[@]}" - echo $" All commands have their own subcommands." + msg_prompt "Usage: $SCRIPT
" + echo $" Empty prints
help." echo "" section_install echo "" diff --git a/local/bin/x-dc b/local/bin/x-dc index 1bc3032..023d9b5 100755 --- a/local/bin/x-dc +++ b/local/bin/x-dc @@ -11,4 +11,3 @@ dir="$1" if [ ! -d "$dir" ]; then mkdir -p "$dir" && exit 0 fi - diff --git a/local/bin/x-ip b/local/bin/x-ip index 39d240e..ec35544 100755 --- a/local/bin/x-ip +++ b/local/bin/x-ip @@ -2,4 +2,3 @@ # Source: https://github.com/thirtythreeforty/dotfiles/blob/master/bin/extip curl icanhazip.com "${@}" - diff --git a/scripts/shared.sh b/scripts/shared.sh index d738b9e..d200faa 100755 --- a/scripts/shared.sh +++ b/scripts/shared.sh @@ -11,6 +11,28 @@ 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() { @@ -68,7 +90,8 @@ function msg_done() echo -e "$(__log_marker) $1 ...$(__log_marker_ok)" } -function msg_done_suffix() { +function msg_done_suffix() +{ echo -e "$(__log_marker) ...$(__log_marker_ok)" } @@ -146,7 +169,7 @@ function menu_usage_header() KEYS="" for item in "${MENU_ARRAY[@]}"; do - CMD=$(echo "${item}"|awk -F ":" '{print $1}') + CMD=$(echo "${item}" | awk -F ":" '{print $1}') KEYS+="${CMD} | " done @@ -163,9 +186,9 @@ function menu_usage() shift MENU_ARRAY=("$@") - menu_usage_header "$MENU_CMD" "${MENU_ARRAY[@]}" + msg "$MENU_CMD" - for item in "${MENU_ARRAY[@]}" ; do + for item in "${MENU_ARRAY[@]}"; do CMD=$(echo "${item}" | awk -F ":" '{print $1}') DESC=$(echo "${item}" | awk -F ":" '{print $2}') menu_item "$CMD" "$DESC" @@ -176,7 +199,7 @@ function menu_usage() # usage: have php && php -v function have { - command -v "$1" >&/dev/null; + command -v "$1" >&/dev/null } # Remove directory from the PATH variable