Advertisement
Guest User

external_plugin_kill.sh

a guest
May 20th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #!/bin/bash
  2. #Simple locate plugin example.
  3. #Put me in ~/.config/gambas3/higgins/extbin to use me
  4.  
  5. #This plugin will list active processes and kill them on selection
  6.  
  7. # !WITHOUT ASKING FOR CONFIRMATION!
  8.  
  9.  
  10. #This plugin will run only when the trigger is used, so:
  11. # to search for "firefox"
  12. # write: k:firef
  13. # (trigger is "k:")
  14.  
  15. #This plugin will list every process with "k:"
  16.  
  17.  
  18. export IFS=$'\n'
  19. trigger="k:" #Search using the trigger? es: l:myfile
  20. minchar=0 #Don't search on queries smaller than that, trigger does not count.
  21.  
  22. query="$@"
  23.  
  24. #Do we use a trigger?
  25. if [ -n "$trigger" ] ; then
  26. #...Yes, we do, so exit if not triggered
  27. if [[ $query != $trigger* ]] ; then
  28. exit
  29. fi
  30. #Strip the trigger prefix from the query
  31. query=$(echo $query| sed "s/^$trigger//")
  32. fi
  33.  
  34. len=${#query}
  35.  
  36. #Exit if the query is too small
  37. if [ $len -lt $minchar ] ; then
  38. exit ;
  39. fi
  40.  
  41. SCRIPTDIR=${0%/*}
  42. #Finally, start the search:
  43. for proc in $( ps -e --sort=cmd | grep -e '[0-9]' |grep "$query") ; do
  44. name=$(echo $proc | awk '{ print $4 }')
  45. pid=$(echo $proc | awk '{ print $1 }')
  46. ttime=$(echo $proc | awk '{ print $3 }')
  47. echo BEGIN
  48. # For fields description and possible values, please refer to plugins/plugin_999_template
  49. echo Text=Process name: $name '(' $pid ')'
  50. echo SubText="Time: $ttime"
  51. echo Image_file="resize://$SCRIPTDIR/support/kill.png"
  52. echo Clipboard_data=$name
  53. echo Action="EXEC"
  54. echo Action_p="kill $pid"
  55. echo END
  56. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement