#!/bin/bash

#gettext
export TEXTDOMAIN=pprocess
export OUTPUT_CHARSET=UTF-8

case $1 in
	-action)
		if [ ! "$ACTION" ]; then
			TXT1="$(gettext 'No action defined')"
			. "$PROGPATH"/box_ok
		fi
		case $ACTION in
			"$(gettext 'End process (kill)')") kill -9 `echo "$LIST" | awk '{print $1}'`;;
			"$(gettext 'CPU priority') - $(gettext 'High')") renice -10 `echo "$LIST" | awk '{print $1}'`;; #high
			"$(gettext 'CPU priority') - $(gettext 'Normal')") renice 0 `echo "$LIST" | awk '{print $1}'`;; #normal
			"$(gettext 'CPU priority') - $(gettext 'Low')") renice 10 `echo "$LIST" | awk '{print $1}'`;; #low
			*)	#send signal
				KILL_SIGNAL="`echo "$ACTION" | cut -d ' ' -f 3`"
				TMP="-`echo "$KILL_SIGNAL" | cut -d " " -f 1`"
				if [  $TMP = "-0" ]; then TMP=""; fi
				kill $TMP `echo "$LIST" | awk '{print $1}'`
		esac
		;;
	-set_filter)
		echo "$FILTER_STRING" > /tmp/pprocess-filter
		;;
	-filter)
		ps > /tmp/pprocess-ps_source
		FILTER_STRING=($(<"/tmp/pprocess-filter"))
		grep -i "$FILTER_STRING" /tmp/pprocess-ps_source > /tmp/pprocess-ps
		;;
	-logfile)
		if [ $LOG_FILE = top ]; then
			rxvt -name pburn -bg black -fg green -geometry 80x20 -title "Pprocess - $(gettext 'Running processes')" -e top
		fi
		Xdialog --title "Pprocess" --fixed-font --no-ok --cancel-label "$(gettext 'Cancel')" --tailbox $LOG_FILE 500x500
		;;

esac
