Page 1 of 2

Register extensions and make menu-entry for PB

Posted: Wed May 21, 2014 7:50 pm
by ts-soft
This small script register mime-type for: *.pb, *.pbi, *.pbf and make a menu-entry on any
freedesktop.org compatible distribution (tested on ubuntu, CentOS and some others)!

Before you can use this script, you have to install purebasic with methode 1, described in install.

Script:

Code: Select all

#!/bin/bash

# Goto home
cd $HOME
# Make sure, dir exist
mkdir -p .local/share/mime/packages
# change to dir for purebasic.xml
cd .local/share/mime/packages
# purebasic.xml create
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > purebasic.xml
echo "<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>" >> purebasic.xml
echo "	<mime-type type=\"text/purebasic\">" >> purebasic.xml
echo "		<comment>PureBasic source code</comment>" >> purebasic.xml
echo "		<glob pattern=\"*.pb\"/>" >> purebasic.xml
echo "		<glob pattern=\"*.pbi\"/>" >> purebasic.xml
echo "		<glob pattern=\"*.pbf\"/>" >> purebasic.xml
echo "	</mime-type>" >> purebasic.xml
echo "</mime-info>" >> purebasic.xml

# change to home
cd $HOME
# Make sure, dir exist
mkdir -p .local/share/applications
# change to dir for PureBasic.desktop
cd .local/share/applications
# PureBasic.desktop create
echo "[Desktop Entry]" > PureBasic.desktop
echo "Comment=PureBasic IDE" >> PureBasic.desktop
echo "Terminal=false" >> PureBasic.desktop
echo "Name=PureBasic" >> PureBasic.desktop
echo "Type=Application" >> PureBasic.desktop
echo "MimeType=text/purebasic" >> PureBasic.desktop
echo "Categories=Development;" >> PureBasic.desktop
# check environment var
if [ "$PUREBASIC_HOME" == "" ]
then
	echo "Exec=${HOME}/purebasic/compilers/purebasic" >> PureBasic.desktop
	echo "Icon=${HOME}/purebasic/logo.png" >> PureBasic.desktop
else
	echo "Exec=${PUREBASIC_HOME}/compilers/purebasic" >> PureBasic.desktop
	echo "Icon=${PUREBASIC_HOME}/logo.png" >> PureBasic.desktop
fi

# Update Databases
update-desktop-database ~/.local/share/applications
update-mime-database    ~/.local/share/mime
After saving, don't forget to make the script executable and run it as user (no root required!)

Download script

Greetings - Thomas

// Update:
you will find this script in your purebasic-dir (>=PB540B9) as "register.sh" :wink:

Re: Register extensions and make menu-entry for PB

Posted: Wed May 21, 2014 9:43 pm
by idle
nice one. I should make this sticky

Re: Register extensions and make menu-entry for PB

Posted: Wed May 21, 2014 10:18 pm
by ts-soft
you're welcome :D
idle wrote:I should make this sticky
Please, do it :wink:

Re: Register extensions and make menu-entry for PB

Posted: Fri May 23, 2014 9:12 pm
by ts-soft
Update:
Uses envvar "PUREBASIC_HOME", if var was set.

Re: Register extensions and make menu-entry for PB

Posted: Fri Nov 28, 2014 11:49 am
by Little John
Very useful.
Thanks a lot, Thomas :!:

Re: Register extensions and make menu-entry for PB

Posted: Thu Sep 03, 2015 1:46 pm
by oldefoxx
That's quite a script! I copied it to a file I named PBlinker.sh. Now I am going to have to make time to go through it and make sure it is compatible with my PureBasic tree of folders. I'm forced to arrange things by folders just to get some sence of order to everything I have downloaded from several sites. I really appreciate your having gone to all this effort!

Re: Register extensions and make menu-entry for PB

Posted: Mon Sep 28, 2015 2:11 am
by fsw
Awesome :!:

Added one more entry:

Code: Select all

echo "StartupNotify=true" >> PureBasic.desktop
just before:

Code: Select all

# check environment var
With this addition you can add PureBasic to your favorites in GNOME 3 :mrgreen:
(mouse/trackpad right click on PureBasic icon inside favorites bar while app is running...)

Sweet 8)

Re: Register extensions and make menu-entry for PB

Posted: Mon Sep 28, 2015 1:41 pm
by Fred
Do you mind if I include it in the PB package ?

Re: Register extensions and make menu-entry for PB

Posted: Mon Sep 28, 2015 2:00 pm
by ts-soft
Please, do it. It's make the installation easier and more comfortable!

After over 1 year testing, it work's with all distris, i have used.

Re: Register extensions and make menu-entry for PB

Posted: Mon Sep 28, 2015 2:25 pm
by Fred
Should it be run automatically in the ./launch script, or should it be a seperate file ?

Re: Register extensions and make menu-entry for PB

Posted: Mon Sep 28, 2015 3:11 pm
by ts-soft
I think, a seperate file is better.

Re: Register extensions and make menu-entry for PB

