Skip to content

Linux port: open a file named on the command line, not just a folder - #2

Open
e-c-hansen wants to merge 1 commit into
mainfrom
feat/open-file-from-cli
Open

Linux port: open a file named on the command line, not just a folder#2
e-c-hansen wants to merge 1 commit into
mainfrom
feat/open-file-from-cli

Conversation

@e-c-hansen

Copy link
Copy Markdown
Owner

minicode notes/todo.md ignored the file and opened the current directory instead, so the only way to reach a file from a shell was to pass its parent folder and then click.

What changed

argv[1] now accepts either form:

  • a directory becomes the sidebar root, as before
  • a file is opened in the editor, with the sidebar rooted at the directory holding it, so its neighbours are still listed

Markdown arrives rendered, because this goes through the same openFileCb a sidebar click uses.

The half that was easy to miss

Passing the file was only part of the problem. GApplication is single-instance, so a second minicode <path> typed while a window was already open handed off to the running process and dropped the argument entirely — the command did nothing at all. That is the state most people are in, since the editor tends to stay open.

Registering HANDLES_COMMAND_LINE and reading argv in the command-line handler fixes it: the running instance re-roots its sidebar, opens the file, and raises its window. HANDLES_OPEN would have been shorter but it insists on treating the argument as a file, and a directory has to keep working.

Two details only show up in that remote case:

  • the path is resolved against the cwd reported by the command line object rather than getcwd, or a relative ../thing would resolve against the cwd of whichever process owns the window
  • no such file or directory goes out via g_application_command_line_printerr, so it lands on the terminal the user typed in rather than the other process's stderr

A path that does not exist still opens the sidebar on its parent, so a mistyped filename lands in the right folder.

Verification

On a private session bus: a directory as the first launch; a relative file path from a second invocation resolving correctly against the caller's cwd; a directory from a second invocation re-rooting; and a missing path reporting back to the caller. Launching with a Markdown file argument stays alive and renders. meson test passes.

BUILD-LINUX.md is updated, including the "Sudden second copy of the app?" section that documented the old limitation.

Not included

The macOS build has the same gap — src/main.mm only accepts a directory — and is untouched, since it cannot be built or tested from a Linux machine. Worth a follow-up from a Mac.

Sidebar selection is also not included: the tree is backed by GtkDirectoryList, which enumerates asynchronously, so revealing and selecting the opened file reliably is more than this change needs.

🤖 Generated with Claude Code

`minicode notes/todo.md` ignored the file and opened the current directory
instead, so the only way to get at a file was to pass its parent folder and
then click. argv[1] now accepts either: a directory becomes the sidebar root
as before, and a file is opened in the editor with the sidebar rooted at the
directory holding it, so its neighbours are still listed. Markdown arrives
rendered, because this goes through the same openFileCb a sidebar click does.

Passing the file was only half of it. GApplication is single-instance, so a
second `minicode <path>` typed while a window was already open handed off to
the running process and dropped the argument on the floor: the command did
nothing at all, which is the state most people are in, since the editor tends
to stay open. Registering HANDLES_COMMAND_LINE and reading argv in the
command-line handler fixes that — the running instance re-roots its sidebar,
opens the file and raises its window. HANDLES_OPEN would have been the shorter
route but it insists on treating the argument as a file, and a directory has
to keep working.

Two details that only show up in the remote case. The path is resolved against
the cwd reported by the command line object rather than getcwd, or a relative
`../thing` would be resolved against the cwd of whichever process happens to
own the window. And "no such file or directory" goes out through
g_application_command_line_printerr, so it lands on the terminal the user typed
in instead of the stderr of that other process. A path that does not exist
still opens the sidebar on its parent, so a mistyped filename lands in the
right folder.

Verified on a private session bus: a directory as the first launch, a relative
file path from a second invocation resolving correctly against the caller's
cwd, a directory from a second invocation re-rooting, and a missing path
reporting to the caller. The macOS build has the same gap (src/main.mm only
accepts a directory) and is untouched here, since it cannot be built or tested
from this machine.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant