From 7dee587ceb3f1969e003c2d556b9d2733aa82400 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Sun, 29 Mar 2020 16:46:38 +0200 Subject: [PATCH] Adding workingdir patch --- README.md | 5 ++++- patches.def.h | 5 +++++ x.c | 24 ++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2e45d54..53063b6 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the ### Changelog: -2020-03-29 - Added invert patch +2020-03-29 - Added invert and workingdir patches 2020-03-24 - Upgraded to latest (master) of st (commit 51e19ea11dd42eefed1ca136ee3f6be975f618b1 at the time of writing). Custom changes to make the altscreen mouse scollback patch working. @@ -113,6 +113,9 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the - [visualbell](https://st.suckless.org/patches/visualbell/) - adds visual indicators for the terminal bell event + - [workingdir](https://st.suckless.org/patches/workingdir/) + - allows user to specify the initial path st should use as the working directory + - [xresources](https://st.suckless.org/patches/xresources/) - adds the ability to configure st via Xresources - during startup, st will read and apply the resources named in the resources[] array in config.h diff --git a/patches.def.h b/patches.def.h index 92ac931..c3cb76e 100644 --- a/patches.def.h +++ b/patches.def.h @@ -196,6 +196,11 @@ */ #define VISUALBELL_3_PATCH 0 +/* This patch allows user to specify the initial path st should use as the working directory. + * https://st.suckless.org/patches/workingdir/ + */ +#define WORKINGDIR_PATCH 0 + /* This patch adds the ability to configure st via Xresources. At startup, st will read and * apply the resources named in the resources[] array in config.h. * https://st.suckless.org/patches/xresources/ diff --git a/x.c b/x.c index ab8daf0..b37cef1 100644 --- a/x.c +++ b/x.c @@ -284,6 +284,9 @@ static char *opt_io = NULL; static char *opt_line = NULL; static char *opt_name = NULL; static char *opt_title = NULL; +#if WORKINGDIR_PATCH +static char *opt_dir = NULL; +#endif // WORKINGDIR_PATCH static int oldbutton = 3; /* button event on startup: 3 = release */ #if VISUALBELL_1_PATCH && !VISUALBELL_2_PATCH && !VISUALBELL_3_PATCH @@ -2410,11 +2413,19 @@ run(void) void usage(void) { - die("usage: %s [-aiv] [-c class] [-f font] [-g geometry]" + die("usage: %s [-aiv] [-c class]" + #if WORKINGDIR_PATCH + " [-d path]" + #endif // WORKINGDIR_PATCH + " [-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]" + " %s [-aiv] [-c class]" + #if WORKINGDIR_PATCH + " [-d path]" + #endif // WORKINGDIR_PATCH + " [-f font] [-g geometry]" " [-n name] [-o file]\n" " [-T title] [-t title] [-w windowid] -l line" " [stty_args ...]\n", argv0, argv0); @@ -2439,6 +2450,11 @@ main(int argc, char *argv[]) case 'c': opt_class = EARGF(usage()); break; + #if WORKINGDIR_PATCH + case 'd': + opt_dir = EARGF(usage()); + break; + #endif // WORKINGDIR_PATCH case 'e': if (argc > 0) --argc, ++argv; @@ -2497,6 +2513,10 @@ run: xinit(cols, rows); xsetenv(); selinit(); + #if WORKINGDIR_PATCH + if (opt_dir && chdir(opt_dir)) + die("Can't change to working directory %s\n", opt_dir); + #endif // WORKINGDIR_PATCH run(); return 0;