Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use $VISUAL and $EDITOR env vars for editor selection #22

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

daemonp
Copy link
Contributor

@daemonp daemonp commented May 4, 2024

Description

This pull request modifies the Edit function in the editor package to use the standard *nix convention of VISUAL and EDITOR environment variables for selecting the text editor.

Motivation and Context

Currently, the Edit function always uses the DefaultEditor, which is hardcoded as "nano". This limits the flexibility for users who prefer to use a different text editor.

Changes

  • Check if the VISUAL environment variable is set using os.Getenv("VISUAL"). If it is set, use its value as the editor.
  • If VISUAL is not set, check if the EDITOR environment variable is set using os.Getenv("EDITOR"). If it is set, use its value as the editor.
  • If neither VISUAL nor EDITOR is set, fall back to using the DefaultEditor, which is set to "nano".

Verified

  • Tested the modified code by setting the VISUAL environment variable to a different editor (e.g., "vim") and verified that the specified editor was used when calling the Edit function.
  • Tested the case when neither VISUAL nor EDITOR is set and confirmed that it falls back to using "nano" as the default editor.

Checklist

  • Tested the changes locally
  • Updated the code to follow the standard *nix convention
  • Provided clear commit message and pull request description

Please review and provide any feedback or suggestions for improvement.

This commit modifies the Edit function in the editor package to use
the standard UNIX convention of $VISUAL and $EDITOR environment variables
for selecting the text editor. If $VISUAL is set, it takes precedence.
If $VISUAL is not set but EDITOR is set, $EDITOR is used. If neither is
set, it falls back to using the default editor, which is set to "nano".

This allows users to customize their preferred text editor by setting
the $VISUAL or $EDITOR environment variable, following the common
convention in UNIX-based systems.
Copy link
Owner

@adzimzf adzimzf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
thank you so much for your contribution.

i'll merge the PR and release it,
you can upgrade the brew.

@adzimzf adzimzf merged commit c5a57fa into adzimzf:master Jun 24, 2024
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.

2 participants