Update shellMen

Cleaned up code, tried to match bash standards, cleared useless comments.
This commit is contained in:
Maxim 2015-04-15 23:39:00 -05:00
parent 58b354afa4
commit 3e921cfe9f
1 changed files with 53 additions and 71 deletions

124
shellMen
View File

@ -48,46 +48,37 @@ case $menuitem in
esac esac
} }
commandInsert(){ commandInsert(){
x=$(cat /tmp/sysMENU/menu.list | wc -l) >> /dev/null ; # Variable set to number of lines filled in list.txt x=$(cat /tmp/sysMENU/menu.list | wc -l) >> /dev/null ;
i="1" i="1"
while [ $i -le $x ]; do while [ $i -le $x ]; do
line1=$(sed -n "${i}p" /tmp/sysMENU/menu.list); # Reads the number of lines in list.txt then sets as a variable counting up to variable x line1=$(sed -n "${i}p" /tmp/sysMENU/menu.list);
filename="${line1%.*}" filename="${line1%.*}"
execMethod=$(grep -A 0 "Exec=" /usr/share/applications/"$line1") execMethod=$(grep -A 0 "Exec=" /usr/share/applications/"$line1")
catagory=$(grep -A 0 "Categories=" /usr/share/applications/"$line1") catagory=$(grep -A 0 "Categories=" /usr/share/applications/"$line1")
preComment=$(grep -A 0 "Comment=" /usr/share/applications/"$line1") preComment=$(grep -A 0 "Comment=" /usr/share/applications/"$line1")
execCMD=$(echo "${filename}) exec ${filename} ;;") execCMD=$(echo "${filename}) exec ${filename} ;;")
if [[ "$catagory" == *"$accss"* ]] || [[ "$catagory" == *"$util"* ]]; then if [[ "$catagory" == *"$accss"* ]] || [[ "$catagory" == *"$util"* ]]; then
echo "$execCMD" >> /tmp/sysMENU/${accss}.sh echo "$execCMD" >> /tmp/sysMENU/${accss}.sh
fi elif [[ "$catagory" == *"$dev"* ]]; then
if [[ "$catagory" == *"$dev"* ]]; then echo "$execCMD" >> /tmp/sysMENU/${dev}.sh
echo "$execCMD" >> /tmp/sysMENU/${dev}.sh elif [[ "$catagory" == *"$gme"* ]]; then
fi echo "$execCMD" >> /tmp/sysMENU/${gme}.sh
if [[ "$catagory" == *"$gme"* ]]; then elif [[ "$catagory" == *"$int"* ]] || [[ "$catagory" == *"$net"* ]] ; then
echo "$execCMD" >> /tmp/sysMENU/${gme}.sh echo "$execCMD" >> /tmp/sysMENU/${int}.sh
fi elif [[ "$catagory" == *"$graph"* ]]; then
if [[ "$catagory" == *"$int"* ]] || [[ "$catagory" == *"$net"* ]] ; then echo "$execCMD" >> /tmp/sysMENU/${graph}.sh
echo "$execCMD" >> /tmp/sysMENU/${int}.sh elif [[ "$catagory" == *"$offce"* ]]; then
fi echo "$execCMD" >> /tmp/sysMENU/${offce}.sh
if [[ "$catagory" == *"$graph"* ]]; then elif [[ "$catagory" == *"$media*" ]] \
echo "$execCMD" >> /tmp/sysMENU/${graph}.sh || [[ "$catagory" == *"$vid"* ]] \
fi || [[ "$catagory" == *"$audio"* ]]; then
if [[ "$catagory" == *"$offce"* ]]; then echo "$execCMD" >> /tmp/sysMENU/${media}.sh
echo "$execCMD" >> /tmp/sysMENU/${offce}.sh elif [[ "$catagory" == *"$sys"* ]]; then
fi echo "$execCMD" >> /tmp/sysMENU/${sys}.sh
if [[ "$catagory" == *"$media*" ]] \ elif [[ "$catagory" == *"$settngs"* ]]; then
|| [[ "$catagory" == *"$vid"* ]] \ echo "$execCMD" >> /tmp/sysMENU/${settngs}.sh
|| [[ "$catagory" == *"$audio"* ]]; then elif [[ "$catagory" == *"$wine"* ]]; then
echo "$execCMD" >> /tmp/sysMENU/${media}.sh echo "$execCMD" >> /tmp/sysMENU/${wine}.sh
fi
if [[ "$catagory" == *"$sys"* ]]; then
echo "$execCMD" >> /tmp/sysMENU/${sys}.sh
fi
if [[ "$catagory" == *"$settngs"* ]]; then
echo "$execCMD" >> /tmp/sysMENU/${settngs}.sh
fi
if [[ "$catagory" == *"$wine"* ]]; then
echo "$execCMD" >> /tmp/sysMENU/${wine}.sh
fi fi
i=$[$i++1]; i=$[$i++1];
done done
@ -102,7 +93,7 @@ echo "esac" >> /tmp/sysMENU/${sys}.sh
echo "esac" >> /tmp/sysMENU/${settngs}.sh echo "esac" >> /tmp/sysMENU/${settngs}.sh
echo "esac" >> /tmp/sysMENU/${wine}.sh echo "esac" >> /tmp/sysMENU/${wine}.sh
chmod +x /tmp/sysMENU/*.sh chmod +x /tmp/sysMENU/*.sh
mainMENU mainMENU;
} }
menuHeaderInsert(){ menuHeaderInsert(){
x=$(cat /tmp/sysMENU/menu.list | wc -l) >> /dev/null ; # Variable set to number of lines filled in list.txt x=$(cat /tmp/sysMENU/menu.list | wc -l) >> /dev/null ; # Variable set to number of lines filled in list.txt
@ -116,36 +107,27 @@ preComment=$(grep -A 0 "Comment=" /usr/share/applications/"$line1")
comment=$(sed s/"Comment="//g <<< ${preComment}) comment=$(sed s/"Comment="//g <<< ${preComment})
inputer=$(echo "$filename "\"$comment"\" \\") inputer=$(echo "$filename "\"$comment"\" \\")
if [[ "$catagory" == *"$accss"* ]] || [[ "$catagory" == *"$util"* ]]; then if [[ "$catagory" == *"$accss"* ]] || [[ "$catagory" == *"$util"* ]]; then
echo "$inputer" >> /tmp/sysMENU/${accss}.sh echo "$inputer" >> /tmp/sysMENU/${accss}.sh
fi elif [[ "$catagory" == *"$dev"* ]]; then
if [[ "$catagory" == *"$dev"* ]]; then echo "$inputer" >> /tmp/sysMENU/${dev}.sh
echo "$inputer" >> /tmp/sysMENU/${dev}.sh elif [[ "$catagory" == *"$gme"* ]]; then
fi echo "$inputer" >> /tmp/sysMENU/${gme}.sh
if [[ "$catagory" == *"$gme"* ]]; then elif [[ "$catagory" == *"$int"* ]] || [[ "$catagory" == *"$net"* ]] ; then
echo "$inputer" >> /tmp/sysMENU/${gme}.sh echo "$inputer" >> /tmp/sysMENU/${int}.sh
fi elif [[ "$catagory" == *"$graph"* ]]; then
if [[ "$catagory" == *"$int"* ]] || [[ "$catagory" == *"$net"* ]] ; then echo "$inputer" >> /tmp/sysMENU/${graph}.sh
echo "$inputer" >> /tmp/sysMENU/${int}.sh elif [[ "$catagory" == *"$offce"* ]]; then
fi echo "$inputer" >> /tmp/sysMENU/${offce}.sh
if [[ "$catagory" == *"$graph"* ]]; then elif [[ "$catagory" == *"$media*" ]] \
echo "$inputer" >> /tmp/sysMENU/${graph}.sh || [[ "$catagory" == *"$vid"* ]] \
fi || [[ "$catagory" == *"$audio"* ]]; then
if [[ "$catagory" == *"$offce"* ]]; then echo "$inputer" >> /tmp/sysMENU/${media}.sh
echo "$inputer" >> /tmp/sysMENU/${offce}.sh elif [[ "$catagory" == *"$sys"* ]]; then
fi echo "$inputer" >> /tmp/sysMENU/${sys}.sh
if [[ "$catagory" == *"$media*" ]] \ elif [[ "$catagory" == *"$settngs"* ]]; then
|| [[ "$catagory" == *"$vid"* ]] \ echo "$inputer" >> /tmp/sysMENU/${settngs}.sh
|| [[ "$catagory" == *"$audio"* ]]; then elif [[ "$catagory" == *"$wine"* ]]; then
echo "$inputer" >> /tmp/sysMENU/${media}.sh echo "$inputer" >> /tmp/sysMENU/${wine}.sh
fi
if [[ "$catagory" == *"$sys"* ]]; then
echo "$inputer" >> /tmp/sysMENU/${sys}.sh
fi
if [[ "$catagory" == *"$settngs"* ]]; then
echo "$inputer" >> /tmp/sysMENU/${settngs}.sh
fi
if [[ "$catagory" == *"$wine"* ]]; then
echo "$inputer" >> /tmp/sysMENU/${wine}.sh
fi fi
i=$[$i++1]; i=$[$i++1];
done done
@ -193,7 +175,7 @@ echo "$endMenuInsert" >> /tmp/sysMENU/${wine}.sh
echo "$menuitmVar" >> /tmp/sysMENU/${wine}.sh echo "$menuitmVar" >> /tmp/sysMENU/${wine}.sh
echo "$preCMD" >> /tmp/sysMENU/${wine}.sh echo "$preCMD" >> /tmp/sysMENU/${wine}.sh
echo "$menuCall" >> /tmp/sysMENU/${wine}.sh echo "$menuCall" >> /tmp/sysMENU/${wine}.sh
commandInsert commandInsert;
} }
startScan() { startScan() {
clear clear
@ -212,9 +194,9 @@ sys="System"
settngs="Settings" settngs="Settings"
wine="Wine" wine="Wine"
mkdir /tmp/sysMENU mkdir /tmp/sysMENU
touch /tmp/sysMENU/menu.list ; # Creates a temp txt file called menu.list in the temp folder of root touch /tmp/sysMENU/menu.list ;
sed -i "d" /tmp/sysMENU/menu.list ; # Clears the file menu.list to rcv new info sed -i "d" /tmp/sysMENU/menu.list ;
ls /usr/share/applications/ >> /tmp/sysMENU/menu.list ; # lists current dir files to menu.list ls /usr/share/applications/ >> /tmp/sysMENU/menu.list ;
header=$(echo "#!/bin/bash header=$(echo "#!/bin/bash
INPUT=/tmp/menu.txt INPUT=/tmp/menu.txt
dialog --clear --backtitle "\"Shellmen"\" \\ dialog --clear --backtitle "\"Shellmen"\" \\
@ -231,13 +213,13 @@ echo "$header" > /tmp/sysMENU/${media}.sh
echo "$header" > /tmp/sysMENU/${sys}.sh echo "$header" > /tmp/sysMENU/${sys}.sh
echo "$header" > /tmp/sysMENU/${settngs}.sh echo "$header" > /tmp/sysMENU/${settngs}.sh
echo "$header" > /tmp/sysMENU/${wine}.sh echo "$header" > /tmp/sysMENU/${wine}.sh
menuHeaderInsert menuHeaderInsert;
} }
pre(){ pre(){
if [ -d /tmp/sysMENU/ ]; then if [ -d /tmp/sysMENU/ ]; then
mainMENU mainMENU;
else else
startScan startScan;
fi fi
} }
pre pre;