I use the rich text editor in Nextcloud a lot, and it can be opened through a sub-menu of the context menu in the GNOME file manager.
You can only open one file at a time, and requires a few clicks and moving the mouse around.
Now, if we could have a simple command to open the Nextcloud editor, for one or more file?
Having a look at the GNOME Files extension, it wasn’t that complicated.
This script will open a file in the Nextcloud editor, if the file is managed:
#!/bin/sh
SOCKET="$XDG_RUNTIME_DIR/Nextcloud/socket"
test -S "$SOCKET" || exit 1
ask() {
echo "$*" | nc -U -q1 "$SOCKET"
}
dirs="$( ask VERSION | sed -n -e '/^REGISTER_PATH:/s///p' )"
for f; do
f="$( realpath "$f" )"
echo "$dirs" |
while read dir; do
if expr "$f" : "$dir/" >/dev/null; then
ask "EDIT:$f" >/dev/null
fi
done
done
The only dependency is netcat(1) — the nc command to talk to a socket.
The command
$ ncedit a.md b.md c.md
will then open three browser windows with the three files, if they’re managed by Nextcloud.
File manager integration
Adding this script as an application for text/markdown files requires a desktop file and a few commands.
If the above script is in /usr/local/bin/ncedit save this as ~/.local/share/applications/ncedit.desktop:
[Desktop Entry]
Type=Application
Name=NC Edit
Exec=/usr/local/bin/ncedit %F
Terminal=false
NoDisplay=true
Icon=Nextcloud
Keywords=text;editor
MimeType=text/markdown
And the run the two commands:
$ update-mime-database ~/.local/share/applications
$ update-desktop-database ~/.local/share/applications
You might have to restart GNOME Files for it to appear.
Now you can select one or more Markdown files in the file manager, and open them with Nextcloud, as if it was a local application.
Leave a Reply