update lservices function

This commit is contained in:
Tomasz Kapias 2023-03-19 22:28:21 +07:00
parent f41365f915
commit fc157b8105
Signed by: tkapias
SSH key fingerprint: SHA256:bsmasrX7y0xxAHa/x1x8zAgHInO4nPpKMk5JIQ0Vsbw

View file

@ -99,7 +99,7 @@ backupcp() { mkdir $HOME/.backups/; cp -r --backup=t "$1" "$HOME"/.backups/; }
md() { mkdir -pv "$1" && cd "$1"; }
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# list almost all services units (except user disabled) with state color
# list almost all services and scopes units (except user disabled) with state color
lservices() {
Help() {
cat <<- HEREDOC
@ -140,11 +140,11 @@ lservices() {
fi
if [[ "$_UID" == "0" ]]; then
local _OUT=$(sudo systemctl list-units --system -q --plain --full --no-pager -t service)
local _OUT=$(sudo systemctl list-units --system -q --plain --full --no-pager -t service,scope | sort)
elif [[ "$_UID" == "$(id -u)" ]]; then
local _OUT=$(systemctl list-units --user -q --plain --full --no-pager -t service)
local _OUT=$(systemctl list-units --user -q --plain --full --no-pager -t service,scope | sort)
else
local _OUT=$(sudo machinectl -q shell --uid="$_UID" .host /usr/bin/systemctl list-units --user -q --plain --full --no-pager -t service)
local _OUT=$(sudo machinectl -q shell --uid="$_UID" .host /usr/bin/systemctl list-units --user -q --plain --full --no-pager -t service,scope | sort)
fi
if [[ $_XCLIP == 1 ]]; then
@ -163,12 +163,12 @@ lservices() {
map["exited"] = yellow
map["failed"] = red
}
match($0,/^(.*)\.service(\s*)loaded\s[a-z]+\s([a-z]+)(\s.*)$/,a) {
status = a[3]
match($0,/^(.*)\.([a-z]+)(\s*)loaded\s[a-z]+\s([a-z]+)(\s.*)$/,a) {
status = a[4]
if ( status in map )
$0 = blue a[1] a[2] reset " " uid " " map[status] status reset a[4]
$0 = blue a[1] a[3] a[2] reset " " uid " " map[status] status reset a[5]
else
$0 = blue a[1] a[2] reset " " uid " " a[3] a[4]
$0 = blue a[1] a[3] a[2] reset " " uid " " a[4] a[5]
}
{ print } '
)