I wrote a ridiculously simple file template service menu installer for Plasma/Dolphin. This isn’t a difficult job to do manually but I use it a lot and this makes it really fast. Perhaps someone might find this useful so I thought I’d share it.
It will overwrite the template of the same name so it’s a bit of a sharp knife. I prefer this because I can fix a bite or two, right click, and push the updated template into place.
I have a folder of templates in my development directory. Each template has a folder that looks similar to this:
/.class.cpp /class.h /.desktop.desktop:
[General]
Name=
Comment=
Category=C++/Qt
Language=C++
Type=Class
Files=Header,Implementation[Header]
Name=Public Header
File=class.h
OutputFile={{ name }}.h[Implementation]
Name=Implementation
File=class.cpp
OutputFile={{ name }}.cpp
The service menu consists of two parts:
~/.local/bin/KDevFileTemplateInstall
#!/bin/bash
TEMPLATE=$1
TMP=/tmp
TEMPLATES_FILE=~/.local/share/kdevfiletemplates/templates/
DIR=$(basename “$TEMPLATE”)
PATH_TEMPLATE=$(dirname “$TEMPLATE”)pwd >> /tmp/temp.log
echo “$1” >> /tmp/temp.logif [ -d “$TEMPLATE” ]; then
if compgen -G "$TEMPLATE"/*.desktop > /dev/null; then tar -cvjf "$TMP/$DIR.tar.bz2" -C "$PATH_TEMPLATE/$DIR" . mv "$TMP/$DIR.tar.bz2" "$TEMPLATES_FILE" else echo "$1 is not a template directory" fi
else
echo "$1 is not a directory or does not exist"
fi
~/.local/share/kio/servicemenus
[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=inode/directory
Actions=InstallTemplate[Desktop Action InstallTemplate]
Name=Install as KDevelop File Template
Icon=folder
Exec=KDevFileTemplateInstall “%f”
I hope this helps someone.