Skip to content

Commit

Permalink
Release 2.8.6
Browse files Browse the repository at this point in the history
fix: Small fixes to improve messages and removed unused function
fix(log): Updated error2 to log to file only
fix(core): Fixed os_binary as it was broken
fix(core): Fixed listing screen sessions and created screen-sessions function
feat(core): Created _remove_last_line function to remove the last line of a string using zsh
fix(core): Fixed lots of issues with displaying system resoruces and information
build: New release 2.8.6
  • Loading branch information
jordantrizz committed May 24, 2023
1 parent 2b4a50b commit 8cdfe82
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 38 deletions.
8 changes: 5 additions & 3 deletions cmds/cmds-core.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,16 @@ zshbop-install () {
}

# -- os-alias - return alias if binary exists for os
# TODO find other commands and use os-binary such as glint
help_core[os-alias]='Return alias if binary exists for os'
os-binary () {
BINARY="$1"
local OS_BINARY_TAG=""
unset LC_CHECK NULL OS_BINARY
_debug "Running $MACHINE_OS"

if [[ $MACHINE_OS == "wsl" || $MACHINE_OS == "linux" ]]; then
_debug "Detected OS wsl || linux"
if [[ $MACHINE_OS == "linux" ]]; then
_debug "Detected OS linux"
OS_BINARY_TAG="linux_x86_64"
elif [[ $MACHINE_OS == "mac" ]]; then
_debug "Detected OS mac"
Expand All @@ -244,7 +246,7 @@ os-binary () {
return 1
else
_debug "Using created alias ${BINARY} ${OS_BINARY}"
function ${BINARY} () { ${OS_BINARY} $@ }
eval "function ${BINARY} () { ${OS_BINARY} \$@ }"
eval "export ${(U)BINARY}_CMD=$OS_BINARY"
return 0
fi
Expand Down
2 changes: 1 addition & 1 deletion cmds/cmds-gridpane.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ gp-oscheck () {

# Check if the version is not 20
if [[ "$version" != "20.04" ]]; then
_error2 "WARNING: Unsupported Ubuntu version ($version)."
_error2 "WARNING: Unsupported Ubuntu version ($version)." 0
else
_success "Running Ubuntu $version supported by GridPane"
fi
Expand Down
37 changes: 22 additions & 15 deletions cmds/cmds-linux.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ ps-mem () {
fi
}


# -- fork
help_linux[fork]='Fork command into background'
fork () {
Expand Down Expand Up @@ -293,19 +292,7 @@ datetz () {

# -- swappiness
help_linux[swappiness]="Display swappiness"
swappiness () {
if [[ $MACHINE_OS == "linux" ]]; then
if [[ -f /proc/sys/vm/swappiness ]]; then
_notice "/proc/sys/vm/swappiness: $(cat /proc/sys/vm/swappiness)"
else
_error "Can't find swap"
fi
elif [[ $MACHINE_OS == "mac" ]]; then
show_swap_mac
else
_error "Not a linux machine"
fi
}
swappiness () { mem } # alias to mem

# -- ubuntu-lts
help_linux[ubuntu-lts]="Display Ubuntu LTS version"
Expand All @@ -323,4 +310,24 @@ ubuntu-lts () {

# Print each version with its codename
echo "$combined"
}
}

# -- Screen sessions
help_linux[screen-sessions]="Display screen sessions"
screen-sessions () {
_cexists screen
if [[ $? == "0" ]]; then
SCREENS=$(screen -ls)
if [[ $SCREENS == *"No Sockets found in"* ]]; then
echo "No screen sessions found"
else
[[ $MACHINE_OS == "linux" ]] && $(screen -ls | head -n -1 | awk ' NR>1 { print $1 " " $5 }' | tr '\n' '#' | sed 's/#/ || /g')
if [[ $MACHINE_OS == "mac" ]]; then
SSESIONS=$(_remove_last_line "$(_remove_last_line "$(screen -ls)")")
echo $SSESIONS | awk ' NR>1 { print $1 " " $4 }' | tr '\n' '#' | sed 's/#/|| /g'
fi
fi
else
_error "Screen not installed" 0
fi
}
2 changes: 1 addition & 1 deletion cmds/cmds-logs.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ maldet-scans () {
MALDET_LOG_FILE="/usr/local/maldetect/logs/event_log"
grep 'scan completed on' ${MALDET_LOG_FILE}
else
_error "Couldn't access ${MALDET_LOG_FILE}"
_error "Couldn't access maldet file at ${MALDET_LOG_FILE}" 0
return 1
fi
}
25 changes: 22 additions & 3 deletions cmds/cmds-system.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,34 @@ function cpu () {
CPU_MODEL=$(lscpu | awk '/Model name:/ { $1=""; print $0 }' | sed 's/^ name: *//')
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"
_error "system-specs not implemented for $MACHINE_OS" 0
return 1
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"
if [[ $OS_MACHINE == "linux" ]]; then
# -- Memory
MEM=$(free -m | awk 'NR==2 {printf "%s MB used, %s MB free, %s MB cached", $3, $4, $6}')

# -- Swappiness
[[ -f /proc/sys/vm/swappiness ]] && SWAP="/proc/sys/vm/swappiness: $(cat /proc/sys/vm/swappiness)" || _error "Can't find swap" 0

# -- Print out Memory and Swap
echo "Memory: $MEM | Swap: $SWAP"
elif [[ $OS_MACHINE == "mac" ]]; then
MEM=$(sysctl hw.memsize | awk '{print $2/1024/1024}')
MEM_USED=$(echo "scale=2; ${MEM} - $(memory_pressure | grep "Pages free" | awk '{print $3/1024}') - $(memory_pressure | grep "Pages active" | awk '{print $3/1024}') - $(memory_pressure | grep "Pages inactive" | awk '{print $3/1024}') - $(memory_pressure | grep "Pages speculative" | awk '{print $3/1024}') - $(memory_pressure | grep "Pages wired down" | awk '{print $4/1024}')" | bc)
MEM_CACHED=$(vm_stat | awk '/^Pages free:/ {free=$3} /^Pages speculative:/ {spec=$3} /^Pages inactive:/ {inactive=$3} /^Pages wired down:/ {wired=$4} END {printf "%.1f MB\n", (free+spec+inactive+wired)*4096/1048576}')
SWAP=$(sysctl vm.swapusage | awk '/vm.swapusage:/ {print $7}')
echo -n "Mem: ${MEM} | Used: ${MEM_USED} | Cached: ${MEM_CACHED} | Swap: ${SWAP}"
_notice "You can also run sysctl vm.swapusage or memory_pressure"
else
_error "system-specs not implemented for $MACHINE_OS" 0
return 1
fi
}

# -- sysinfo
Expand Down
17 changes: 14 additions & 3 deletions cmds/os-common.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ alias ls="${DEFAULT_LS}"
DEFAULT_EXA="${EXA_CMD} --long --all --group"

# -- os-binary
os-binary fastfetch
os-binary "fastfetch"
os-binary "exa"
os-binary "glow"

Expand All @@ -33,8 +33,19 @@ function sysfetch () {
fi
}

function sysfetch-short () {
eval "${FASTFETCH_CMD} --structure Title:OS:Host:Kernel:Uptime --logo none"
function sysfetch-motd () {
#fastfetch --structure Title:OS:Host --logo none | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g" | sed "s/\n/ - /g"
#fastfetch --structure Kernel:Uptime --logo none | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g"
# https://superuser.com/a/1570726
_loading3 "$(fastfetch --structure Title:OS:Host --logo none | sed -E $'s|\x1b\\[[0-\\?]*[ -/]*[@-~]||g;
s|\x1b[PX^_][^\x1b]*\x1b\\\\||g;
s:\x1b\\][^\x07]*(\x07|\x1b\\\\)::g;
s|\x1b[@-_]||g' | tr '\n' ' ')"

_loading3 "$(fastfetch --structure Kernel:Uptime --logo none | sed -E $'s|\x1b\\[[0-\\?]*[ -/]*[@-~]||g;
s|\x1b[PX^_][^\x1b]*\x1b\\\\||g;
s:\x1b\\][^\x07]*(\x07|\x1b\\\\)::g;
s|\x1b[@-_]||g' | tr '\n' ' ')"
}

# -- tran - https://github.com/abdfnx/tran/releases
Expand Down
7 changes: 7 additions & 0 deletions lib/functions-core.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ function _pipe_separate() {
echo ""
}

# _detect_host_type
_detect_host_type() {
local dmi_output
dmi_output=$(sudo dmidecode -s system-product-name 2>/dev/null)
Expand All @@ -211,4 +212,10 @@ _detect_host_type() {
else
echo "Unable to determine"
fi
}

# -- _remove_last_line
function _remove_last_line () {
local STRING="${@%$'\n'*}"
echo "$STRING"
}
8 changes: 2 additions & 6 deletions lib/functions.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -412,19 +412,15 @@ function zshbop_check-system () {

# -- CPU
_debug "Checking CPU"
echo "$(_loading3 $(cpu))"
[[ $(cpu) == "0" ]] && echo "$(_loading3 $(cpu))"

# -- MEM
_debug "Checking memory"
echo "$(_loading3 $(mem))"
[[ $(mem) == "0" ]] && echo "$(_loading3 $(mem))"

# -- network interfaces
_debug "Network interfaces"
_loading3 "Checking network interfaces - $(interfaces)"

# -- check swappiness
_debug "Checking swappiness"
echo "$(_loading3 "Swappiness") $(swappiness)"

# -- check disk space
_debug "Checking disk space on $MACHINE_OS"
Expand Down
6 changes: 3 additions & 3 deletions lib/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function init_sshkeys () {
_dlog "-- Loading -- $SSH_KEY"
eval `keychain -q --eval --agents ssh $SSH_KEY`
else
_elog "-- Can't find $SSH_KEY, please check your CUSTOM_SSH_KEY array in .zshbop.conf"
_error "-- Can't find $SSH_KEY, please check your CUSTOM_SSH_KEY array in .zshbop.conf" 0
fi
done
else
Expand Down Expand Up @@ -547,13 +547,13 @@ init_motd () {
_loading3 "Operating System - ${MACHINE_OS} - ${MACHINE_OS_FLAVOUR}"

# -- system details
_loading3 "System details $(sysfetch-short | tr '\n' '|' | sed "s/|/ | /g")"
sysfetch-motd

# -- system-details
zshbop_check-system

# -- Show screen sessions
_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) "
_loading3 "Screen Sessions - $(screen-sessions)"

# -- Check software
init_check_software
Expand Down
1 change: 0 additions & 1 deletion motd/motd-gp.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ motd_gp () {
# -- gp-oscheck
_loading2 "Checking OS"
gp-oscheck
check-cpu-mhz

# -- inform
_notice "View more GridPane logs with the command gp-logs"
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.8.5
2.8.6
2 changes: 1 addition & 1 deletion zshbop.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ LOG_MSG=""
[[ -f $ZSHBOP_ROOT/.verbose ]] && export ZSH_VERBOSE=1 || export ZSH_VERBOSE=0 # -- zshbop verbose logging
_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"; }
_error2 () { ERROR_MSG="$bg[red] *[ERROR] ${1} ${RSC}"; [[ -z $2 ]] && { echo $ERROR_MSG | tee -a "$SCRIPT_LOG"; } || echo "$ERROR_MSG" >> "$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"; }
Expand Down

0 comments on commit 8cdfe82

Please sign in to comment.