aboutsummaryrefslogtreecommitdiff
path: root/sam.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-03 19:54:42 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-03 21:38:05 +0200
commit994c19d263f9c64c79b64e26099c4a625c161242 (patch)
treea8234d0fc37852dbf791bd22bdc6a0f084c58097 /sam.c
parenta547e3053bf112206452e56b919806bf4c9d575f (diff)
downloadvis-994c19d263f9c64c79b64e26099c4a625c161242.tar.gz
vis-994c19d263f9c64c79b64e26099c4a625c161242.tar.xz
sam: implement cd (change directory) command
Diffstat (limited to 'sam.c')
-rw-r--r--sam.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/sam.c b/sam.c
index 282825f..0b04b55 100644
--- 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"