shod

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 49fbac90be2a98dd02970f2455301202e10093c8
parent f48e8979d70bdb8e70b8769db5a4e18713cfb35d
Author: seninha <lucas@seninha.org>
Date:   Wed, 31 Aug 2022 15:15:34 -0300

run commands

Diffstat:
MREADME | 18++++--------------
Mshod.1 | 14+++++++++++++-
Mshod.c | 39++++++++++++++++++++++++---------------
3 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/README b/README @@ -14,20 +14,10 @@ │ │ └───────────────────────┘ -shod is a multi-monitor floating reparenting X11 window manager that -supports tiled and tabbed containers. shod sets no keybindings, reads -no configuration, and works only via mouse with a given key modifier -(Alt by default) and by responding to client messages sent by the shodc -utility (shod's remote controller). - - -!WARNING! -shod now reads commands from stdin to be run at initialization. If you -do not want shod to run anything, open /dev/null on standard input when -calling shod on your ~/.xinitrc (or related file), like this: - - exec shod </dev/null - +shod is a multi-monitor, floating, reparenting X11 window manager that +supports tiled and tabbed containers. shod works via mouse with a given +key modifier (Alt by default) and by responding to client messages sent +by the shodc utility (shod's remote controller). shod was inspired by the following programs and window managers. I'd like to thank their authors for their work that helped me developing diff --git a/shod.1 b/shod.1 @@ -7,6 +7,7 @@ .RB [ \-cds ] .RB [ \-m .IR modifier ] +.RI [ file ] .PP .B shodc close .RI [ win_id ] @@ -60,8 +61,19 @@ a controller called .IR shodc (1) to control shod). .PP +If a file is given as argument, .B shod -passes its standard input to the shell after initializing itself. +passes this file to +.IR sh (1) +to run the commands in that file after +.B shod +has initialized itself. +However, if the argument is a hyphen +.RB ( - ), +.B shod +calls +.IR sh (1) +to run commands from the standard input instead. .PP The options are as follows: .TP diff --git a/shod.c b/shod.c @@ -590,7 +590,7 @@ volatile sig_atomic_t running = 1; static void usage(void) { - (void)fprintf(stderr, "usage: shod [-cs] [-m modifier]\n"); + (void)fprintf(stderr, "usage: shod [-cds] [-m modifier] [file]\n"); exit(1); } @@ -654,10 +654,19 @@ efork(void) /* call execlp checking for error; exit on error */ static void -eexec(const char *cmd) +execshell(char *filename) { - if (execlp(cmd, cmd, NULL) == -1) { - err(1, "%s", cmd); + char *argv[3]; + + if ((argv[0] = getenv(SHELL)) == NULL) + argv[0] = DEF_SHELL; + if (filename[0] == '-' && filename[1] == '\0') + argv[1] = NULL; /* read commands from stdin */ + else + argv[1] = filename; /* read commands from file */ + argv[2] = NULL; + if (execvp(argv[0], argv) == -1) { + err(1, "%s", argv[0]); } } @@ -839,7 +848,7 @@ getresources(void) } /* read command-line options */ -static void +static char * getoptions(int argc, char *argv[]) { int c; @@ -869,9 +878,9 @@ getoptions(int argc, char *argv[]) } argc -= optind; argv += optind; - if (argc != 0) { + if (argc > 1) usage(); - } + return *argv; } /* initialize visual and depth */ @@ -6384,16 +6393,15 @@ xeventunmapnotify(XEvent *e) /* run stdin on sh */ static void -autostart(void) +autostart(char *filename) { pid_t pid; - char *shell; - if ((shell = getenv(SHELL)) == NULL) - shell = DEF_SHELL; + if (filename == NULL) + return; if ((pid = efork()) == 0) { if (efork() == 0) - eexec(shell); + execshell(filename); exit(0); } waitpid(pid, NULL, 0); @@ -6460,6 +6468,7 @@ int main(int argc, char *argv[]) { XEvent ev; + char *filename; void (*xevents[LASTEvent])(XEvent *) = { [ButtonPress] = xeventbuttonpress, [ClientMessage] = xeventclientmessage, @@ -6490,7 +6499,7 @@ main(int argc, char *argv[]) /* get configuration */ getresources(); - getoptions(argc, argv); + filename = getoptions(argc, argv); /* check sloppy focus */ if (config.sloppyfocus) @@ -6529,8 +6538,8 @@ main(int argc, char *argv[]) ewmhsetclientsstacking(); ewmhsetactivewindow(None); - /* run stdin on sh */ - autostart(); + /* run sh script */ + autostart(filename); /* scan windows */ scan();