How to open files from better_errors with RubyMine on Linux

Updated . Posted . Visible to the public.

I recently noticed that better_errors allows you to to open files from within your favorite editor Show archive.org snapshot . However it was not so easy to get rubymine:// links to work on Gnome/Linux. Here is how it finally worked for me:

Step 1: Add a Desktop launcher Show archive.org snapshot

Add this file to ~/.local/share/applications/rubymine.desktop:

[Desktop Entry]
Version=1.0
Type=Application
Encoding=UTF-8
Name=Rubymine
Exec=sh -c '/snap/bin/rubymine ${0#"rubymine://"}' %u
Terminal=false
StartupNotify=false
Categories=Application;
MimeType=x-scheme-handler/rubymine;

Note the Exec madness:

  • You might have to adjust the path to match your executable (which rubymine) depending on how you have installed rubymine
  • RubyMine does not know how to handle arguments like rubymine://Gemfile. We have to strip the protocol
  • The rubymine:// prefix is thus stripped from %u using some weird shell parameter expansion Show archive.org snapshot syntax

Step 2: Map the rubymine mime type to the new launcher

Add the following to ~/.config/mimeapps.list:

x-scheme-handler/rubymine=rubymine.desktop

Step 3: Test your desktop entry

  • Does gio mime x-scheme-handler/rubymine suggest Registered applications: rubymine.desktop?
  • Does xdg-open "rubymine:///etc/hosts" open the hosts-file in RubyMine?

Step 4: Tell better_errors to use your opener

The BETTER_ERRORS_EDITOR_URL Show archive.org snapshot environment variable can be used to tweak better_errors:

export BETTER_ERRORS_EDITOR_URL="rubymine://%{file_unencoded}"

Step 5: Try it out!

Restart your server (in a new terminal!) and add a raise statement to your local application.Does better_errors link to your file system?
Make sure that better_errors is at least on Version 2.9 or newer, the BETTER_ERRORS_EDITOR_URL variable was introduced in 2020.

Image

Michael Leimstädtner
Last edit
Michael Leimstädtner
License
Source code in this card is licensed under the MIT License.
Posted by Michael Leimstädtner to makandra dev (2023-06-29 14:08)