st-workingdir-20200317-51e19ea.diff (2395B)
1 From ae14b869d7bc0e0cd8ed16157837ad09aaacacc0 Mon Sep 17 00:00:00 2001 2 From: David Gricar <coppie@protonmail.com> 3 Date: Tue, 17 Mar 2020 13:38:05 +0100 4 Subject: [PATCH] Add switch to provide initial working directory 5 6 This patch adds -p switch which takes one argument 'path' and can be 7 used to set the initial working directory of the new st instance. 8 It acts the same as running 'cd path' command after starting the st 9 instance. 10 --- 11 st.1 | 8 ++++++++ 12 x.c | 13 +++++++++---- 13 2 files changed, 17 insertions(+), 4 deletions(-) 14 15 diff --git a/st.1 b/st.1 16 index e8d6059..a901122 100644 17 --- a/st.1 18 +++ b/st.1 19 @@ -6,6 +6,8 @@ st \- simple terminal 20 .RB [ \-aiv ] 21 .RB [ \-c 22 .IR class ] 23 +.RB [ \-d 24 +.IR path ] 25 .RB [ \-f 26 .IR font ] 27 .RB [ \-g 28 @@ -30,6 +32,8 @@ st \- simple terminal 29 .RB [ \-aiv ] 30 .RB [ \-c 31 .IR class ] 32 +.RB [ \-d 33 +.IR path ] 34 .RB [ \-f 35 .IR font ] 36 .RB [ \-g 37 @@ -58,6 +62,10 @@ disable alternate screens in terminal 38 .BI \-c " class" 39 defines the window class (default $TERM). 40 .TP 41 +.BI \-d " path" 42 +changes the working directory to 43 +.IR path . 44 +.TP 45 .BI \-f " font" 46 defines the 47 .I font 48 diff --git a/x.c b/x.c 49 index 48a6676..fab2ddc 100644 50 --- a/x.c 51 +++ b/x.c 52 @@ -250,6 +250,7 @@ static char *opt_io = NULL; 53 static char *opt_line = NULL; 54 static char *opt_name = NULL; 55 static char *opt_title = NULL; 56 +static char *opt_dir = NULL; 57 58 static int oldbutton = 3; /* button event on startup: 3 = release */ 59 60 @@ -1958,12 +1959,12 @@ run(void) 61 void 62 usage(void) 63 { 64 - die("usage: %s [-aiv] [-c class] [-f font] [-g geometry]" 65 - " [-n name] [-o file]\n" 66 + die("usage: %s [-aiv] [-c class] [-d path] [-f font]" 67 + " [-g geometry] [-n name] [-o file]\n" 68 " [-T title] [-t title] [-w windowid]" 69 " [[-e] command [args ...]]\n" 70 - " %s [-aiv] [-c class] [-f font] [-g geometry]" 71 - " [-n name] [-o file]\n" 72 + " %s [-aiv] [-c class] [-d path] [-f font]" 73 + " [-g geometry] [-n name] [-o file]\n" 74 " [-T title] [-t title] [-w windowid] -l line" 75 " [stty_args ...]\n", argv0, argv0); 76 } 77 @@ -2015,6 +2016,9 @@ main(int argc, char *argv[]) 78 case 'v': 79 die("%s " VERSION "\n", argv0); 80 break; 81 + case 'd': 82 + opt_dir = EARGF(usage()); 83 + break; 84 default: 85 usage(); 86 } ARGEND; 87 @@ -2034,6 +2038,7 @@ run: 88 xinit(cols, rows); 89 xsetenv(); 90 selinit(); 91 + chdir(opt_dir); 92 run(); 93 94 return 0; 95 -- 96 2.25.1 97