Posted: Mon Sep 28, 2015 3:19 pm
by Fred
Ok, thanks. Added for the next beta :)

Re: Register extensions and make menu-entry for PB

Posted: Sun Oct 18, 2015 12:54 pm
by lakomet
If the script is in the folder distribution

Code: Select all

# check environment var
if [ "$PUREBASIC_HOME" == "" ]
then
   echo "Exec=${HOME}/purebasic/compilers/purebasic" >> PureBasic.desktop
   echo "Icon=${HOME}/purebasic/logo.png" >> PureBasic.desktop
else
   echo "Exec=${PUREBASIC_HOME}/compilers/purebasic" >> PureBasic.desktop
   echo "Icon=${PUREBASIC_HOME}/logo.png" >> PureBasic.desktop
fi
Can be replaced by

Code: Select all

#!/bin/bash
 
ABSOLUTE_FILENAME=`readlink -e "$0"`
DIRECTORY=`dirname "$ABSOLUTE_FILENAME"`

# Goto home
cd $HOME
# Make sure, dir exist
mkdir -p .local/share/mime/packages
# change to dir for purebasic.xml
cd .local/share/mime/packages
# purebasic.xml create
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > purebasic.xml
echo "<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>" >> purebasic.xml
echo "   <mime-type type=\"text/purebasic\">" >> purebasic.xml
echo "      <comment>PureBasic source code</comment>" >> purebasic.xml
echo "      <glob pattern=\"*.pb\"/>" >> purebasic.xml
echo "      <glob pattern=\"*.pbi\"/>" >> purebasic.xml
echo "      <glob pattern=\"*.pbf\"/>" >> purebasic.xml
echo "   </mime-type>" >> purebasic.xml
echo "</mime-info>" >> purebasic.xml

# change to home
cd $HOME
# Make sure, dir exist
mkdir -p .local/share/applications
# change to dir for PureBasic.desktop
cd .local/share/applications
# PureBasic.desktop create
echo "[Desktop Entry]" > PureBasic.desktop
echo "Comment=PureBasic IDE" >> PureBasic.desktop
echo "Terminal=false" >> PureBasic.desktop
echo "Name=PureBasic" >> PureBasic.desktop
echo "Type=Application" >> PureBasic.desktop
echo "MimeType=text/purebasic" >> PureBasic.desktop
echo "Categories=Development;" >> PureBasic.desktop
echo "Exec=${DIRECTORY}/compilers/purebasic" >> PureBasic.desktop
echo "Icon=${DIRECTORY}/logo.png" >> PureBasic.desktop

# Update Databases
update-desktop-database ~/.local/share/applications
update-mime-database    ~/.local/share/mime

Re: Register extensions and make menu-entry for PB

Posted: Thu Jan 12, 2017 12:42 pm
by pwd
Added *.pbp to the list of extensions and cleaned ts-soft's version a bit:

Code: Select all

#!/bin/bash

###############################################################################
DIR_MIME=".local/share/mime"
FILE_MIME="purebasic.xml"

# go home
cd $HOME

# make sure dir exist
mkdir -p $DIR_MIME/packages

# change dir
cd $DIR_MIME/packages

# create extension.xml
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<mime-info xmlns=\"http://www.freedesktop.org/standards/shared-mime-info\">
	<mime-type type=\"text/purebasic\">
		<comment>PureBasic source code</comment>
		<glob pattern=\"*.pb\"/>
		<glob pattern=\"*.pbi\"/>
		<glob pattern=\"*.pbf\"/>
		<glob pattern=\"*.pbp\"/>
	</mime-type>
</mime-info>" > $FILE_MIME

###############################################################################
DIR_APPS=".local/share/applications"
FILE_APPS="PureBasic.desktop"

# go home
cd $HOME

# make sure dir exist
mkdir -p $DIR_APPS

# change dir
cd $DIR_APPS

# create application.desktop
echo "[Desktop Entry]
Comment=PureBasic IDE
Terminal=false
Name=PureBasic
Type=Application
MimeType=text/purebasic
Categories=Development;
StartupNotify=true" > $FILE_APPS

# check environment var
if [ "$PUREBASIC_HOME" == "" ]
then
	echo "Exec=${HOME}/purebasic/compilers/purebasic" >> $FILE_APPS
	echo "Icon=${HOME}/purebasic/logo.png" >> $FILE_APPS
else
	echo "Exec=${PUREBASIC_HOME}/compilers/purebasic" >> $FILE_APPS
	echo "Icon=${PUREBASIC_HOME}/logo.png" >> $FILE_APPS
fi

chmod +x $FILE_APPS
###############################################################################

# update databases
update-mime-database ~/$DIR_MIME
update-desktop-database ~/$DIR_APPS

echo "File extensions (.pb, .pbi, .pbf, .pbp) are now registered for PureBasic"

Re: Register extensions and make menu-entry for PB

Posted: Sun May 28, 2017 7:31 pm
by fryquez
If I run the Purebasic 5.60 included register.sh on my Ubuntu Mate 17.04,
I get an error: register.sh: 36: [: unexpected operator