diff --git a/session/session.plugin.zsh b/session/session.plugin.zsh new file mode 100644 index 0000000..d79840b --- /dev/null +++ b/session/session.plugin.zsh @@ -0,0 +1,27 @@ +session() { + if [[ "$1" == "" ]]; then + echo "usage: session []" + 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 + eval $cmd + else + if [[ "$host" != "" ]]; then + echo "$fg[red]error:$reset_color not allowed inside tmux session" + return 1 + fi + tmux list-sessions | grep "$name:" &> /dev/null || \ + tmux new-session -Ads $name -c $HOME + tmux switch-client -t $name + fi + fi +} diff --git a/utilities/utilities.plugin.zsh b/utilities/utilities.plugin.zsh index c8cdaa9..2602c89 100644 --- a/utilities/utilities.plugin.zsh +++ b/utilities/utilities.plugin.zsh @@ -62,6 +62,7 @@ notify_ignore_list=( ping podman python + session slides ssh sudo diff --git a/zshrc b/zshrc index d4d2101..ab01726 100644 --- a/zshrc +++ b/zshrc @@ -41,6 +41,9 @@ source-plugin utilities # Automatically source .enter and .exit scripts on cd source-plugin autoenv +# Session manager +source-plugin session + # Layout tmux window commands [ "$TMUX" != "" ] && source-plugin layout