Skip to content

Instantly share code, notes, and snippets.

@leminhtr
Last active May 11, 2020 21:10
Show Gist options
  • Save leminhtr/23eb232203b70be7cf44a2f230d59795 to your computer and use it in GitHub Desktop.
Save leminhtr/23eb232203b70be7cf44a2f230d59795 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Resolve the location of the Pycharm installation.
# This includes resolving any symlinks.
PRG=$0
while [ -h "$PRG" ]; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
if expr "$link" : '^/' 2> /dev/null >/dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
PYCHARM_BIN=`dirname "$PRG"`
PYCHARM_BIN='Zotero_linux'
# absolutize dir
oldpwd=`pwd`
cd "${PYCHARM_BIN}"
PYCHARM_BIN=`pwd`
cd "${oldpwd}"
# Get an png of the icon to use for the application and replace this line by the filename
ICON_FILE_NAME=zotero_icon.png
# Replace "pycharm" by the name of the application
XDG_ICON_NAME=zotero-eap
TMP_DIR=`mktemp --directory`
DESKTOP_FILE=$TMP_DIR/zotero-eap.desktop
cat << EOF > $DESKTOP_FILE
[Desktop Entry]
Version=1.0
Encoding=UTF-8
# Edit name to use in menu
Name=Zotero
Type=Application
Categories=Research;Bibliography;Article;
Terminal=false
StartupNotify=true
StartupWMClass=zotero
Exec="$PYCHARM_BIN/zotero" %u
MimeType=x-scheme-handler/$XDG_ICON_NAME;
Icon=$XDG_ICON_NAME.png
EOF
xdg-desktop-menu install $DESKTOP_FILE
xdg-icon-resource install --size 128 "$PYCHARM_BIN/$ICON_FILE_NAME" $XDG_ICON_NAME
rm $DESKTOP_FILE
rm -R $TMP_DIR
MENU_DESKTOP_FOLDER='.local/share/applications'
echo "$XDG_ICON_NAME.desktop desktop entry has been added to $HOME/$MENU_DESKTOP_FOLDER/."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment