summaryrefslogtreecommitdiff
path: root/.local/bin/screenx
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/screenx')
-rwxr-xr-x.local/bin/screenx51
1 files changed, 51 insertions, 0 deletions
diff --git a/.local/bin/screenx b/.local/bin/screenx
new file mode 100755
index 0000000..3ba25c7
--- /dev/null
+++ b/.local/bin/screenx
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+help() { echo "screenx - execute command in a new fullscreen terminal
+
+USAGE:
+ screenx [OPTION]... <command>
+
+OPTIONS:
+ -n no prompt when exiting
+ -h show this help message"; }
+
+err() { printf 'screenx: %s\n' "$@" >&2; exit 1; }
+while getopts 'nh' o; do case "$o" in
+ n) nflag=0 ;;
+ h) help >&2; exit ;;
+ *) err "invalid option -- '$OPTARG'" ;;
+esac done
+shift $((OPTIND - 1))
+
+[ "$#" -lt 1 ] && help >&2 && exit 1
+cmds="$*"
+[ "$nflag" = 0 ] ||
+ cmds="$cmds; printf '\n%s' 'Press <Enter> to continue: '; read -r arg"
+
+tmuxcmds="tmux set status off; $cmds; tmux set status on;"
+set_screen() {
+ [ -z "$TMUX" ] &&
+ err '$TMUX not set, only tmux is supported for screen program'
+ tmux new-window -n screenx "$tmuxcmds"
+}
+new_screen() { tmux new-session -s screenx "$tmuxcmds"; }
+
+terminal_emulator() {
+ [ -z "$DISPLAY" ] && return 1
+ #err 'screenx: terminal_emulator: $DISPLAY not set'
+ case "$TERMINAL" in
+ '') echo 'screenx: $TERMINAL not set' && exit 1 ;;
+ alacritty) export TERMINAL="alacritty" ;;
+ esac
+ wmctrl -r :ACTIVE: -b remove,fullscreen
+ $TERMINAL -e sh -c "sleep 0.2; $cmds" &
+ sleep 0.2 && wmctrl -r :ACTIVE: -b add,fullscreen
+}
+
+case "$TERM" in
+ '') err '$TERM not set' ;;
+ *screen*) set_screen ;;
+ *linux*) setfont ter-132n && new_screen ;;
+ *256*) terminal_emulator || new_screen ;;
+ *) err "no action for \$TERM: $TERM"
+esac