From 93c6d6c7a2f8a885a7226b45ff46f214a799b979 Mon Sep 17 00:00:00 2001 From: Antonio Huete Jimenez Date: Fri, 12 Feb 2010 20:15:04 +0100 Subject: [PATCH] hammer - Take in account edition preferences. For viconfig directive, $EDITOR and/or $VISUAL were not taken in account, forcing the editor to vi. --- sbin/hammer/cmd_config.c | 14 +++++++++++--- sbin/hammer/hammer.8 | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/sbin/hammer/cmd_config.c b/sbin/hammer/cmd_config.c index 780e646cec..9a60146616 100644 --- a/sbin/hammer/cmd_config.c +++ b/sbin/hammer/cmd_config.c @@ -108,7 +108,7 @@ hammer_cmd_viconfig(char **av, int ac) struct timeval times[2]; const char *dirpath; struct stat st; - char *runcmd; + char *runcmd, *editor, *tmp; char path[32]; ssize_t n; int fd; @@ -163,7 +163,13 @@ hammer_cmd_viconfig(char **av, int ac) close(fd); utimes(path, times); - asprintf(&runcmd, "vi %s", path); + if ((tmp = getenv("EDITOR")) != NULL || + (tmp = getenv("VISUAL")) != NULL) + editor = strdup(tmp); + else + editor = strdup("vi"); + + asprintf(&runcmd, "%s %s", editor, path); system(runcmd); if (stat(path, &st) < 0) @@ -187,6 +193,8 @@ hammer_cmd_viconfig(char **av, int ac) } bzero(config.config.text + n, sizeof(config.config.text) - n); config_set(dirpath, &config); + free(editor); + free(runcmd); } static void @@ -218,7 +226,7 @@ config_set(const char *dirpath, struct hammer_ioc_config *config) if (ioctl(fd, HAMMERIOC_GET_VERSION, &version) < 0) errx(2, "hammer config: not a HAMMER filesystem!"); if (ioctl(fd, HAMMERIOC_SET_CONFIG, config) < 0) - errx(2, "hammer config: config_set"); + err(2, "hammer config"); close(fd); } diff --git a/sbin/hammer/hammer.8 b/sbin/hammer/hammer.8 index c94429617c..1e8a54439b 100644 --- a/sbin/hammer/hammer.8 +++ b/sbin/hammer/hammer.8 @@ -32,7 +32,7 @@ .\" .\" $DragonFly: src/sbin/hammer/hammer.8,v 1.58 2008/11/13 02:04:27 dillon Exp $ .\" -.Dd January 15, 2010 +.Dd February 12, 2010 .Dt HAMMER 8 .Os .Sh NAME @@ -1177,6 +1177,20 @@ New undo/flush, giving faster sync. .El .El .\".Sh EXAMPLES +.Sh ENVIRONMENT +If the following environment variables exist, they will be used by +.Nm : +.Bl +.It Ev EDITOR +The editor program specified in the variable +.Ev EDITOR +will be invoked instead of the default editor, which is +.Xr vi 1 +.It Ev VISUAL +Same effect as +.Ev EDITOR +variable. +.El .Sh PSEUDO-FILESYSTEM (PFS) NOTES The root of a PFS is not hooked into the primary .Nm HAMMER -- 2.11.4.GIT