From cd33a054b8111a5ef5ff9e0661aa9157ef0d4208 Mon Sep 17 00:00:00 2001 From: Alexander Gehrke Date: Mon, 12 Jul 2021 10:27:20 +0200 Subject: [PATCH] shell-wrappers: extend g-add script to allow non-tmux sessions --- g-add.zsh | 50 ++++++++++++++++++++++++++++++------------ lib/term-wrapper-kitty | 2 +- misc/sweechat | 2 +- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/g-add.zsh b/g-add.zsh index 6aae936..dea1fe4 100755 --- a/g-add.zsh +++ b/g-add.zsh @@ -6,13 +6,35 @@ if [[ -z $1 ]]; then <<-HELP Usage: $0 [opts] Options: - -p, --path PATH target directory to install into (defaults to ~/.local/bin) - -d, --dot, -m, --multi create g.\$prog links, allowing multiple instances + -p, --path PATH target directory to install into (defaults to ~/.local/bin) + -d, --dot, -m, --multi create g.\$prog links, allowing multiple instances + -n, --no-tmux don't launch with tmux HELP exit 1 fi -zparseopts -D -E p:=install_path -path:=install_path d=multi -dot=multi m=multi -multi=multi +zparseopts -D -E \ + p:=install_path -path:=install_path \ + d=multi -dot=multi m=multi -multi=multi \ + n=notmux -no-tmux=notmux + + +do-install() { + local wrapper=$1 + local install_path=$2 + local prefix=$3 + local prog=$4 + local target="$prefix${prog:t}" + + target="$prefix${prog:t}" + if [[ -e $install_path/${target} ]]; then + warning "${target} already exists at $install_path. Skipping." + else + check "Creating $prog link $target… " + ln -fsr lib/$wrapper $install_path/$target || fail + succeed + fi +} if [[ ! $install_path ]]; then install_path=$HOME/.local/bin @@ -20,15 +42,15 @@ else install_path=${install_path[2]} fi -if [[ $multi ]]; then prefix='g.'; else prefix='g'; fi +if [[ $notmux ]]; then + if [[ $multi ]]; then warning "Ignoring $multi, as no tmux is used"; fi + for prog in $@; do + do-install with-term $install_path g $prog + done +else + if [[ $multi ]]; then prefix='g.'; else prefix='g'; fi -for prog in $@; do - target="$prefix${prog:t}" - if [[ -e $install_path/${target} ]]; then - warning "${target} already exists at $install_path. Skipping." - else - check "Creating $target… " - ln -fsr lib/g $install_path/$target || fail - succeed - fi -done + for prog in $@; do + do-install g $install_path $prefix $prog + done +fi diff --git a/lib/term-wrapper-kitty b/lib/term-wrapper-kitty index 1dfe0d7..31415ae 100755 --- a/lib/term-wrapper-kitty +++ b/lib/term-wrapper-kitty @@ -5,4 +5,4 @@ zparseopts -D -E \ e:=execute -exec=execute -execute=execute \ c:=class -class=class -kitty -1 ${class+--class=}${class[2]} ${title:+-T} ${title[2]} ${=execute[2]} "$@" +kitty ${class+--class=}${class[2]} ${title+-T} ${title[2]} ${=execute[2]} "$@" diff --git a/misc/sweechat b/misc/sweechat index 7395cb8..42785b8 100755 --- a/misc/sweechat +++ b/misc/sweechat @@ -8,4 +8,4 @@ else server="qwerty"; fi -exec x-terminal-emulator -t Weechat -e tmux new-session mosh "${server}" -- tmux attach "$@" -t weechat +exec x-terminal-emulator -t Weechat -e mosh "${server}" -- tmux attach "$@" -t weechat