* but if you are using another shell this runs only in bash*
you can take advantage of arrays using bash
(I credited amigo in a prior thread for the code base and pasted the original code a few posts ago )* I will include a diff patch for clarity
I put a safety in there all files get generated in /tmp/desktop
so if you are happy with the results you could manually copy over the
old desktops (thats your call) the user woud have to repackage all the packages with the new desktops to do the job right
I replaced the underscore with the "+" because some files may use underscore in names
Code: Select all
#!/bin/bash
make a template of all the desktops and lets you view them in /tmp/desktops
so none of your original desktops get overwritten
builds an array for speeding up any scripts that search info from the desktop
now all your desktops will have a format and an organized template
the first line is [Desktop Entry],Name,Icon,Categories,Exec,Comment
and thats what you will expect to see when you search the desktops for info
#[Desktop Entry]
#Name=AbiWord
#Icon=/usr/share/icons/abiword_48.png
#Categories=Application;Office;WordProcessor;GNOME;GTK;X-Red-Hat-Base;
#Exec=abiword
#Comment=Compose, edit, and view documents
# make a template of the desktops regenerate all desktops to the new simple template
# removes poorly formatted desktops and creates a standard which allows later for easy reading of strings
# into an array to speed up scripts since the newly generated desktops maintain a standard format
# less commands are needed to filter data for output this is where all the time is wasted
# having to parse poorly formatted files from the start if you have organized files
# everything is fast and easy to parse the code
:>arraytest.txt
mkdir -p /tmp/desktops
for DESKTOP_FILE in /usr/share/applications/* ; do
#for DESKTOP_FILE in /usr/share/applications/Editra.desktop ; do
while read LINE ; do
case $LINE in
Name=*) NAME="${LINE[@]}"'|' ;;
Icon=*) ICON="${LINE[@]}"'|' ;;
#Terminal=*)
#Type=*)
Categories=*) CATS="${LINE[@]}"'|' ;;
Exec=*) EXEC="${LINE[@]}"'|' ;;
Comment=*) COMM="${LINE[@]}"'|' ;;
esac
done < $DESKTOP_FILE
echo $NAME$ICON$CATS$EXEC
# To test the extract function below, use the following line instead of above
# fixes spaces in the string names by replacing them with a "+" making a correctly formatted array
echo '[Desktop+Entry]|'$NAME$ICON$CATS$EXEC$COMM | tr ' ' '+' >>arraytest.txt
#uncomment if you want to generate all new desktops in /temp/desktops
echo '[Desktop+Entry]|'$NAME$ICON$CATS$EXEC$COMM | tr ' ' '+' | tr '| ' ' ' | tr ' ' '\n' | tr '+' ' '>/tmp/desktops/`basename $DESKTOP_FILE`
done