dm-kill.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env bash
  2. #
  3. # Script name: dmkill
  4. # Description: Search for a process to kill.
  5. # Dependencies: dmenu
  6. # GitLab: https://www.gitlab.com/dwt1/dmscripts
  7. # License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
  8. # Contributors: Derek Taylor
  9. # Colors:
  10. # # Materia Manjaro
  11. # nf='#09dbc9'
  12. # nb='#222b2e'
  13. # sf='#dbdcd5'
  14. # sb='#009185'
  15. # Everforest
  16. nf='#d3c6aa'
  17. nb='#2d353b'
  18. sf='#a7c080'
  19. sb='#475258'
  20. fn='Iosevka-18:normal'
  21. # fn='Ubuntu-16:normal'
  22. # Gruvbox
  23. # nf='#fea63c'
  24. # nb='#282828'
  25. # # sf='#dbdcd5'
  26. # sb='#d79921'
  27. # fn='Sarasa Mono SC Nerd-17:normal'
  28. # Running ps to get running processes and display in dmenu.
  29. selected="$(ps --user "$(id -u)" -F --no-headers | \
  30. awk '{print $1" "$2" "$11}' | \
  31. dmenu -i -l 20 -nf ${nf} -nb ${nb} \
  32. -sf ${sf} -sb ${sb} \
  33. -fn ${fn} -p "Search for process to kill:")"
  34. # Nested 'if' statements. The outer 'if' statement is what to do
  35. # when we select one of the 'selected' options listed in dmenu.
  36. if [[ -n $selected ]]; then
  37. # Piping No/Yes into dmenu as a safety measure, in case you
  38. # select a process that you don't actually want killed.
  39. answer="$(echo -e "No\nYes" | dmenu -i -l 2 -nf '#09dbc9' -nb '#222b2e' \
  40. -sf '#dbdcd5' -sb '#009185' \
  41. -fn 'Ubuntu-14:normal' -p "Kill $selected?")"
  42. if [[ $answer == "Yes" ]]; then
  43. selpid="$(awk '{print $2}' <<< "$selected")";
  44. kill -9 "$selpid"
  45. echo "Process $selected has been killed." && exit 0
  46. else
  47. echo "Program terminated." && exit 0
  48. fi
  49. fi
  50. exit 0