code quality

This commit is contained in:
fatalerrors
2026-03-25 20:43:06 +01:00
parent 84e6fdd429
commit 60a159c3ea

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
# #
# * Redistribution and use in source and binary forms, # * Redistribution and use in source and binary forms,
@@ -128,12 +128,12 @@ gpid()
for pid in $@; do for pid in $@; do
local result=$(ps $psopt | grep $pid | awk '{print $1}' | sed "s/\n/ /") local result=$(ps $psopt | grep $pid | awk '{print $1}' | sed "s/\n/ /")
if [[ $single ]]; then if [[ $single ]]; then
[[ $result ]] && echo "${result//$'\n'/ }" [[ -n "$result" ]] && echo "${result//$'\n'/ }"
else else
[[ $result ]] && echo "$pid: ${result//$'\n'/ }" [[ -n "$result" ]] && echo "$pid: ${result//$'\n'/ }"
fi fi
done done
[[ $result ]] || return 1 [[ -n "$result" ]] || return 1
} }
export -f gpid export -f gpid
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -155,8 +155,14 @@ ku()
disp E "Usage: ku <username1 [username2 ...]>" disp E "Usage: ku <username1 [username2 ...]>"
return 1 return 1
fi fi
for u in $@; do local users="$@"
for u in $users; do
if ! id "$u" >/dev/null 2>&1; then
disp E "User '$u' does not exist."
return 1
else
killall -u "$u" killall -u "$u"
fi
done done
} }
export -f ku export -f ku
@@ -187,7 +193,7 @@ kt()
return 1 return 1
fi fi
children_pids=$(pgrep -P "$parent_pid") local children_pids=$(pgrep -P "$parent_pid")
for pid in $children_pids; do for pid in $children_pids; do
kt "$pid" "$@" || break kt "$pid" "$@" || break
@@ -198,3 +204,4 @@ kt()
# EOF # EOF