From 994c19d263f9c64c79b64e26099c4a625c161242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sun, 3 Apr 2016 19:54:42 +0200 Subject: sam: implement cd (change directory) command --- sam.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'sam.c') diff --git a/sam.c b/sam.c index 282825f..0b04b55 100644 --- a/sam.c +++ b/sam.c @@ -9,6 +9,7 @@ #include #include #include +#include #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" -- cgit v1.2.3