Skip to content

Instantly share code, notes, and snippets.

@Guts
Last active March 28, 2024 10:25
Show Gist options
  • Save Guts/bc7d883922676ab14f857ed951b3a583 to your computer and use it in GitHub Desktop.
Save Guts/bc7d883922676ab14f857ed951b3a583 to your computer and use it in GitHub Desktop.
Bash script to quickly set up QGIS to develop a plugin.
#!/bin/sh
set -e
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <git remote> <git local folder>" >&2
echo "Example: $0 [email protected]:Oslandia/qgis/qompligis.git /tmp/qgis_dev" >&2
exit 1
fi
# variables to change to fit your environment
GIT_REMOTE=$1
GIT_LOCAL_FOLDER=$2
# main
git clone $GIT_REMOTE $GIT_LOCAL_FOLDER
# parent folder of folder containing the plugin folder - did you get it? ;)
PLG_FOLDER_PATH=$(realpath $(dirname $(dirname $(find $GIT_LOCAL_FOLDER -name metadata.txt -type f))))
# plugin parent folder name (used by QGIS to enable/disable a plugin)
PLG_FOLDER_NAME=$(basename $PLG_FOLDER_PATH)
# extract plugin name
PLG_NAME=$(find $GIT_LOCAL_FOLDER -name metadata.txt -type f -exec grep -Hn "name=" {} \;| cut -d = -f 2)
# set default profile
# seule différence : -i n'a pas le même comportement sur gnu sed (utilisé majoritairement sur linux) et bsd/posix sed (sur bsd et dérivés dont macos)
# sed -i ... n'est pas possible sur posix sed. Il faut définir une extension, même vide (exemple '' ou '.bak', mais cela s'écrit sed -i '' et sur gnu sed: sed -i'' note l'espace)
sed "s|^defaultProfile=.*|defaultProfile=plg_$PLG_NAME|" ~/.local/share/QGIS/QGIS3/profiles/profiles.ini > /tmp/profiles.ini
mv /tmp/profiles.ini ~/.local/share/QGIS/QGIS3/profiles/profiles.ini
# create profile configuration path and file
mkdir -v -p ~/.local/share/QGIS/QGIS3/profiles/plg_"$PLG_NAME"/QGIS/
touch ~/.local/share/QGIS/QGIS3/profiles/plg_"$PLG_NAME"/QGIS/QGIS3.ini
# customize QGIS: disable noisy things and enable plugin
echo "[core]\nNewsFeed\httpsfeedqgisorg\disabled=true" >> ~/.local/share/QGIS/QGIS3/profiles/plg_"$PLG_NAME"/QGIS/QGIS3.ini
echo "\n[PythonPlugins]\n$PLG_FOLDER_NAME=true" >> ~/.local/share/QGIS/QGIS3/profiles/plg_"$PLG_NAME"/QGIS/QGIS3.ini
echo "\n[qgis]\ncustomEnvVars=overwrite|QGIS_PLUGINPATH=${PLG_FOLDER_PATH}" >> ~/.local/share/QGIS/QGIS3/profiles/plg_"$PLG_NAME"/QGIS/QGIS3.ini
echo "customEnvVarsUse=true" >> ~/.local/share/QGIS/QGIS3/profiles/plg_"$PLG_NAME"/QGIS/QGIS3.ini
echo "checkVersion=false\n" >> ~/.local/share/QGIS/QGIS3/profiles/plg_"$PLG_NAME"/QGIS/QGIS3.ini
# launch QGIS withtou blocking the shell
nohup qgis --profile "plg_$PLG_NAME" &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment