Add session command

This commit is contained in:
2024-08-21 20:21:51 +01:00
parent 4ff10eb05e
commit ba228a419d
3 changed files with 29 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
session() {
if [[ "$1" == "" ]]; then
echo "usage: session <name> [<host>]"
else
local name=$1
local host=$2
if [[ "$3" != "" ]]; then
echo "$fg[red]error:$reset_color invalid argument: $3"
return 1
fi
if [[ "$TMUX" == "" ]]; then
local cmd="tmux new-session -As $name"
if [[ "$host" != "" ]]; then
cmd="ssh $host -t $cmd"
fi
else
if [[ "$host" != "" ]]; then
echo "$fg[red]error:$reset_color <host> not allowed inside tmux session"
return 1
fi
cmd="tmux switch-client -t $name"
fi
eval $cmd
fi
}