2024-04-23 04:34:15 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2024-05-06 10:59:23 +02:00
|
|
|
ps_command="ps -eo comm:25,pid --sort=-%mem" # 25 char command name and pids sorted by memory usage
|
|
|
|
dmenu_command="dmenu -l 30 -bw 2 -W 220 -X 1131 -Y 15 -i"
|
|
|
|
|
|
|
|
# tab separated list for dmenu to ignore showing the pid
|
|
|
|
process_list=$(eval "$ps_command" | sed -E '1d; s/[[:space:]]{2,}/\t/g')
|
|
|
|
|
|
|
|
selected_process=$(echo "$process_list" | eval "$dmenu_command")
|
|
|
|
|
|
|
|
process_name=$(echo "$selected_process" | awk '{$NF=""; print}')
|
|
|
|
process_pid=$(echo "$selected_process" | awk '{print $NF}')
|
|
|
|
|
|
|
|
[[ -z $process_pid ]] && exit 1
|
|
|
|
if ps -p "$process_pid" >/dev/null 2>&1; then
|
|
|
|
choice=$(echo -e "yes\nno" | dmenu -i -l 2 -bw 2 -W 300 -X 1051 -Y 15 -p "Terminate '$(ps -o comm= -p "$process_pid")'?") &&
|
|
|
|
([[ $choice == "yes" ]] && kill "$process_pid") || exit 0
|
2024-04-23 04:34:15 +02:00
|
|
|
else
|
2024-05-06 10:59:23 +02:00
|
|
|
notify-send "Process: $process_name not found"
|
2024-04-23 04:34:15 +02:00
|
|
|
fi
|