commit b565d9af9ac6a511f450f2d5faeaf550a7375bb6
parent 5430cf2a0f9d07b6f5084c60bb06821e9545d337
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Sat, 20 Jan 2024 09:14:01 -0800
Add root command
This command shows and sets the working directory. Since aps has
no knowledge of filesystems and such, items are left as is. This
may or may not change in the future.
Diffstat:
4 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/aps/command.c b/aps/command.c
@@ -25,6 +25,7 @@
#include <regex.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include "aps.h"
#include "arg.h"
@@ -301,3 +302,17 @@ com_close(struct aps *aps, int fd, int argc, char **argv)
{
return aps_unname(aps) ? errstr : NULL;
}
+
+char *
+com_root(struct aps *aps, int fd, int argc, char **argv)
+{
+ char buf[PATH_MAX];
+
+ if (!getwd(buf))
+ return errstr;
+ if (aps_bufline(aps, fd, buf))
+ return errstr;
+ if (argc && chdir(argv[0]))
+ return errstr;
+ return NULL;
+}
diff --git a/aps/command.h b/aps/command.h
@@ -21,3 +21,4 @@ char *com_stop(struct aps *, int, int, char **);
char *com_terminate(struct aps *, int, int, char **);
char *com_toggle(struct aps *, int, int, char **);
char *com_truncate(struct aps *, int, int, char **);
+char *com_root(struct aps *, int, int, char **);
diff --git a/aps/config.h b/aps/config.h
@@ -20,6 +20,7 @@ static struct command commands[] = {
{ "player", com_player },
{ "previous", com_previous },
{ "remove", com_remove },
+ { "root", com_root },
{ "seek", com_seek },
{ "status", com_status },
{ "stop", com_stop },
diff --git a/man/aps.1 b/man/aps.1
@@ -91,6 +91,10 @@ Remove the items matching
.Ar pattern
from the queue, returning the items removed. If no pattern is
given, remove only the current item.
+.It Cm root Op Ar path
+Return the current working directory and change it to
+.Ar path
+if given.
.It Cm seek Ar pattern
Seek to the first item which matches
.Ar pattern .