Picking OneDrive folders to sync from the Omarchy bar: building a shell plugin in an hour

Picking OneDrive folders to sync from the Omarchy bar: building a shell plugin in an hour

I keep about 45 root folders in OneDrive and want five of them on my Linux laptop. The abraunegg onedrive client handles that with a sync_list file, but changing the selection is a chore: stop the service, edit the file, run a resync, delete the folder you no longer want, start the service again.

So I built an Omarchy shell plugin that turns the whole routine into a list of checkboxes. This post covers what it does, how it was built, and how little it takes to write a plugin for the Omarchy shell.

An Omarchy desktop with the OneDrive Folders panel open under its cloud icon in the bar

What it does

A cloud icon sits in the bar. Clicking it opens a panel that lists every root folder in the OneDrive account, with the locally synced ones checked.

  • Check a folder to start syncing it.
  • Uncheck a folder to stop syncing it and delete its local copy.
  • Press Apply changes. Unchecking needs a second press to confirm the delete.

Nothing runs in the background. The folder list is fetched each time the panel opens, and while a sync is in flight the list is locked.

The plugin is a front end only. The onedrive client still does all the syncing.

How it was built

I built it with Claude Code, using the Omarchy skill that ships with the distribution. The prompt was one line: make me a new Omarchy shell plugin, ask me what it should do, build it following the plugin guide, and enable it. From there it was a conversation: two rounds of questions, then code.

The plugin is five files and 499 lines:

File Lines Purpose
Panel.qml 317 The bar button and the panel
onedrive-folders 135 Bash helper that does the actual work
manifest.json 22 Tells the shell what the plugin is
test.sh 13 Checks the sync_list rewrite
i18n/en.json 12 The strings

The manifest

A plugin is a directory under ~/.config/omarchy/plugins/<author>.<name>/ with a manifest.json. This one declares a single bar widget:

{
  "schemaVersion": 1,
  "id": "techpreacher.onedrive-folders",
  "name": "OneDrive Folders",
  "version": "1.0.0",
  "kinds": ["bar-widget"],
  "entryPoints": { "barWidget": "Panel.qml" },
  "barWidget": {
    "displayName": "OneDrive Folders",
    "category": "Status",
    "defaultSection": "right"
  }
}

The helper

All the logic lives in a bash script, so the QML stays a thin view and the risky parts can be tested from a terminal.

onedrive-folders list prints JSON for the panel. The onedrive client has no command to list remote folders, so the helper asks Microsoft Graph directly. It exchanges the client's own refresh token for an access token and requests the children of the drive root. The refresh token goes from its file straight to login.microsoftonline.com through curl --data-urlencode "refresh_token@file", so it never appears in a process argument list.

onedrive-folders apply --add NAME --remove NAME changes the selection. It launches itself as a detached unit with systemd-run --user, so a shell reload cannot kill it halfway. The unit then does this, in order:

  1. Stops onedrive.service if it is running.
  2. Syncs each folder that is being removed one last time, so pending local changes are uploaded.
  3. Rewrites sync_list, keeping the old one as sync_list.prev.
  4. Runs onedrive --sync --resync --resync-auth, which the client demands after a sync_list change.
  5. Deletes the local copies of unchecked folders.
  6. Starts the service again if it was running before.

The order matters. Deleting a folder while the service is running, or while the folder is still in sync_list, would delete it in OneDrive too. The local delete therefore happens last, after the resync has succeeded with the folder already excluded.

Two guards came out of thinking about what could go wrong:

  • The helper refuses to empty sync_list. An empty file turns selective sync off, and the client would start downloading the whole account.
  • Folder names arrive from the network and end up in rm -rf. They are validated, passed as arguments and never interpolated into a command, and the delete target must resolve to a direct child of the sync directory.

The panel

Omarchy's shell is built on Quickshell, and plugins are QML. The shell's own UI kit in qs.Ui does most of the work. The skeleton of the panel is this:

import qs.Commons
import qs.Ui

