From b9e952d91593016bf15883f2c19b8a7fc3fcaf0c Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Sat, 24 Sep 2022 15:57:10 -0500 Subject: [PATCH] zshmux creation --- README.md | 10 +++++++++- zshmux.zsh | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 zshmux.zsh diff --git a/README.md b/README.md index 1a76528..817c180 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # zshmux -A super simple zsh plugin to attach to tmux sessions for new shells + +If a new shell is launched, *zshmux* quickly checks if there are any tmux sessions, or if the current shell is already in a tmux instance. +If you are not already in a tmux session *zshmux* will ask if you want to attach a currently running session, or make a new session in the shell. + +## How to use: +-Clone this repository + 'git clone https://github.com/huboles/zshmux' +-Source *zshmux* in your .zshrc + 'source /zshmux/zshmux.zsh' diff --git a/zshmux.zsh b/zshmux.zsh new file mode 100644 index 0000000..137333d --- /dev/null +++ b/zshmux.zsh @@ -0,0 +1,19 @@ +#!/bin/zsh + +if [[ -z $TMUX ]]; then + if tlist &> /dev/null ; then + printf 'Current tmux sessions:\n\n' + tlist + else + printf '\nNo tmux sessions active\n' + fi + printf '\n\tAttach session?: [name] (empty if none): ' + read response + if [ -n "$response" ]; then + if tlist | grep -q "$response"; then + tmux attach-session -t $response + else + tmux new-session -s $response + fi + fi +fi -- 2.44.2