shell-wrappers: extend g-add script to allow non-tmux sessions

This commit is contained in:
Alexander Gehrke 2021-07-12 10:27:20 +02:00
parent 4f440e962b
commit cd33a054b8
3 changed files with 38 additions and 16 deletions

View file

@ -6,13 +6,35 @@ if [[ -z $1 ]]; then
<<-HELP
Usage: $0 [opts] <program_names>
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

View file

@ -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]} "$@"

View file

@ -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