Panel {
  id: root
  moduleName: "techpreacher.onedrive-folders"
  ipcTarget: "techpreacher.onedrive-folders"

  onOpenedChanged: if (opened) refresh()

  Process {
    id: listProc
    command: [root.helper, "list"]
    stdout: StdioCollector { onStreamFinished: root.folders = JSON.parse(text).folders }
  }

  BarIconButton {
    id: button
    bar: root.bar
    text: "󰅟"
    onPressed: root.toggle()
  }

  KeyboardPanel {
    anchorItem: button
    owner: root
    open: root.opened
    content: PanelKeyCatcher { /* hero, status line, Apply button, folder rows */ }
  }
}

Panel gives open, close and toggle plus an IPC target. KeyboardPanel supplies the popup that grows out of the bar icon. PanelHero, CursorSurface and Button give the header, the hover rows and the Apply button, all in the current theme. I wrote no colors, no animation and no window code.

Checkbox clicks are only staged in the panel. Nothing touches the system until Apply, which matters because every apply costs a full resync.

What went wrong along the way

Three things, all small:

  • omarchy plugin enable failed on the first try. The shell had not finished rescanning the new directory. Running it again a few seconds later worked.
  • The list was cut off on my smaller monitor. I had nested a fixed-height scroll area inside the panel. Making the whole panel one Flickable, the way Omarchy's own Dropbox panel does, fixed it.
  • The first real apply showed an error immediately. The helper writes a failure marker when an apply starts and removes it on success, and the panel displayed that marker while the apply was still running. The apply itself was fine. The marker is now ignored while anything is in flight.

The first two were caught by opening the panel with omarchy-shell <plugin-id> open and taking a screenshot. The third I found by using it.

How easy is it to write an Omarchy plugin?

Easier than I expected. A few things make it so:

  • Hot reload. Saving any file under ~/.config/omarchy/plugins/ reloads the plugin. There is no build step and no shell restart.
  • A real UI kit. Panels, buttons, toggles, text fields and confirm dialogs already exist and already follow the theme, the animation settings and right-to-left layouts.
  • Working examples on disk. Every built-in panel is readable QML under /usr/share/omarchy/shell/plugins/. The Dropbox panel was my template.
  • Tooling. omarchy plugin validate <dir> checks the manifest, omarchy plugin enable <id> --section right puts the widget on the bar, and omarchy plugin clone copies a built-in plugin into your config to modify.
  • Translations for free. Strings go in i18n/en.json and are read through Commons.Translations. Adding a language is one more JSON file.

The one thing to take seriously: plugins run unsandboxed inside the long-lived shell process. Omarchy's plugin guide is direct about this. Set textFormat: Text.PlainText on any text that shows outside data, bound and validate what you read from the network, and never build a shell command out of it.

Where it is published

Omarchy has no plugin store that I could find. A plugin is published as a public git repository with manifest.json at its root, and omarchy plugin add installs straight from the URL.

The plugin is here: https://github.com/TechPreacher/omarchy-onedrive-folders

It is MIT licensed. A small GitHub Actions workflow runs the helper's test on every push.

Installing it

You need Omarchy, the abraunegg onedrive client signed in, and a sync_list with at least one entry. Then:

omarchy plugin add https://github.com/TechPreacher/omarchy-onedrive-folders.git --enable

omarchy plugin add clones the repository, validates it, and warns you that plugins are arbitrary code. Read the code before you say yes; it is short.

To update or remove it:

omarchy plugin update techpreacher.onedrive-folders
omarchy plugin remove techpreacher.onedrive-folders

Caveats

This is version 1.0.0 and it has had light use:

  • Tested with onedrive v2.5.12 on one personal Microsoft account.
  • Adding a folder has been run for real. Removing a folder follows the steps above but has not been exercised yet, so try it first on a folder you can afford to re-download.
  • Root folders only, and English only for now.

If you sync OneDrive selectively on Omarchy, give it a try. And if you have a small annoyance of your own that involves a terminal and four commands in the right order, it is probably a plugin.

→ Disclaimer