Register extensions and make menu-entry for PB

Linux specific forum
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Register extensions and make menu-entry for PB

Post 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:
Last edited by ts-soft on Sat Oct 10, 2015 12:30 pm, edited 2 times in total.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
idle
Always Here
Always Here
Posts: 5038
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Register extensions and make menu-entry for PB

Post by idle »

nice one. I should make this sticky
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Register extensions and make menu-entry for PB

Post by ts-soft »

you're welcome :D
idle wrote:I should make this sticky
Please, do it :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Register extensions and make menu-entry for PB

Post by ts-soft »

Update:
Uses envvar "PUREBASIC_HOME", if var was set.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Register extensions and make menu-entry for PB

Post by Little John »

Very useful.
Thanks a lot, Thomas :!:
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Re: Register extensions and make menu-entry for PB

Post 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!
has-been wanna-be (You may not agree with what I say, but it will make you think).
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Register extensions and make menu-entry for PB

Post 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)

I am to provide the public with beneficial shocks.
Alfred Hitshock
Fred
Administrator
Administrator
Posts: 16616
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Register extensions and make menu-entry for PB

Post by Fred »

Do you mind if I include it in the PB package ?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Register extensions and make menu-entry for PB

Post 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.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Fred
Administrator
Administrator
Posts: 16616
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Register extensions and make menu-entry for PB

Post by Fred »

Should it be run automatically in the ./launch script, or should it be a seperate file ?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Register extensions and make menu-entry for PB

Post by ts-soft »

I think, a seperate file is better.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Fred
Administrator
Administrator
Posts: 16616
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Register extensions and make menu-entry for PB

Post by Fred »

Ok, thanks. Added for the next beta :)
lakomet
User
User
Posts: 53
Joined: Mon Apr 04, 2011 3:56 am
Location: Russia,Angarsk

Re: Register extensions and make menu-entry for PB

Post 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
Linux Mint Maya(Mate), x86, PureBasic 5.00(5.10b1)
pwd
User
User
Posts: 60
Joined: Thu Sep 06, 2012 9:39 am

Re: Register extensions and make menu-entry for PB

Post 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"
fryquez
Enthusiast
Enthusiast
Posts: 362
Joined: Mon Dec 21, 2015 8:12 pm

Re: Register extensions and make menu-entry for PB

Post 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
Post Reply