vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit f8283f3ea6b752eea40c47df3dc6c87316338338
parent 20beb12580ccbc5fd2373e1f55b497b65087cd6c
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sun,  3 Apr 2016 19:54:42 +0200

sam: implement cd (change directory) command

Diffstat:
Msam.c | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/sam.c b/sam.c @@ -9,6 +9,7 @@ #include <stdio.h> #include <ctype.h> #include <errno.h> +#include <unistd.h> #include "sam.h" #include "vis-core.h" #include "buffer.h" @@ -87,6 +88,7 @@ static bool cmd_write(Vis*, Win*, Command*,const char *argv[], Cursor*, Filerang static bool cmd_read(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*); static bool cmd_edit(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*); static bool cmd_quit(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*); +static bool cmd_cd(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*); /* vi(m) commands */ static bool cmd_set(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*); static bool cmd_open(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*); @@ -131,6 +133,7 @@ static const CommandDef cmds[] = { { { "}" }, 0, NULL, NULL }, { { "e" }, CMD_FILE|CMD_FORCE, NULL, cmd_edit }, { { "q" }, CMD_FORCE, NULL, cmd_quit }, + { { "cd" }, CMD_ARGV, NULL, cmd_cd }, /* vi(m) related commands */ { { "bdelete" }, CMD_FORCE, NULL, cmd_bdelete }, { { "help" }, 0, NULL, cmd_help }, @@ -1129,4 +1132,11 @@ static bool cmd_pipeout(Vis *vis, Win *win, Command *cmd, const char *argv[], Cu return !vis->cancel_filter && status == 0; } +static bool cmd_cd(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) { + const char *dir = argv[1]; + if (!dir) + dir = getenv("HOME"); + return chdir(dir) == 0; +} + #include "vis-cmds.c"