Read more

How to open files from better_errors with RubyMine on Linux

Michael Leimstädtner
June 29, 2023Software engineer at makandra GmbH

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

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more 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

Posted by Michael Leimstädtner to makandra dev (2023-06-29 16:08)