#! /bin/bash

if [[ -z ${@:1} || $1 = -help ]]; then
	echo -e "
Cls. Command-Line utility to close running Applications.
	
${LGR}usage : cls [opt]${NC}

opt
-k 		: kill Applications.
-stat : showing list of running applications.

"

exit 0
fi

if [ $1 == -k ]; then

while sleep 1
do
{
list=$(ps -fu mobile | grep 'Application' | awk '{print $2,$8}' | sed -r 's/[/]+/ /g' | awk '{print $1,$NF}' | sort -t ' ' -k2 -f | grep -v "MTerminal" | awk '{print $1}')


for pid in $list; do
kill $pid
done
}
done
fi

if [ $1 == -s ]; then
ps -fu mobile | grep 'Application' | awk '{print $2,$8}' | sed -r 's/[/]+/ /g' | awk '{print $1,$NF}' | sort -t ' ' -k2 -f

fi

exit

