Skip to content

Bash script to create PHPStorm shortcut and a symbolic link in Ubuntu

Bash script to create PHPStorm shortcut and a symbolic link in Ubuntu

In this bash script file, the PHPSTORM_PATH variable is defined at the top of the script and is used to define the path to the PHPStorm binary ($PHPSTORM_PATH/bin/phpstorm.sh) and the path to the icon file ($PHPSTORM_PATH/bin/phpstorm.png). This makes it easy to change the path to the PHPStorm installation directory by simply changing the value of the PHPSTORM_PATH variable.

Just copy and paste the content to a new text file with an extension “.sh”. Make it executable

Don’t forget to change the “/path/to/phpstorm” at line 4 with your own path

#!/bin/bash

# Define the path to the PHPStorm binary
#PHPSTORM_PATH=/home/*username*/Apps/PhpStorm-233.14475.35
PHPSTORM_PATH=/path/to/phpstorm

# Define the path to the desktop file directory
DESKTOP_DIR=$HOME/.local/share/applications

# Define the PHPStorm binary
PHPSTORM_BIN=$PHPSTORM_PATH/bin/phpstorm.sh

# Define the path to the icon file
ICON_PATH=$PHPSTORM_PATH/bin/phpstorm.png

# Define the symbolic link path
SYMLINK_PATH=/usr/local/bin/phpstorm

# Define the desktop file path
DESKTOP_FILE=$DESKTOP_DIR/phpstorm.desktop

# Check if the symbolic link already exists
if [ -L "$SYMLINK_PATH" ]; then
    echo "Symbolic link already exists. Renaming it to phpstorm.old."
    sudo mv -f "$SYMLINK_PATH" "${SYMLINK_PATH}.old"
fi

# Create the symbolic link
sudo ln -s $PHPSTORM_BIN $SYMLINK_PATH

# Check if the desktop file already exists
if [ -f "$DESKTOP_FILE" ]; then
    echo "Desktop file already exists. Renaming it to phpstorm.old.desktop."
    mv "$DESKTOP_FILE" "${DESKTOP_FILE}.old"
fi

# Create the desktop file
echo "[Desktop Entry]
Name=PHPStorm
Comment=PHP IDE
Exec=$SYMLINK_PATH
Icon=$ICON_PATH
Terminal=false
Type=Application
Categories=Development;" > $DESKTOP_FILE

# Set the permissions for the desktop file
chmod +x $DESKTOP_FILE

echo "Done."

Note: Please check the quotes when you paste the script so the content is imported correctly.

Views: 13

Leave a Reply

Your email address will not be published. Required fields are marked *