I'm trying to edit the rails credentials file, like so.
EDITOR="subl --wait" bin/rails credentials:edit
# Editing config/credentials.yml.enc...
# File encrypted and saved.
The file loads in sublime, however it encrypts and saves immediately without giving me chance to edit the file. Why is this? What do I need to do to ensure I can edit and save the file?
I can confirm the sublime is in my path:
which subl
# /usr/local/bin/subl
** UPDATE **
I have discovered, setting the editor has no effect. The credentials open in sublime no matter:
# Each results in credentials opening in sublime
EDITOR="subl --wait" bin/rails credentials:edit
EDITOR="nano --wait" bin/rails credentials:edit
EDITOR="vim --wait" bin/rails credentials:edit
While you did not specify your rails version, based on your symptoms I am going to guess that you are using Rails 7.1 or greater, and also have an environment variable set for "VISUAL"
This Commit. Added the following:
def editor
ENV["VISUAL"].to_s.empty? ? ENV["EDITOR"] : ENV["VISUAL"]
end
For the stated reason of:
Support
VISUAL
environment variable for commands which open an editor, and prefer it overEDITOR
.
Since your EDITOR
variable is being ignored regardless of its contents I believe this is your issue.
To test this theory you can either inspect your environment for the VISUAL
variable (which seems to be set to subl
) or try calling VISUAL="subl --wait" bin/rails credentials:edit
and see if it works.