From 7ba3dba2bcea824264cafce64930dcee431cdea6 Mon Sep 17 00:00:00 2001 From: Alexander Gehrke Date: Mon, 5 Jul 2021 13:11:42 +0200 Subject: [PATCH] Add wrappers for terminals to make scripts terminal-agnostic Scripts launching a terminal will now require x-terminal-emulator in the path. A symlink for it can be created using `select-term.zsh`. --- lib/g | 4 +--- lib/term-wrapper-alacritty | 12 ++++++++++++ lib/term-wrapper-kitty | 9 +++++++++ misc/guiterm | 30 ------------------------------ misc/sweechat | 4 ++-- select-term.zsh | 29 +++++++++++++++++++++++++++++ 6 files changed, 53 insertions(+), 35 deletions(-) create mode 100644 lib/term-wrapper-alacritty create mode 100755 lib/term-wrapper-kitty delete mode 100755 misc/guiterm create mode 100755 select-term.zsh diff --git a/lib/g b/lib/g index 1ae8a39..8860a94 100755 --- a/lib/g +++ b/lib/g @@ -24,6 +24,4 @@ else action="tmux new-session -s ${prog} ${prog}" fi -#exec alacritty --title G${prog} -e ${=action} -#exec urxvt -name G${prog} -e ${=action} -exec alacritty -t G${prog} -e ${=action} +exec x-terminal-emulator -t G${prog} -e ${=action} diff --git a/lib/term-wrapper-alacritty b/lib/term-wrapper-alacritty new file mode 100644 index 0000000..e9560c9 --- /dev/null +++ b/lib/term-wrapper-alacritty @@ -0,0 +1,12 @@ +#!/bin/zsh + +zparseopts -D -E \ + t:=title -title=title \ + e:=execute -exec=execute -execute=execute \ + c:=class -class=class + +if [[ -n $1 || -n $execute ]]; then + execparam="-e" +fi + +alacritty ${class+--class} ${class[2]} ${title+-t} ${title[2]} $execparam ${=execute[2]} "$@" diff --git a/lib/term-wrapper-kitty b/lib/term-wrapper-kitty new file mode 100755 index 0000000..71420f0 --- /dev/null +++ b/lib/term-wrapper-kitty @@ -0,0 +1,9 @@ +#!/bin/zsh + +zparseopts -D -E \ + t:=title -title=title \ + e:=execute -exec=execute -execute=execute \ + c:=class -class=class + + +kitty -1 ${class+--class=}${class[2]} ${title+-T} ${title[2]} ${=execute[2]} "$@" diff --git a/misc/guiterm b/misc/guiterm deleted file mode 100755 index 9ac7c28..0000000 --- a/misc/guiterm +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/zsh -#dep:tmux alacritty - -if [[ "${0:t}" == "guiterm" ]]; then - <<-HELP - Symlink to g\$progname to start \$progname in tmux in a new terminal or - reattach a tmux session named \$progname in a new terminal - - Symlink to g.\$progname to start \$progname in tmux in a new terminal - regardless of existing tmux sessions" - - Example symlink names: - gmutt: start mutt in a terminal or open the existing one - g.zsh: open a terminal running a new zsh session - HELP - exit 1 -fi - -prog=${${0:t}[2,-1]} -if [[ "$prog[1]" == "." ]]; then - prog=${prog[2,-1]} - action="tmux new-session ${prog}" -elif tmux list-sessions | grep -qe "^${prog}:"; then - action="tmux attach -t ${prog}" -else - action="tmux new-session -s ${prog} ${prog}" -fi - -#exec alacritty --title G${prog} -e ${=action} -exec alacritty -t G${prog} -e ${=action} diff --git a/misc/sweechat b/misc/sweechat index cbef248..7395cb8 100755 --- a/misc/sweechat +++ b/misc/sweechat @@ -1,5 +1,5 @@ #!/bin/zsh -#dep:alacritty tmux mosh +#dep:x-terminal-emulator tmux mosh if [[ "$1" == "-S" ]]; then shift server=${1}; @@ -8,4 +8,4 @@ else server="qwerty"; fi -exec alacritty -t Weechat -e tmux new-session mosh "${server}" -- tmux attach "$@" -t weechat +exec x-terminal-emulator -t Weechat -e tmux new-session mosh "${server}" -- tmux attach "$@" -t weechat diff --git a/select-term.zsh b/select-term.zsh new file mode 100755 index 0000000..083e70b --- /dev/null +++ b/select-term.zsh @@ -0,0 +1,29 @@ +#!/bin/zsh + +zparseopts -D -E p:=install_path -path:=install_path h:=help -help:=help + +if [[ $help ]]; then + <<-HELP + Usage: $0 [opts] + + Installs a wrapper script for the selected terminal under the name + "x-terminal-emulator" in path. The wrapper ensures a common interface for + setting title, class and passing commands. + + Options: + -p, --path PATH target directory to install into (defaults to ~/.local/bin) + HELP + exit 1 +fi + + +if [[ ! $install_path ]]; then + install_path=$HOME/.local/bin +else + install_path=${install_path[2]} +fi + +terms=( lib/term-wrapper-* ) + +selected_term=$(printf "%s\n" ${terms:t} | fzf) +ln -fsr lib/$selected_term $install_path/x-terminal-emulator