summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcelo Lira <setanta@gmail.com>2025-03-02 06:04:17 -0300
committerMarcelo Lira <setanta@gmail.com>2025-03-03 16:12:29 -0300
commitaaabc50e3267871d1619bfe4f565187f08524a1f (patch)
tree6d58934e399e6a7bf51762c710696ef25173a9bb
parent5d8c9d1f5183e56a8563fc93eba8d7d4a8f842dd (diff)
workingdir
This patch allows user to specify the initial path st should use as WD (working directory). https://st.suckless.org/patches/workingdir/
-rw-r--r--st.18
-rw-r--r--x.c15
2 files changed, 19 insertions, 4 deletions
diff --git a/st.1 b/st.1
index 57ddfb8..acb4c2a 100644
--- a/st.1
+++ b/st.1
@@ -6,6 +6,8 @@ st \- simple terminal
.RB [ \-aiv ]
.RB [ \-c
.IR class ]
+.RB [ \-d
+.IR path ]
.RB [ \-f
.IR font ]
.RB [ \-g
@@ -32,6 +34,8 @@ st \- simple terminal
.RB [ \-aiv ]
.RB [ \-c
.IR class ]
+.RB [ \-d
+.IR path ]
.RB [ \-f
.IR font ]
.RB [ \-g
@@ -62,6 +66,10 @@ disable alternate screens in terminal
.BI \-c " class"
defines the window class (default $TERM).
.TP
+.BI \-d " path"
+changes the working directory to
+.IR path .
+.TP
.BI \-f " font"
defines the
.I font
diff --git a/x.c b/x.c
index 1fda75b..e0eb263 100644
--- a/x.c
+++ b/x.c
@@ -270,6 +270,7 @@ static char *opt_io = NULL;
static char *opt_line = NULL;
static char *opt_name = NULL;
static char *opt_title = NULL;
+static char *opt_dir = NULL;
static uint buttons; /* bit field of pressed buttons */
static int cursorblinks = 0;
@@ -2727,12 +2728,12 @@ reload(int sig)
void
usage(void)
{
- die("usage: %s [-aiv] [-c class] [-f font] [-g geometry]"
- " [-n name] [-o file]\n"
+ die("usage: %s [-aiv] [-c class] [-d path] [-f font]"
+ " [-g geometry] [-n name] [-o file]\n"
" [-T title] [-t title] [-w windowid]"
" [[-e] command [args ...]]\n"
- " %s [-aiv] [-c class] [-f font] [-g geometry]"
- " [-n name] [-o file]\n"
+ " %s [-aiv] [-c class] [-d path] [-f font]"
+ " [-g geometry] [-n name] [-o file]\n"
" [-T title] [-t title] [-w windowid] -l line"
" [stty_args ...]\n", argv0, argv0);
}
@@ -2793,6 +2794,9 @@ main(int argc, char *argv[])
if (!(defaultfontsize > 0))
usage();
break;
+ case 'd':
+ opt_dir = EARGF(usage());
+ break;
default:
usage();
} ARGEND;
@@ -2804,6 +2808,9 @@ run:
if (!opt_title)
opt_title = (opt_line || !opt_cmd) ? "st" : opt_cmd[0];
+ if (opt_dir && chdir(opt_dir) != 0)
+ die("can't change into directory %s\n", opt_dir);
+
setlocale(LC_CTYPE, "");
XSetLocaleModifiers("");
xrdb_load();