From 04df93df58c35ce73f8c9998d5b7156da059f562 Mon Sep 17 00:00:00 2001 From: Mathieu Ablasou Date: Wed, 9 Aug 2023 19:46:06 +0200 Subject: [PATCH] Prefer `VISUAL` to `EDITOR` --- docs/manual.md | 17 +++++++++++++++-- src/env.cr | 1 + src/main.cr | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/docs/manual.md b/docs/manual.md index 66f14e9..48dd7d2 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -91,6 +91,18 @@ drop 'The Fool.png' This shell script is opened in an editor for you to review. After you close it, it will be executed. +### Editor configuration + +By default, batch uses whatever you’ve set as your default text editor via one of the `VISUAL` or `EDITOR` environment variables, or else falls back to the vi editor to process items. + +To change that default to something else, you can use the `--editor` option: + +``` sh +batch -e vim +``` + +Now, no matter what is set as your default shell editor, batch will fire up Vim to process items. + ### Advanced usage batch lets you apply external filters—such as [tr], [sed] or [awk][gawk]—before invoking the editor: @@ -141,7 +153,7 @@ Here is my personal configuration: ``` sh # interactive map imap() { - batch -e 'kak -n' -f 'iconv -f UTF-8 -t ASCII//TRANSLIT//IGNORE' -f 'tr [:upper:] [:lower:]' -f "tr -s \\'[:blank:] -" -f 'tr -d ?!,' "$@" + batch -e kak -f 'iconv -f UTF-8 -t ASCII//TRANSLIT//IGNORE' -f 'tr [:upper:] [:lower:]' -f "tr -s \\'[:blank:] -" -f 'tr -d ?!,' "$@" } # auto map @@ -216,7 +228,7 @@ Specifies the shell script to run on deleted items. Specifies the editor to use. -Default is fetch from the `EDITOR` environment variable. +Default is fetch from the `VISUAL` environment variable, then the `EDITOR` environment variable, and then the default chosen at compile time, which is usually `vi`. ###### `-f ` ###### `--filter=` @@ -258,6 +270,7 @@ Show version. The following environment variables have an effect on `batch`. +###### VISUAL ###### EDITOR Configures the default text editor. diff --git a/src/env.cr b/src/env.cr index a74520b..65239d2 100644 --- a/src/env.cr +++ b/src/env.cr @@ -1 +1,2 @@ ENV["EDITOR"] ||= "vi" +ENV["VISUAL"] ||= ENV["EDITOR"] diff --git a/src/main.cr b/src/main.cr index 6838163..740718a 100644 --- a/src/main.cr +++ b/src/main.cr @@ -9,7 +9,7 @@ VERSION = {{ `git describe --tags --always`.chomp.stringify }} pick_command = Command.new("echo") map_command = Command.new("echo") drop_command = Command.new("echo") -editor_command = Command.parse(ENV["EDITOR"]) +editor_command = Command.parse(ENV["VISUAL"]) filter_commands = Array(Command).new edit = true pick = true