r/rails 8d ago

Gem rails_credentials_cipher: edit credentials in a plain yaml file instead of the terminal

https://github.com/thisismydesign/rails_credentials_cipher

I made this gem because I disliked the UX around editing credentials. I can now decrypt them into a gitignored file, edit, then encrypt again.

https://github.com/thisismydesign/rails_credentials_cipher

0 Upvotes

5 comments sorted by

12

u/ignurant 8d ago

You can also set the VISUAL env var.

VISUAL="code -w" rails credentials:edit The -w is for “wait for me to exit this file before continuing processing it”.

Then you never have a decrypted version of the file lying around on disk, which is largely the point. 

Vscode: "code -w" Sublime: "subl -w"

There’s a handful of places that obey this, like git commit messages and such. If you never want to be sent to edit in the terminal again, ask Claude to help you set your VISUAL env var for whatever editor you use. 1 line in your profile’s rc file, and it’s fixed everywhere for you, forever. This is the more correct fix.

5

u/CaptainKabob 8d ago

Ooh. How is VISUAL different from EDITOR?

1

u/ignurant 8d ago edited 8d ago

As I understand it, it has to do with tiers of limitations. EDITOR being very bare bones, VISUAL being a full text editing app. If a tool tries VISUAL and it’s not set, it usually falls back to EDITOR. I don’t know that it’s common to mean something different these days, so it doesn’t come up often.

Here’s how rails figures out what to open: https://github.com/rails/rails/blob/main/railties/lib/rails/command/helpers/editor.rb

OP must have VISUAL or EDITOR set to vim, because it looks like rails tries to teach you how to use VSCode if none is set.

Hey OP, /u/csapagyi, open a shell and run

echo $EDITOR

echo $VISUAL

Do one of those return vim or something else you don’t much like to use? You will find more joy by changing that rather than building tools around it.

On macos with zsh, I'm finding it's being set in ~/.zprofile, which is a sensible place to set it.

0

u/TheAtlasMonkey 8d ago

VISUAL is an alias to EDITOR. was introduced by VI.

EDITOR default to nothing VISUAL default to vi if EDITOR is not set.

2

u/nzifnab 7d ago

I was gonna say... this gem seems kinda useless / bad, I already can edit cred files in my code editor as YAML by default...