Skip to content

Commit d6c80b5

Browse files
committed
use uniform logic for selecting between 'vi' or 'editor'
1 parent babaf13 commit d6c80b5

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

src/defaults/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ use settings_dsl::{
2121
result_of, storage_of,
2222
};
2323

24+
pub const SYSTEM_EDITOR: &str = if cfg!(target_os = "linux") {
25+
"/usr/bin/editor"
26+
} else {
27+
"/usr/bin/vi"
28+
};
29+
2430
defaults! {
2531
always_query_group_plugin = false #ignored
2632
always_set_home = false #ignored
@@ -54,7 +60,7 @@ defaults! {
5460
passwd_timeout = (5*60) (!= 0) {fractional_minutes}
5561
timestamp_timeout = (15*60) (!= 0) {fractional_minutes}
5662

57-
editor = "/usr/bin/editor"
63+
editor = SYSTEM_EDITOR
5864
env_editor = true
5965

6066
env_keep = ["COLORS", "DISPLAY", "HOSTNAME", "KRB5CCNAME", "LS_COLORS", "PATH",

src/sudoers/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,7 @@ fn select_editor(settings: &Settings, trusted_env: bool) -> PathBuf {
345345

346346
// fallback on hardcoded path -- always provide something to the caller
347347

348-
PathBuf::from(if cfg!(target_os = "linux") {
349-
"/usr/bin/editor"
350-
} else {
351-
"/usr/bin/vi"
352-
})
348+
PathBuf::from(defaults::SYSTEM_EDITOR)
353349
}
354350

355351
// a `take_while` variant that does not consume the first non-matching item

src/visudo/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,7 @@ fn edit_sudoers_file(
273273
sudoers.visudo_editor_path(&host_name, &current_user, &current_user)
274274
} else {
275275
// there is no /etc/sudoers config yet, so use a system default
276-
PathBuf::from(if cfg!(target_os = "linux") {
277-
"/usr/bin/editor"
278-
} else {
279-
"/usr/bin/vi"
280-
})
276+
PathBuf::from(crate::defaults::SYSTEM_EDITOR)
281277
};
282278

283279
loop {

0 commit comments

Comments
 (0)