Improved code

This commit is contained in:
Maxim 2019-05-30 18:51:01 -05:00 committed by GitHub
parent bac324c5c9
commit bb2b6a705b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 167 additions and 143 deletions

310
shellMen
View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# #
# By Maxim F. Stewart # By Maxim F. Stewart
# Contact: [1itdominator@gmail.com] # Contact: [maxim2131@gmail.com] OR [gamer1119@gmail.com]
# #
# Copyright 2013 Maxim F. Stewart # Copyright 2013 Maxim F. Stewart
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
@ -18,167 +18,191 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------------------# #---------------------------------------------------------------------------------------#
pre() declare -a menu=("Accessories" "Utility" "Multimedia" "Video" "Audio"
{ "Development" "Game" "Internet" "Network" "Graphics"
accss="Accessories" util="Utility" media="Multimedia" vid="Video" "Office" "System" "Settings" "Wine")
audio="Audio" dev="Development" gme="Game" net="Network"
int="Internet" graph="Graphics" offce="Office" sys="System"
settngs="Settings" wine="Wine" pth="/tmp/sysMENU"
if [ -d "${pth}"/ ]; then mainMENU() {
mainMENU; exec 3>&1; # Custom stream to set variable from dialog
else
startScan; INPUT=$(dialog --clear --backtitle "Shellmen" \
fi --title "[ M A I N - M E N U ]" \
--menu "Please Select An Option" 16 50 15 \
Accessories "General Programs" \
System "Main System Programs" \
Settings "Main System Settings" \
Multimedia "Audio & Video Programs" \
Graphics "Image Programs" \
Games "Gaming Programs" \
Office "Wordprocess & Documents Programs" \
Development "Programing Programs" \
Internet "Various Internet Related Programs" \
Wine "Windows Exe & Program Support" 2>&1 1>&3 )
case $INPUT in
Accessories) bash /tmp/sysMENU/Accessories.sh ;;
System) bash /tmp/sysMENU/System.sh ;;
Settings) bash /tmp/sysMENU/Settings.sh ;;
Multimedia) bash /tmp/sysMENU/Multimedia.sh ;;
Graphics) bash /tmp/sysMENU/Graphics.sh ;;
Games) bash /tmp/sysMENU/Game.sh ;;
Office) bash /tmp/sysMENU/Office.sh ;;
Development) bash /tmp/sysMENU/Development.sh ;;
Internet) bash /tmp/sysMENU/Internet.sh ;;
Wine) bash /tmp/sysMENU/Wine.sh ;;
Exit) echo "Bye!"; break ;;
esac
} }
startScan() commandInsert() {
{ x=$(cat /tmp/sysMENU/menu.list | wc -l) >> /dev/null ;
clear
mkdir "${pth}"
touch "${pth}"/menu.list ;
sed -i "d" "${pth}"/menu.list ;
ls /usr/share/applications/ >> "${pth}"/menu.list ;
header='#!/bin/bash
INPUT=/tmp/menu.txt
dialog --clear --backtitle "Shellmen" \
--title "[ S U B - M E N U ]" \
--menu "Please Select An Option" 15 50 10 \
Main_Menu "Goes To Main Menu" \'
echo "$header" > "${pth}"/${accss}.sh
echo "$header" > "${pth}"/${dev}.sh
echo "$header" > "${pth}"/${gme}.sh
echo "$header" > "${pth}"/${int}.sh
echo "$header" > "${pth}"/${graph}.sh
echo "$header" > "${pth}"/${offce}.sh
echo "$header" > "${pth}"/${media}.sh
echo "$header" > "${pth}"/${sys}.sh
echo "$header" > "${pth}"/${settngs}.sh
echo "$header" > "${pth}"/${wine}.sh
menuHeaderInsert;
}
menuHeaderInsert()
{
x=$(cat "${pth}"/menu.list | wc -l) >> /dev/null ;
i="1" i="1"
while [ $i -le $x ]; do while [ $i -le $x ]; do
# 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);
line1=$(sed -n "${i}p" "${pth}"/menu.list); filename="${line1%.*}"
execMethod=$(grep -A 0 "Exec=" /usr/share/applications/"$line1")
catagory=$(grep -A 0 "Categories=" /usr/share/applications/"$line1")
preComment=$(grep -A 0 "Comment=" /usr/share/applications/"$line1")
execCMD=$(echo "${filename}) exec ${filename} ;;")
if [[ "$catagory" == *"${menu[0]}"* ]] || [[ "$catagory" == *"${menu[1]}"* ]]; then
echo "$execCMD" >> /tmp/sysMENU/"${menu[0]}".sh
elif [[ "$catagory" == *"${menu[2]}"* ]] \
|| [[ "$catagory" == *"${menu[3]}"* ]] \
|| [[ "$catagory" == *"${menu[4]}"* ]]; then
echo "$execCMD" >> /tmp/sysMENU/"${menu[2]}".sh
elif [[ "$catagory" == *"${menu[5]}"* ]]; then
echo "$execCMD" >> /tmp/sysMENU/"${menu[5]}".sh
elif [[ "$catagory" == *"${menu[6]}"* ]]; then
echo "$execCMD" >> /tmp/sysMENU/"${menu[6]}".sh
elif [[ "$catagory" == *"${menu[7]}"* ]] || [[ "$catagory" == *"${menu[8]}"* ]] ; then
echo "$execCMD" >> /tmp/sysMENU/"${menu[7]}".sh
elif [[ "$catagory" == *"${menu[9]}"* ]]; then
echo "$execCMD" >> /tmp/sysMENU/"${menu[8]}".sh
elif [[ "$catagory" == *"${menu[10]}"* ]]; then
echo "$execCMD" >> /tmp/sysMENU/"${menu[10]}".sh
elif [[ "$catagory" == *"${menu[11]}"* ]]; then
echo "$execCMD" >> /tmp/sysMENU/"${menu[11]}".sh
elif [[ "$catagory" == *"${menu[12]}"* ]]; then
echo "$execCMD" >> /tmp/sysMENU/"${menu[12]}".sh
elif [[ "$catagory" == *"${menu[13]}"* ]]; then
echo "$execCMD" >> /tmp/sysMENU/"${menu[13]}".sh
fi
i=$[$i++1];
done
for opt in "${menu[@]}"; do
if [[ opt == "${menu[8]}" ]]; then
opt = ${menu[7]}
fi
if [[ opt == "${menu[3]}" || opt == "${menu[4]}" ]]; then
opt = ${menu[2]}
fi
echo "esac" >> /tmp/sysMENU/"${opt}".sh
done
chmod +x /tmp/sysMENU/*.sh
mainMENU;
}
menuHeaderInsert() {
x=$(cat /tmp/sysMENU/menu.list | wc -l) >> /dev/null ; # Variable set to number of lines filled in list.txt
i="1"
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
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")
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
echo "$inputer" >> "${pth}"/${accss}.sh if [[ "$catagory" == *"${menu[0]}"* ]] || [[ "$catagory" == *"${menu[1]}"* ]]; then
elif [[ "$catagory" == *"$dev"* ]]; then echo "$inputer" >> /tmp/sysMENU/"${menu[0]}".sh
echo "$inputer" >> "${pth}"/${dev}.sh elif [[ "$catagory" == *"${menu[2]}*" ]] \
elif [[ "$catagory" == *"$gme"* ]]; then || [[ "$catagory" == *"${menu[3]}"* ]] \
echo "$inputer" >> "${pth}"/${gme}.sh || [[ "$catagory" == *"${menu[4]}"* ]]; then
elif [[ "$catagory" == *"$int"* ]] || [[ "$catagory" == *"$net"* ]] ; then echo "$inputer" >> /tmp/sysMENU/"${menu[2]}".sh
echo "$inputer" >> "${pth}"/${int}.sh elif [[ "$catagory" == *"${menu[5]}"* ]]; then
elif [[ "$catagory" == *"$graph"* ]]; then echo "$inputer" >> /tmp/sysMENU/"${menu[5]}".sh
echo "$inputer" >> "${pth}"/${graph}.sh elif [[ "$catagory" == *"${menu[6]}"* ]]; then
elif [[ "$catagory" == *"$offce"* ]]; then echo "$inputer" >> /tmp/sysMENU/"${menu[6]}".sh
echo "$inputer" >> "${pth}"/${offce}.sh elif [[ "$catagory" == *"${menu[7]}"* ]] || [[ "$catagory" == *"${menu[8]}"* ]] ; then
elif [[ "$catagory" == *"$media*" ]] \ echo "$inputer" >> /tmp/sysMENU/"${menu[7]}".sh
|| [[ "$catagory" == *"$vid"* ]] \ elif [[ "$catagory" == *"${menu[9]}"* ]]; then
|| [[ "$catagory" == *"$audio"* ]]; then echo "$inputer" >> /tmp/sysMENU/"${menu[9]}".sh
echo "$inputer" >> "${pth}"/${media}.sh elif [[ "$catagory" == *"${menu[10]}"* ]]; then
elif [[ "$catagory" == *"$sys"* ]]; then echo "$inputer" >> /tmp/sysMENU/"${menu[10]}".sh
echo "$inputer" >> "${pth}"/${sys}.sh elif [[ "$catagory" == *"${menu[11]}"* ]]; then
elif [[ "$catagory" == *"$settngs"* ]]; then echo "$inputer" >> /tmp/sysMENU/"${menu[11]}".sh
echo "$inputer" >> "${pth}"/${settngs}.sh elif [[ "$catagory" == *"${menu[12]}"* ]]; then
elif [[ "$catagory" == *"$wine"* ]]; then echo "$inputer" >> /tmp/sysMENU/"${menu[12]}".sh
echo "$inputer" >> "${pth}"/${wine}.sh elif [[ "$catagory" == *"${menu[13]}"* ]]; then
echo "$inputer" >> /tmp/sysMENU/"${menu[13]}".sh
fi fi
i=$[$i++1]; i=$[$i++1];
done done
echo "2>"\"'${INPUT}'"\"" | tee -a "${pth}"/*.sh endMenuInsert=$(echo "2>"\"'${INPUT}'"\"")
echo 'menuitem=$(<"${INPUT}")' | tee -a "${pth}"/*.sh menuitmVar=$(echo 'menuitem=$(<"${INPUT}")')
echo "case \$menuitem in" | tee -a "${pth}"/*.sh preCMD=$(echo "case \$menuitem in")
echo "Main_Menu) exec shellMen ;;" | tee -a "${pth}"/*.sh menuCall=$(echo "Main_Menu) bash /bin/shellMen ;;")
commandInsert;
}
commandInsert() for opt in "${menu[@]}"; do
{ if [[ opt == "${menu[8]}" ]]; then
x=$(cat "${pth}"/menu.list | wc -l) >> /dev/null ; opt = ${menu[7]}
i="1"
while [ $i -le $x ]; do
line1=$(sed -n "${i}p" "${pth}"/menu.list);
filename="${line1%.*}"
execMethod=$(grep -A 0 -m2 "Exec=" /usr/share/applications/"$line1" | tail -n1)
execMethod=$(echo ${execMethod} | sed s/Exec=//g | sed s/%f//g | sed s/Try//g)
catagory=$(grep -A 0 "Categories=" /usr/share/applications/"$line1")
preComment=$(grep -A 0 "Comment=" /usr/share/applications/"$line1")
execCMD=$(echo "${filename}) ${execMethod} & shellMen ;;")
if [[ "$catagory" == *"$accss"* ]] || [[ "$catagory" == *"$util"* ]]; then
echo "$execCMD" >> "${pth}"/${accss}.sh
elif [[ "$catagory" == *"$dev"* ]]; then
echo "$execCMD" >> "${pth}"/${dev}.sh
elif [[ "$catagory" == *"$gme"* ]]; then
echo "$execCMD" >> "${pth}"/${gme}.sh
elif [[ "$catagory" == *"$int"* ]] || [[ "$catagory" == *"$net"* ]] ; then
echo "$execCMD" >> "${pth}"/${int}.sh
elif [[ "$catagory" == *"$graph"* ]]; then
echo "$execCMD" >> "${pth}"/${graph}.sh
elif [[ "$catagory" == *"$offce"* ]]; then
echo "$execCMD" >> "${pth}"/${offce}.sh
elif [[ "$catagory" == *"$media*" ]] \
|| [[ "$catagory" == *"$vid"* ]] \
|| [[ "$catagory" == *"$audio"* ]]; then
echo "$execCMD" >> "${pth}"/${media}.sh
elif [[ "$catagory" == *"$sys"* ]]; then
echo "$execCMD" >> "${pth}"/${sys}.sh
elif [[ "$catagory" == *"$settngs"* ]]; then
echo "$execCMD" >> "${pth}"/${settngs}.sh
elif [[ "$catagory" == *"$wine"* ]]; then
echo "$execCMD" >> "${pth}"/${wine}.sh
fi fi
i=$[$i++1];
if [[ opt == "${menu[3]}" || opt == "${menu[4]}" ]]; then
opt = ${menu[2]}
fi
echo "$endMenuInsert" >> /tmp/sysMENU/"${opt}".sh
echo "$menuitmVar" >> /tmp/sysMENU/"${opt}".sh
echo "$preCMD" >> /tmp/sysMENU/"${opt}".sh
echo "$menuCall" >> /tmp/sysMENU/"${opt}".sh
done done
echo "esac" | tee -a "${pth}"/*.sh
chmod +x "${pth}"/*.sh commandInsert;
mainMENU;
} }
mainMENU() startScan() {
{ clear
mkdir /tmp/sysMENU
touch /tmp/sysMENU/menu.list ;
sed -i "d" /tmp/sysMENU/menu.list ;
ls -p /usr/share/applications/ | grep -v / >> /tmp/sysMENU/menu.list ;
header='''#!/bin/bash
INPUT=/tmp/menu.txt INPUT=/tmp/menu.txt
dialog --clear --backtitle "Shellmen" \ dialog --clear --backtitle "Shellmen" \
--title "[ M A I N - M E N U ]" \ --title "[ S U B - M E N U ]" \
--menu "Please Select An Option" 16 50 15 \ --menu "Please Select An Option" 15 50 10 \
Accessories "General Programs" \ Main_Menu "Goes To Main Menu" \'''
System "Main System Programs" \
Settings "Main System Settings" \ for opt in "${menu[@]}"; do
Multimedia "Audio & Video Programs" \ if [[ opt == "${menu[8]}" ]]; then
Graphics "Image Programs" \ opt = ${menu[7]}
Games "Gaming Programs" \ fi
Office "Wordprocess & Documents Programs" \
Development "Programing Programs" \ if [[ opt == "${menu[3]}" || opt == "${menu[4]}" ]]; then
Internet "Various Internet Related Programs" \ opt = ${menu[2]}
Wine "Windows Exe & Program Support" 2>"${INPUT}" fi
menuitem=$(<"${INPUT}") echo "$header" > /tmp/sysMENU/"${opt}".sh
case $menuitem in done
Accessories) bash "${pth}"/Accessories.sh ;;
System) bash "${pth}"/System.sh ;; menuHeaderInsert;
Settings) bash "${pth}"/Settings.sh ;; }
Multimedia) bash "${pth}"/Multimedia.sh ;;
Graphics) bash "${pth}"/Graphics.sh ;; pre() {
Games) bash "${pth}"/Game.sh ;; if [ -d /tmp/sysMENU/ ]; then
Office) bash "${pth}"/Office.sh ;; mainMENU;
Development) bash "${pth}"/Development.sh ;; else
Internet) bash "${pth}"/Internet.sh ;; startScan;
Wine) bash "${pth}"/Wine.sh ;; fi
Exit) echo "Bye!"; break ;;
esac
} }
pre; pre;