From 2b4a50b58f7a78b63999bbed5d12f97fd6476ba4 Mon Sep 17 00:00:00 2001 From: Jordan Trask Date: Tue, 23 May 2023 10:04:23 -0400 Subject: [PATCH] Release 2.8.5 fix(zshbop): Set $ZSHBOP_UPDATE_GIT as to not presist through reloads. fix(init): Fix $MACHINE_OS and add $MACHINE_OS2 added init_home_bin fix(glint): Fixed glint OS detection and install style(git): Added function infront of functions for better searching :) fix(software): Glint checking added return 1 so that _cexists works properly fix(zshbop): Fixed branch command when not in zshbop directory style(init): Ensure init_check_vm shows errors so they're more prominent. improvement(init): Improved init_check_vm improvement(init): Improved init_check_vm message to install qemu-guest-agent improvement(zshbop): Addd faults to zshbop reports to show just faults enhance(zshbop): Create category faults for zshbop report style(glint): Print categories before running gc style(init): Making init text smaller and easier to distinguish style(init): Changed style to be more compact --- cmds/cmds-git.zsh | 16 ++++++++-- cmds/cmds-linux.zsh | 6 ++-- cmds/cmds-software.zsh | 28 +++++++++-------- cmds/cmds-system.zsh | 56 ++++++++++++++++----------------- cmds/os-common.zsh | 6 +++- cmds/os-linux.zsh | 61 ++++++++++++++++++------------------ lib/functions.zsh | 45 +++++++++++++++------------ lib/init.zsh | 70 +++++++++++++++++++++++++++--------------- version | 2 +- zshbop.zsh | 13 ++++---- 10 files changed, 173 insertions(+), 130 deletions(-) diff --git a/cmds/cmds-git.zsh b/cmds/cmds-git.zsh index 124d3363..e18cf0aa 100644 --- a/cmds/cmds-git.zsh +++ b/cmds/cmds-git.zsh @@ -14,10 +14,20 @@ typeset -gA help_git # - gc help_git[gc]='Git commit + push' -gc () { +function gc () { _cexists glint if [[ $? == "0" ]]; then _loading "Committing using glint" + echo "build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm) +ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs) +docs: Documentation only changes +feat: A new feature +fix: A bug fix +perf: A code change that improves performance +refactor: A code change that neither fixes a bug nor adds a feature +style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) +test: Adding missing tests or correcting existing tests +" glint commit git push else @@ -29,7 +39,7 @@ gc () { # - gbdc help_git[gbdc]='git branch diff on commits' -gbdc () { +function gbdc () { if [[ ! -n $1 ]] || [[ ! -n $2 ]]; then echo "Usage: gbdc " else @@ -39,7 +49,7 @@ gbdc () { # -- git-config help_git[git-config]='Configure git name and email' -git-config () { +function git-config () { vared -p "Name? " -c GIT_NAME vared -p "Email? " -c GIT_EMAIL git config --global user.email $GIT_EMAIL diff --git a/cmds/cmds-linux.zsh b/cmds/cmds-linux.zsh index 0d5fed09..3edc599e 100644 --- a/cmds/cmds-linux.zsh +++ b/cmds/cmds-linux.zsh @@ -47,11 +47,11 @@ fi help_linux[broot]='Get an overview of a directory, even a big one' _cexists broot if [[ $? == "1" ]]; then - broot () { + function broot () { check_broot } - check_broot () { - _error "broot not installed" + function check_broot () { + _error "broot not installed" 0 } fi diff --git a/cmds/cmds-software.zsh b/cmds/cmds-software.zsh index ff9d6422..ccf192dc 100644 --- a/cmds/cmds-software.zsh +++ b/cmds/cmds-software.zsh @@ -204,7 +204,7 @@ b2_download () { chmod u+x $HOME/bin/b2-linux if [[ $? -ge 1 ]]; then _error "Download failed." - else + else _success "b2-linux downloaded to $HOME/bin, run the b2 command" alias b2=b2-linux fi @@ -223,8 +223,8 @@ b2_download () { alias b2=b2-darwin fi fi - fi -} + fi +} # -- powershell help_software[powershell]="Powershell for Linux" @@ -324,7 +324,7 @@ function software_jiq () { # -- plik-conf help_software[plik-conf]='Print out .plikrc' -function plik-conf () { +function plik-conf () { if [[ ! -f $HOME/.plikrc ]]; then _error "No $HOME/.plikrc exists" return 1 @@ -353,28 +353,30 @@ function bat() { } # -- glint -help_software[change]="Install glint - https://github.com/brigand/glint" +help_software[glint]="Install glint - https://github.com/brigand/glint" if [[ $MACHINE_OS == "linux" ]]; then + _debug "Check for gblint-linux under $MACHINE_OS" _cexists glint-linux if [[ $? == "0" ]]; then - function glint () { glint-linux $* } + function glint () { glint-linux $* } function software_glint { _success "Glint installed" } else - function glint () { _error "Glint not installed, type software glint to install" } - function software_glint { + function glint () { _error "Glint not installed, type software glint to install"; return 1; } + function software_glint { _loading "Installing glint" curl -L -o $HOME/bin/glint-linux https://github.com/brigand/glint/releases/download/v6.3.4/glint-linux - chmod u+x $HOME/bin/glint-macos + chmod u+x $HOME/bin/glint-linux _loading3 "Reload shell" } fi elif [[ $MACHINE_OS == "mac" ]]; then + _debug "Check for gblint-linux under $MACHINE_OS" _cexists glint-macos if [[ $? == "0" ]]; then - function glint () { glint-macos $* } + function glint () { glint-macos $* } function software_glint { _success "Glint installed" } - else - function glint () { _error "Glint not installed, type software glint to install" } + else + function glint () { _error "Glint not installed, type software glint to install"; return 1; } function software_glint { _loading "Installing glint" curl -L -o $HOME/bin/glint-macos https://github.com/brigand/glint/releases/download/v6.3.4/glint-macos @@ -382,6 +384,8 @@ elif [[ $MACHINE_OS == "mac" ]]; then _loading3 "Reload shell" } fi +else + _debug "Couldn't detect OS for glint" fi # -- change diff --git a/cmds/cmds-system.zsh b/cmds/cmds-system.zsh index 3fe3a3f9..31d4f4e2 100644 --- a/cmds/cmds-system.zsh +++ b/cmds/cmds-system.zsh @@ -11,42 +11,21 @@ help_files[system]='System commands' # - Init help array typeset -gA help_system -# -- cpu -help_system[cpu]='Get CPU cores and threads.' -cpu () { - eval "lscpu | grep -E '^Thread|^Core|^Socket|^CPU\(|Model name|CPU MHz:|Hypervisor vendor:'" -} - # -- highcpu help_system[highcpu]='Get processes with high CPU usage.' alias highcpu="ps aux | sort -nrk 3,3 | head -n 5" -# -- mem -help_system[mem]='Get memory information' -alias mem="free -m" - # -- disk help_system[disk]='Get disk information' alias disk="lsblk" -# -- sysinfo -help_system[sysinfo]='Get system information' -sysinfo () { - _loading "CPU" - cpu - _loading "Memory" - mem - _loading "Disk" - disk - _loading "Short Format" -} - # -- sysinfo help_system[yabs]='Run yabs' alias yabs="yabs.sh" -help_system[system-specs]='Print system specs' -function system-specs () { +# -- cpu +help_system[cpu]='CPU Information' +function cpu () { # -- FreeBSD if [[ $MACHINE_OS == "freebsd" ]]; then mhz=$(sysctl -n hw.cpufrequency | awk '{print $1/1000000}') @@ -59,11 +38,11 @@ function system-specs () { _error "Please install the bc command" else if (( $(echo "$CPU_MHZ < 3" | bc -l) )); then - CPU_CHECK=$(_error "CPU Mhz = $CPU_MHZ and is below 3Ghz") + CPU_CHECK=$(_error "CPU Mhz = $CPU_MHZ and is below 3Ghz" 0 ) elif (( $(echo "$CPU_MHZ < 3.5" | bc -l) )); then - CPU_CHECK=$(_warning "CPU Mhz = $CPU_MHZ and is between 3Ghz and 3.5Ghz") + CPU_CHECK=$(_warning "CPU Mhz = $CPU_MHZ and is between 3Ghz and 3.5Ghz" 0) else - CPU_CHECK=$(_success "CPU Mhz = $CPU_MHZ and is 3.5Ghz or above") + CPU_CHECK="CPU Mhz = $CPU_MHZ and is 3.5Ghz or above" fi fi @@ -71,14 +50,31 @@ function system-specs () { CPU_CORES=$(lscpu | awk '/^Core\(s\) per socket/{print $4}') CPU_THREADS=$(lscpu | awk '/^CPU\(s\)/{print $2}') CPU_MODEL=$(lscpu | awk '/Model name:/ { $1=""; print $0 }' | sed 's/^ name: *//') - echo " - $CPU_MODEL - ${CPU_SOCKET}S/${CPU_CORES}C/${CPU_THREADS}T @ ${CPU_MHZ}" - echo " - $CPU_CHECK" - echo " - Memory: $(free -g | awk '/^Mem:/{print $2}')GB" + echo "CPU: $CPU_MODEL - ${CPU_SOCKET}S/${CPU_CORES}C/${CPU_THREADS}T @ ${CPU_MHZ} || $CPU_CHECK" else _error "system-specs not implemented for $MACHINE_OS" fi } +# -- mem +help_system[mem]='Get memory information' +function mem () { + memory_info=$(free -m | awk 'NR==2 {printf "%s MB used, %s MB free, %s MB cached", $3, $4, $6}') + echo "Memory: $memory_info" +} + +# -- sysinfo +help_system[sysinfo]='Get system information' +sysinfo () { + _loading "CPU" + cpu + _loading "Memory" + mem + _loading "Disk" + disk + _loading "Short Format" +} + help_system[count-files-directories]='Count files and directories' function count-files-directories () { local target_dir="$1" diff --git a/cmds/os-common.zsh b/cmds/os-common.zsh index eaa54e4d..f23d51b2 100644 --- a/cmds/os-common.zsh +++ b/cmds/os-common.zsh @@ -19,7 +19,7 @@ os-binary "exa" os-binary "glow" # -- sysfetch -sysfetch () { +function sysfetch () { DEFAULT_SYSFETCH="neofetch" export FASTFETCH_CONFIG="--structure Title:OS:Host:Kernel:Uptime:Packages:CPU:GPU:Memory:Disk:Shell:Terminal:TerminalFont:Locale --logo none" _debug "Checking if fastfetch is installed" @@ -33,6 +33,10 @@ sysfetch () { fi } +function sysfetch-short () { + eval "${FASTFETCH_CMD} --structure Title:OS:Host:Kernel:Uptime --logo none" +} + # -- tran - https://github.com/abdfnx/tran/releases alias tran="tran_linux_amd64" diff --git a/cmds/os-linux.zsh b/cmds/os-linux.zsh index 7e17bd94..88624949 100644 --- a/cmds/os-linux.zsh +++ b/cmds/os-linux.zsh @@ -26,40 +26,39 @@ alias tran="tran_linux_amd64" # -- interfaces help_linux[interfaces]="List interfaces ip, mac and link" interfaces_linux () { - # Get a list of all network interfaces - interfaces=($(ip -o link show | awk '{print $2}' | tr -d ':')) + local OUTPUT="" + local INTERFACES=() + local INTERFACES_OUTPUT="" - # Loop through each interface - OUTPUT=$(_banner_grey "Interface IP Mac Speed") - for interface in $interfaces; do - _debug "Processing interface: $interface" - if [[ $interface == *NONE* ]] && { interface=$(echo $interface | sed 's/@NONE//g'); _debug "Found @NONE in \$interface, removing @NONE"; } - - # Get MAC address - mac=$(ip -o link show $interface | awk '{print $17}') + # -- Check if ifconfig commmand exists + _cexists ifconfig + if [[ $? -ge "1" ]]; then + _error "ifconfig command not found, required, run zshbop install-env" + return 1 + fi - # Get link speed - speed=$(ethtool $interface 2>>/dev/null | grep 'Speed: ' | awk '{print $2}') - [[ -z $speed ]] && speed="N/A" + # -- Get a list of all network interfaces + INTERFACES=("${(f)$(ip -o link show | awk '{print $2}' | sed 's/://')}") - # Get IP address - ip=$(ip -o addr show $interface | awk '{print $3","$4}') - if [[ "${ip%%\n*}" != "${ip}" ]]; then - _debug " -- Found multiple IP addresses for $interface" - while read -r ip; do - _debug "Interface: $interface IP: $ip MAC: $mac Speed: $speed" - OUTPUT+="\n$interface $ip $mac $speed" - done <<< "${ip}" - elif [[ -z $ip ]]; then - _debug " -- No IP address found for $interface" - OUTPUT+="\n$interface N/A $mac $speed" - else - # Print interface information - _debug "Interface: $interface IP: $ip MAC: $mac Speed: $speed" - OUTPUT+="\n$interface $ip $mac $speed" - fi - done - echo -e "$OUTPUT" | column -t + # -- Loop through each interface + for INTERFACE in $INTERFACES; do + + # -- Get MAC address + INTERFACE_MAC=$(ifconfig $INTERFACE | awk '/ether/{print $2}') + + # -- Get link speed + INTERFACE_SPEED=$(ethtool $INTERFACE 2> /dev/null | awk '/Speed:/ {print $2}') + [[ -z $INTERFACE_SPEED ]] && INTERFACE_SPEED="N/A" + + # Get IP address + INTERFACE_IP=$(ifconfig $INTERFACE | awk '/inet /{print $2}') + + # -- Print interface information + _debug "$INTERFACE:$INTERFACE_IP - $INTERFACE_MAC $INTERFACE_SPEED" + INTERFACES_OUTPUT+="$INTERFACE:$INTERFACE_IP - $INTERFACE_MAC $INTERFACE_SPEED || " + done + + echo "$INTERFACES_OUTPUT" } # -- check_diskspace_linux diff --git a/lib/functions.zsh b/lib/functions.zsh index 12117af9..817e5394 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -96,14 +96,14 @@ help_zshbop[branch]='Run main or dev branch of zshbop' zshbop_branch () { _debug_all if [[ -n $2 ]]; then - _loading " -- Switching to $2 branch" + _loading "Switching to $2 branch" GIT_CHECKOUT=$(git --git-dir=$ZSHBOP_ROOT/.git --work-tree=$ZSHBOP_ROOT checkout $2) _debug "GIT_CHECKOUT: $GIT_CHECKOUT" if [[ $? -eq "0" ]]; then - _success " -- Switched to $2 branch, pulling latest changes" - git pull + _success " --Switched to $2 branch, pulling latest changes" + git --git-dir=$ZSHBOP_ROOT/.git --work-tree=$ZSHBOP_ROOT pull else - _error " -- Failed to switch to $2 branch" + _error " -- Failed to switch to $2 branch" fi elif [[ $? -ge "1" ]]; then _error "Branch doesn't seem to exist" @@ -349,7 +349,7 @@ zshbop_help () { # -- zshbop_report # -------------- help_zshbop[report]='Print out errors and warnings' -zshbop_report () { +function zshbop_report () { local LOG_LEVEL="$1" local SHOW_LEVEL=() local TAIL_LINES="" @@ -366,9 +366,7 @@ zshbop_report () { SHOW_LEVEL=("WARNING" "ALERT" "ERROR") _loading3 "No log level specified" elif [[ $LOG_LEVEL == "help" ]]; then - echo "Usage: report " - elif [[ $LOG_LEVEL == "less" ]]; then - less $SCRIPT_LOG + echo "Usage: report " elif [[ $LOG_LEVEL = "all" ]]; then SHOW_LEVEL=("ERROR" "WARNING" "ALERT" "LOG") elif [[ $LOG_LEVEL = "debug" ]]; then @@ -379,10 +377,14 @@ zshbop_report () { SHOW_LEVEL=("WARNING") elif [[ $LOG_LEVEL = "alert" ]]; then SHOW_LEVEL=("ALERT") - elif [[ $LOG_LEVEL = "log" ]]; then - SHOW_LEVEL=("LOG") elif [[ $LOG_LEVEL = "notice" ]]; then SHOW_LEVEL=("NOTICE") + elif [[ $LOG_LEVEL = "log" ]]; then + SHOW_LEVEL=("LOG") + elif [[ $LOG_LEVEL == "less" ]]; then + less $SCRIPT_LOG + elif [[ $LOG_LEVEL = "faults" ]]; then + SHOW_LEVEL=("ERROR" "WARNING" "ALERT") else _error "Unknown $LOG_LEVEL" fi @@ -390,11 +392,11 @@ zshbop_report () { # -- start _debug_all _loading "-- zshbop report ------------" - _loading3 "Showing - ${SHOW_LEVEL[@]}" + [[ $LOG_LEVEL != "faults" ]] && _loading3 "Showing - ${SHOW_LEVEL[@]}" # -- print out logs for LOG in $SHOW_LEVEL; do - _loading2 "-- $LOG ------------" - _loading3 "Last $TAIL_LINES $LOG from - grep "\[${LOG}\]" $SCRIPT_LOG" + [[ $LOG_LEVEL != "faults" ]] && _loading2 "-- $LOG ------------" + [[ $LOG_LEVEL != "faults" ]] && _loading3 "Last $TAIL_LINES $LOG from - grep "\[${LOG}\]" $SCRIPT_LOG" grep "\[$LOG\]" $SCRIPT_LOG | tail -n $TAIL_LINES done echo "" @@ -404,14 +406,21 @@ zshbop_report () { # -- system_check - check usualy system stuff # ============================================== help_zshbop[check-system]='Print out errors and warnings' -zshbop_check-system () { +function zshbop_check-system () { # -- start _debug_all + + # -- CPU + _debug "Checking CPU" + echo "$(_loading3 $(cpu))" + + # -- MEM + _debug "Checking memory" + echo "$(_loading3 $(mem))" # -- network interfaces _debug "Network interfaces" - _loading3 "Checking network interfaces" - interfaces | sed 's/^/ /' + _loading3 "Checking network interfaces - $(interfaces)" # -- check swappiness _debug "Checking swappiness" @@ -425,9 +434,7 @@ zshbop_check-system () { _debug "Checking block devices" echo "$(_loading3 "Checking block devices") $(check_blockdevices)" - # -- Quick CPU/Mem - _debug "Checking CPU/Mem" - echo "$(_loading3 "Checking CPU/Mem") $(system-specs)" + } # -------------- diff --git a/lib/init.zsh b/lib/init.zsh index e5324175..6378e406 100644 --- a/lib/init.zsh +++ b/lib/init.zsh @@ -90,9 +90,9 @@ init_detectos () { *) MACHINE_OS="UNKNOWN:${UNAME}" esac - # -- Check for WSL and set as MACHINE_OS + # -- Check for WSL and set as MACHINE_OS2 if [[ $(uname -r) =~ "Microsoft" || $(uname -r) =~ "microsoft" ]]; then - MACHINE_OS="wsl" + MACHINE_OS2="wsl" fi # -- Check for synology and set as MACHINE_OS @@ -406,14 +406,13 @@ function init_app_config () { # ============================================== init_check_software () { # -- Check services and software - _loading "Checking Software" # -- check if atop is installed if _cexists atop; then # -- check if atop is running using ps and pgrep - pgrep atop >> /dev/null && _success "atop installed and running" || _warning "atop installed but not running, if this is a server install it" + pgrep atop >> /dev/null && _success "atop installed and running" 0 || _warning "atop installed but not running, if this is a server install it" 0 else - _warning "atop not installed, if this is a server install it" + _warning "atop not installed, if this is a server install it" 0 fi # -- check if broot is installed @@ -425,7 +424,6 @@ init_check_software () { # ============================================== function init_check_services () { # -- Check system software versions - _loading "Checking Service Versions" # -- cloudflared if (( $+commands[cloudflared] )) && _alert "cloudflared: $(cloudflared -v)" || _log "cloudflared Server not installed" @@ -487,21 +485,28 @@ function init_check_vm () { _debug "virt-what installed" VM=$(virt-what) if [[ -n $VM ]]; then - _warning "VM-virt-what: Running on $VM" _debug "virt-what returned $VM" + if [[ $VM == "kvm" ]]; then + if [[ $(pgrep qemu) ]] || [[ $(pgrep qemu-system) ]]; then + echo "$(_loading3 VM-virt-what:) Running on KVM, and qemu guest tools is running" + else + _warning "VM-virt-what: Running on KVM, but qemu is not running, install qemu-guest-agent" 0 + fi + else + _alert "VM-virt-what: Running on $VM" 0 + fi else - _notice "Not running in a VM" + _loading3 "Not running in a VM" _debug "virt-what returned $VM" fi else - _notice "Unable to determine if in virtual environment, please install virt-what" + _alert "Unable to determine if in virtual environment, please install virt-what" 0 fi - } +} # ============================================== # -- check if in virtual environment secondary method # ============================================== - function init_check_vm_2 () { _debug "Checking if in virtual environment" if [[ -d /sys/devices/virtual ]] || [[ -f /proc/vz ]] || [[ -d /proc/xen ]]; then @@ -511,9 +516,24 @@ function init_check_vm_2 () { fi } +# ============================================== +# -- init_home_bin - Make sure $HOME/bin exists +# ============================================== +function init_home_bin () { + # -- check if home bin exists + if [[ -d $HOME/bin ]]; then + _debug "Home bin exists" + else + _loading2 "\$HOME/bin does not exist...creating home bin" + mkdir $HOME/bin + fi +} + +########################################################### ########################################################### # ---- Leave this at the bottom. Do not move above. ------ ########################################################### +########################################################### # ============================================== # -- init_motd - initial scripts to run on login @@ -521,29 +541,25 @@ function init_check_vm_2 () { init_motd () { # -- Start motd _debug_all + _loading "System Information" # -- OS specific motd _loading3 "Operating System - ${MACHINE_OS} - ${MACHINE_OS_FLAVOUR}" # -- system details - _loading "System details" - sysfetch | _pipe_separate 2 | sed 's/^/ /' - echo "" - - _loading "System check on $MACHINE_OS" - zshbop_check-system - init_check_vm - echo "" + _loading3 "System details $(sysfetch-short | tr '\n' '|' | sed "s/|/ | /g")" + # -- system-details + zshbop_check-system + # -- Show screen sessions - _loading "Screen Sessions" - _cexists screen && _success "$(screen -list)" || _error "Screen not installed" + _loading3 "Screen Sessions $(_cexists screen && echo "$(screen -ls | head -n -1 | awk ' NR>2 { print $1 " " $5 }' | tr '\n' '#' | sed 's/#/ || /g')" || _error "Screen not installed" 0) " - # -- Running system checklist + # -- Check software init_check_software - echo "" - # -- Check service software versions + # -- Check service software versions + _loading3 "Checking Service Versions" init_check_services echo "" @@ -554,11 +570,14 @@ init_motd () { _loading2 "Run zshbop check or system-specs." #env-install to install default and extra tools. Run system-specs for more system details." # TODO - add system-specs + echo "" # -- run report after exec zsh if [[ $RUN_REPORT == "1" ]]; then zshbop_report export RUN_REPORT=0 + else + zshbop_report faults fi # -- last echo to keep motd clean @@ -578,6 +597,7 @@ function init_zshbop () { # -- Init zshbop init_checkzsh # -- Check zsh init_path # -- Set paths + init_home_bin # -- Check if home bin exists init_detectos # -- Detect operating system init_pkg_manager # -- Init package manager init_cmds # -- Include commands @@ -591,6 +611,8 @@ function init_zshbop () { init_plugins # -- Init plugins init_sshkeys # -- Init ssh keys + echo "" + _debug "init_zshbop: \$funcstack = $funcstack" if [[ $ZSHBOP_RELOAD == "1" ]]; then _loading2 "Not loading init_motd, init_sshkeys on Reload" diff --git a/version b/version index 0409c163..7f04bb11 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.8.4 \ No newline at end of file +2.8.5 \ No newline at end of file diff --git a/zshbop.zsh b/zshbop.zsh index 569b6f12..8ec482d3 100755 --- a/zshbop.zsh +++ b/zshbop.zsh @@ -59,6 +59,7 @@ export GIT_HOME="${HOME}/git" export REPOS_DIR="$ZSHBOP_ROOT/repos" export RUN_REPORT="0" export ZSHBOP_RELOAD="0" +export ZSHBOP_UPDATE_GIT="" # -- zshbop git export ZSHBOP_BRANCH=$(git --git-dir=$ZSHBOP_ROOT/.git --work-tree=$ZSHBOP_ROOT rev-parse --abbrev-ref HEAD) # -- current branch @@ -159,12 +160,12 @@ ZSH_VERBOSE="0" ZSHBOP_LOGS="" LOG_MSG="" [[ -f $ZSHBOP_ROOT/.verbose ]] && export ZSH_VERBOSE=1 || export ZSH_VERBOSE=0 # -- zshbop verbose logging -_log () { LOG_MSG="${*}"; [[ $ZSH_VERBOSE == 1 ]] && { echo "[LOG] \033[30m** : ${*}\033[0m" | tee -a "$SCRIPT_LOG"; } || { echo "[LOG] $LOG_MSG" >> "$SCRIPT_LOG"; } } # -- log for core -_error () { echo "$fg[red] *[ERROR] $@ ${RSC}" | tee -a "$SCRIPT_LOG"; } -_error2 () { echo "$bg[red] *[ERROR] $@ ${RSC}" | tee -a "$SCRIPT_LOG"; } -_warning () { echo "$fg[yellow] *[WARNING] $@ ${RSC}" | tee -a "$SCRIPT_LOG"; } -_alert () { echo "$bg[red] $fg[yellow] *[ALERT] $@ ${RSC}" | tee -a "$SCRIPT_LOG"; } -_notice () { NOTICE_MSG="$fg[blue] * $@ ${RSC}"; echo "$NOTICE_MSG";echo "[NOTICE] $NOTICE_MSG" >> "$SCRIPT_LOG"; } +_log () { LOG_MSG="[LOG] ${1}"; [[ -z $2 ]] && { [[ $ZSH_VERBOSE == 1 ]] && { echo "$LOG_MSG" | tee -a "$SCRIPT_LOG"; } } || { echo "$LOG_MSG" >> "$SCRIPT_LOG"; } } # -- log for core +_error () { ERROR_MSG="$fg[red] *[ERROR] ${1} ${RSC}"; [[ -z $2 ]] && { echo $ERROR_MSG | tee -a "$SCRIPT_LOG"; } || echo "$ERROR_MSG" >> "$SCRIPT_LOG"; } +_error2 () { echo "$bg[red] *[ERROR] ${1} ${RSC}" | tee -a "$SCRIPT_LOG"; } +_warning () { WARN_MSG="$fg[yellow] *[WARNING] ${1} ${RSC}"; [[ -z $2 ]] && { echo $WARN_MSG | tee -a "$SCRIPT_LOG"; } || echo "$WARN_MSG" >> "$SCRIPT_LOG" } +_alert () { ALERT_MSG="$bg[red] $fg[yellow] *[ALERT] ${1} ${RSC}"; [[ -z $2 ]] && { echo $ALERT_MSG | tee -a "$SCRIPT_LOG"; } || echo "$ALERT_MSG" >> "$SCRIPT_LOG"; } +_notice () { NOTICE_MSG="$fg[blue] * [NOTICE]${1} ${RSC}"; [[ -z $2 ]] && { echo $NOTICE_MSG | tee -a "$SCRIPT_LOG"; } || echo "$NOTICE_MSG" >> "$SCRIPT_LOG"; } _dlog () { _log "${*}"; _debug "${*}" } _elog () { _log "${*}"; _error "${*}" }