summaryrefslogtreecommitdiff
path: root/tohu/nextstep/bin
diff options
context:
space:
mode:
Diffstat (limited to 'tohu/nextstep/bin')
-rwxr-xr-xtohu/nextstep/bin/acme12
-rwxr-xr-xtohu/nextstep/bin/start-tohu36
-rwxr-xr-xtohu/nextstep/bin/tohu-bar105
3 files changed, 153 insertions, 0 deletions
diff --git a/tohu/nextstep/bin/acme b/tohu/nextstep/bin/acme
new file mode 100755
index 0000000..200980f
--- /dev/null
+++ b/tohu/nextstep/bin/acme
@@ -0,0 +1,12 @@
+#!/bin/sh
+export PLAN9="${PLAN9:-/usr/lib/plan9}"
+case ":$PATH:" in
+ *":$PLAN9/bin:"*) ;;
+ *) export PATH="$PATH:$PLAN9/bin" ;;
+esac
+if [ -z "${NAMESPACE:-}" ]; then
+ export NAMESPACE="${XDG_RUNTIME_DIR:-/tmp/$(id -u)-runtime-dir}/p9ns"
+fi
+mkdir -p "$NAMESPACE"
+chmod 0700 "$NAMESPACE"
+exec /usr/local/libexec/acme-bin "$@"
diff --git a/tohu/nextstep/bin/start-tohu b/tohu/nextstep/bin/start-tohu
new file mode 100755
index 0000000..842c780
--- /dev/null
+++ b/tohu/nextstep/bin/start-tohu
@@ -0,0 +1,36 @@
+#!/bin/sh
+export SHELL="/usr/bin/oksh"
+export ENV="$HOME/.kshrc"
+export XKB_DEFAULT_LAYOUT=de
+export GDK_DPI_SCALE=1.4
+export QT_FONT_DPI=134
+export XCURSOR_SIZE=32
+if [ -z "$XDG_RUNTIME_DIR" ]; then
+ export XDG_RUNTIME_DIR="/tmp/$(id -u)-runtime-dir"
+ mkdir -p "$XDG_RUNTIME_DIR"
+ chmod 0700 "$XDG_RUNTIME_DIR"
+fi
+
+export PLAN9="/usr/lib/plan9"
+case ":$PATH:" in
+ *":$PLAN9/bin:"*) ;;
+ *) export PATH="$PATH:$PLAN9/bin" ;;
+esac
+if [ -z "${NAMESPACE:-}" ]; then
+ export NAMESPACE="$XDG_RUNTIME_DIR/p9ns"
+fi
+mkdir -p "$NAMESPACE"
+chmod 0700 "$NAMESPACE"
+
+pkill -x wawa mojito 2>/dev/null || true
+rm -f "$XDG_RUNTIME_DIR/tohu-bar.fifo" "$XDG_RUNTIME_DIR/tohu-bar.pid"
+
+cur_tty=$(tty 2>/dev/null || true)
+case "$cur_tty" in
+ /dev/tty[1-9]*)
+ exec swc-launch -t "$cur_tty" tohu 2>/tmp/tohu.log
+ ;;
+ *)
+ exec swc-launch tohu 2>/tmp/tohu.log
+ ;;
+esac
diff --git a/tohu/nextstep/bin/tohu-bar b/tohu/nextstep/bin/tohu-bar
new file mode 100755
index 0000000..a4d113e
--- /dev/null
+++ b/tohu/nextstep/bin/tohu-bar
@@ -0,0 +1,105 @@
+#!/bin/sh
+set -u
+
+RUNTIME="${XDG_RUNTIME_DIR:-/tmp}"
+STATE_FILE="$RUNTIME/tohu-state"
+PID_FILE="$RUNTIME/tohu-bar.pid"
+FIFO_FILE="$RUNTIME/tohu-bar.fifo"
+BAR_FONT="IBM Plex Mono:pixelsize=14"
+
+trim_title() {
+ t="$1"
+ if [ -z "$t" ]; then
+ printf '%s' "Workspace"
+ return
+ fi
+ printf '%s' "$t" | tr -d '\r\n' | tr '%' '/' | awk '{ if (length($0) > 48) printf "%s...", substr($0, 1, 45); else printf "%s", $0 }'
+}
+
+format_bar() {
+ ws=1
+ occ=0
+ title=""
+ if [ -r "$STATE_FILE" ]; then
+ while IFS='=' read -r k v; do
+ case "$k" in
+ ws) [ -n "$v" ] && ws="$v" ;;
+ occ) [ -n "$v" ] && occ="$v" ;;
+ title) title="$v" ;;
+ esac
+ done < "$STATE_FILE"
+ fi
+
+ left='%{l} '
+ i=1
+ while [ "$i" -le 9 ]; do
+ bit=$((1 << i))
+ is_occ=$((occ & bit))
+ if [ "$i" -eq "$ws" ]; then
+ left="${left}%{B#000000}%{F#ffffff} $i %{B-}%{F-}"
+ elif [ "$is_occ" -ne 0 ]; then
+ left="${left}%{B#8c8c8c}%{F#000000} ${i}ยท %{B-}%{F-}"
+ elif [ "$i" -le 5 ]; then
+ left="${left} $i "
+ fi
+ i=$((i + 1))
+ done
+
+ t_disp=$(trim_title "$title")
+ center="%{c}%{B#d8d8d8}%{F#000000} ${t_disp} %{B-}%{F-}"
+
+ load=$(awk '{print $1}' /proc/loadavg 2>/dev/null || printf '0.00')
+ mem=$(awk '/^MemTotal:/{t=$2} /^MemAvailable:/{a=$2} END{if(t>0) printf "%.1f/%.1fG",(t-a)/1048576,t/1048576; else printf "--"}' /proc/meminfo 2>/dev/null)
+ up=$(awk '{s=int($1); d=int(s/86400); h=int((s%86400)/3600); m=int((s%3600)/60); if(d>0) printf "%dd%dh",d,h; else if(h>0) printf "%dh%02dm",h,m; else printf "%dm",m}' /proc/uptime 2>/dev/null || printf '--')
+ oper=$(cat /sys/class/net/wlan0/operstate 2>/dev/null || printf 'down')
+ now=$(date '+%H:%M')
+
+ if [ "$oper" = "up" ]; then
+ right="%{r}%{B#c8c8c8}%{F#000000} load ${load} | ${mem} | up ${up} %{B#000000}%{F#ffffff} ${now} %{B-}%{F-}"
+ else
+ right="%{r}%{B#c8c8c8}%{F#000000} load ${load} | ${mem} | up ${up} | offline %{B#000000}%{F#ffffff} ${now} %{B-}%{F-}"
+ fi
+
+ printf '%s%s%s\n' "$left" "$center" "$right"
+}
+
+if [ "${1:-}" = "--once" ]; then
+ format_bar
+ exit 0
+fi
+
+sleep_pid=""
+mojito_pid=""
+
+cleanup() {
+ rm -f "$PID_FILE" "$FIFO_FILE"
+ [ -n "$sleep_pid" ] && kill "$sleep_pid" 2>/dev/null || true
+ [ -n "$mojito_pid" ] && kill "$mojito_pid" 2>/dev/null || true
+ exit 0
+}
+
+on_usr1() {
+ [ -n "$sleep_pid" ] && kill "$sleep_pid" 2>/dev/null || true
+}
+
+trap cleanup INT TERM HUP
+trap on_usr1 USR1
+
+rm -f "$FIFO_FILE"
+mkfifo -m 0600 "$FIFO_FILE"
+mojito -g x26 -f "$BAR_FONT" -B "#aaaaaa" -F "#000000" -U "#000000" < "$FIFO_FILE" &
+mojito_pid=$!
+
+exec 3>"$FIFO_FILE"
+rm -f "$FIFO_FILE"
+printf '%s\n' "$$" > "$PID_FILE"
+
+while kill -0 "$mojito_pid" 2>/dev/null; do
+ format_bar >&3 2>/dev/null || break
+ sleep 2 &
+ sleep_pid=$!
+ wait "$sleep_pid" 2>/dev/null || true
+ sleep_pid=""
+done
+
+cleanup