From 9ca1ae3ceca5944765af94514e75a96195de5716 Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Fri, 15 Mar 2024 17:47:12 +0100 Subject: Add stumpish. --- .bin/stumpish | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100755 .bin/stumpish (limited to '.bin/stumpish') diff --git a/.bin/stumpish b/.bin/stumpish new file mode 100755 index 0000000..9e95c0c --- /dev/null +++ b/.bin/stumpish @@ -0,0 +1,196 @@ +#!/bin/sh + +# Copyright (C) 2007 Jonathan Moore Liles +# +# Maintainer: Jonathan Moore Liles +# +# stumpish is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# stumpish is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, see +# . + +### STUMPwm Interactive SHell. + +DELAY=0.01 + +if ! sleep $DELAY 2>/dev/null >&2 +then + DELAY=1 +fi + +# replace -E with -r option for old versions of GNU sed +if ! sed -E 1p /dev/null 2>/dev/null; then + sed() { shift; command sed -r "$@"; } +fi + +# parse C-style backslash sequences by default +if [ "$(echo -e foo)" = foo ]; then + echo() { builtin echo -e "$@"; } +fi + +wait_result () +{ + while true + do + RESULT=$(xprop -root -f STUMPWM_COMMAND_RESULT 8s \ + STUMPWM_COMMAND_RESULT 2>/dev/null | + sed -E 's/\\([[:digit:]]+)/\\0\1/g') + if echo "$RESULT" | grep -v -q 'not found.$' + then + break + fi + + sleep $DELAY + done + + xprop -root -remove STUMPWM_COMMAND_RESULT + + if echo "$RESULT" | grep -q '= $' + then + return 0 + fi + + echo "$RESULT" | + sed -E 's/[^"\\n]+"// + /^"[[:space:]]*$/d + s/(^|[^\\])\\n/\1\ +/g + s/\\(["\\n])/\1/g + s/\^([*[:digit:]]+|[Bbn])//g' +} + +send_cmd () +{ + local cmd="$1" + + if [ "$cmd" = "stumpwm-quit" ] + then + cmd=quit + elif [ "$cmd" = "quit" ] + then + exit + fi + + xprop -root -f STUMPWM_COMMAND 8s -set STUMPWM_COMMAND "$cmd" + + wait_result +} + +usage () +{ + cat <&2 +} + +tput () +{ + local cap1=$1 cap2=$2 + shift 2 + + command tput $cap1 $@ 2>/dev/null || + command tput $cap2 $@ 2>/dev/null +} + +READLINE=yes + +if [ "x$1" = "x-r" ] +then + READLINE=no + shift 1 +fi + +if [ $# -gt 0 ] +then + [ "$1" = "--help" ] && usage + if [ "$1" = "-e" ] + then + if [ $# -ne 2 ] + then + echo "'-e' requires exactly one argument!" + exit + fi + shift 1 + IFS='' + ARGS=$(cat /dev/stdin) + send_cmd "$1 $ARGS" + else + IFS=' ' + send_cmd "$*" + fi +else + if [ -t 0 ] + then + if ! type rlwrap 2>/dev/null >&2 + then + warn rlwrap not found, command completion won\'t work + elif [ $READLINE = yes ] + then + COMMANDS="${TMPDIR:-/tmp}/stumpish.commands.$$" + echo $(send_cmd "commands") | + sed -E 's/[[:space:]]+/\ +/g' | + sort > "$COMMANDS" + trap 'rm -f "$COMMANDS"' exit int term + rlwrap -b '' -f "$COMMANDS" "$0" -r + exit + fi + + tput AF setaf 5 + echo Welcome to the STUMPwm Interactive SHell. + tput me sgr0 + echo 'Type \c' + tput AF setaf 2 + echo 'commands\c' + tput me sgr0 + echo \ for a list of commands. + + while read -p '> ' REPLY + do + tput md bold + tput AF setaf 2 + send_cmd "$REPLY" + tput me sgr0 + done + else + while read REPLY + do + send_cmd "$REPLY" + done + fi +fi -- cgit v1.2.3