commit 9760f41d4f26e482415ee8f8264a7f6f63cfb7e2 Author: Deven Blake Date: Sat May 14 20:42:46 2022 -0400 displaym diff --git a/displaym/LICENSE b/displaym/LICENSE new file mode 100644 index 0000000..68a49da --- /dev/null +++ b/displaym/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/displaym/README.md b/displaym/README.md new file mode 100644 index 0000000..d8cbc7f --- /dev/null +++ b/displaym/README.md @@ -0,0 +1,59 @@ +# displaym + +A dirt-simple window manager manager using shellscript. + +## Dependencies + +### POSIX + +- mkdir(1) +- printf(1) +- sh(1) +- test(1) + +### Non-POSIX + +- bak(1) + +## Design + +It's encouraged to read the `displaym` source *rather than* this documentation, as the script is quite simple. + +Usage: `displaym [WM] [action]` + +`[WM]` refers to the folder in which `[action].sh` is stored. +`[action].sh` is sourced within `displaym`, which is a script executed by `sh(1)`. +On systems where Bash acts as the system's POSIX-compatible shell you may be able to use Bashisms within displaym actions but this isn't recommended. + +The environment variable `$DISPLAYM_CONFIG` refers to the location of the displaym configuration directory; this is the directory that contains `[WM]/[action].sh`. +If `$DISPLAYM_CONFIG` is already set, it's not overriden. +The default location, if `$XDG_CONFIG_HOME` is set, is `$XDG_CONFIG_HOME/displaym`. +Otherwise, the default location is `$HOME/.displaym`. +If `$HOME` isn't set this will make the default displaym configuration directory location `/.displaym`. + +Typically a `[WM]` folder will contain a `start.sh` and `stop.sh`, so (for example) the user may execute `displaym i3 start` to "start" the exemplary window manager i3. +Both the window manager name and action name are arbitrary, and use is not limited to the realm of window manager management, it just happens to be well suited to the application. +`displaym` could be renamed to `remotem` and the user could run `remotem [CITY] [COMPUTER]` to remote into a known computer in a known city. + +Here's an example `bspwm/start.sh`: + +```sh +#!/bin/sh + +# start bspwm + +# combine base sxhkd (keyboard daemon) config and bspwm-specifc config, output +# to the proper place +[ -n "$SXHKD_CONFIG ] || SXHKD_CONFIG="$HOME/.config/sxhkd/sxhkdrc" +cat "$DISPLAYM_CONFIG/sxhkdrc" "$DISPLAYM_CONFIG/$WM/sxhkdrc" >"$SXHKD_CONFIG" + +# combine base .xinitrc (X initialization run-commands) and bspwm-specific +# .xinitrc, output to the proper place +cat "$DISPLAYM_CONFIG/.xinitrc" "$DISPLAYM_CONFIG/$WM/.xinitrc" >"$HOME/.xinitrc" + +# start X +startx +``` + +Because the `[action].sh` is sourced from `displaym`, a number of useful environment variables are already set: +`$DISPLAYM_CONFIG`, `$WM`, and `$SCRIPT` (which refers to the `[action]`). diff --git a/displaym/displaym b/displaym/displaym new file mode 100755 index 0000000..1204674 --- /dev/null +++ b/displaym/displaym @@ -0,0 +1,45 @@ +#!/bin/sh +set -e + +argv0="$0" + +error(){ + printf "%s: %s\n" "$argv0" "$1" 1>&2 + exit $2 +} + +usage(){ + set +x + printf "\ +Usage: + %s [window manager] [action]\n" "$argv0" 1>&2 + exit 64 # sysexits(3) EX_USAGE +} + +[ -n "$2" ] \ + || usage + +# sysexits(3) EX_OSERR +[ -n "$HOME" ] \ + || error "No \$HOME environment variable set. This is very bad." 71 + +if [ -z "$DISPLAYM_CONFIG" ]; then + [ -z "$XDG_CONFIG_HOME" ] \ + && DISPLAYM_CONFIG="$HOME/.displaym" \ + || DISPLAYM_CONFIG="$XDG_CONFIG_HOME/displaym" +fi + +export DISPLAYM_CONFIG + +[ -e "$DISPLAYM_CONFIG" ] && ! [ -d "$DISPLAYM_CONFIG" ] \ + && bak "$DISPLAYM_CONFIG" \ + || true + +[ -d "$DISPLAYM_CONFIG" ] \ + || mkdir -p "$DISPLAYM_CONFIG" + +WM="$1"; export WM +SCRIPT="$2" + +# with exported DISPLAYM_CONFIG and WM +sh <"$DISPLAYM_CONFIG/$WM/$SCRIPT.sh"