From dc01861a1a08d50048ed2cb3c88106ede973567c Mon Sep 17 00:00:00 2001 From: Wes Key <2540699+chopnico@users.noreply.github.com> Date: Thu, 23 Dec 2021 22:24:02 -0500 Subject: [PATCH] updated naming conventions and format based on comments --- plugins/tmux-autoattach/README.md | 8 +++++ .../tmux-autoattach/tmux-autoattach.plugin.sh | 29 +++++++++++++++++++ plugins/tmux/README.md | 3 -- plugins/tmux/tmux.plugin.sh | 3 -- 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 plugins/tmux-autoattach/README.md create mode 100644 plugins/tmux-autoattach/tmux-autoattach.plugin.sh delete mode 100644 plugins/tmux/README.md delete mode 100644 plugins/tmux/tmux.plugin.sh diff --git a/plugins/tmux-autoattach/README.md b/plugins/tmux-autoattach/README.md new file mode 100644 index 0000000..0630b97 --- /dev/null +++ b/plugins/tmux-autoattach/README.md @@ -0,0 +1,8 @@ +# tmux plugin + +The tmux plugin will either attach or create a new tmux session for each bash session. If a session already exists, it will simply attach. + +## OSH_PLUGIN_TMUX_AUTOATTACH_BEHAVIOR + +| exit | This will completely close out your shell session, including your terminal, but keep your tmux sessions intact. This will also close your session if you detach. | +| detach | This will allow you to detach from the tmux screen without closing the terminal or shell session. | diff --git a/plugins/tmux-autoattach/tmux-autoattach.plugin.sh b/plugins/tmux-autoattach/tmux-autoattach.plugin.sh new file mode 100644 index 0000000..8c93359 --- /dev/null +++ b/plugins/tmux-autoattach/tmux-autoattach.plugin.sh @@ -0,0 +1,29 @@ +# @chopnico 2021 +# +# tmux-autoattach.plugin.sh +# +# A tmux plugin that will automatically attach itself to a bash session. + +[ -z "$OSH_PLUGIN_TMUX_AUTOATTACH_BEHAVIOR" ] && export OSH_PLUGIN_TMUX_AUTOATTACH_BEHAVIOR="detach" + +_osh_plugin_tmux_autoattach_exit() { + [ -z "$TMUX" ] && tmux -2u new -A && exit +} + +_osh_plugin_tmux_autoattach_detach() { + [ -z "$TMUX" ] && tmux -2u new -A +} + +if [ "$DISPLAY" ] || [ "$WAYLAND_DISPLAY" ]; then + case "$OSH_PLUGIN_TMUX_AUTOATTACH_BEHAVIOR" in + "exit") + _osh_plugin_tmux_autoattach_exit + ;; + "detach") + _osh_plugin_tmux_autoattach_detach + ;; + *) + _osh_plugin_tmux_autoattach_detach + ;; + esac +fi diff --git a/plugins/tmux/README.md b/plugins/tmux/README.md deleted file mode 100644 index 6454cfd..0000000 --- a/plugins/tmux/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# tmux plugin - -The tmux plugin will either attach or create a new tmux session for each bash session. If a session already exists, it will simply attach. diff --git a/plugins/tmux/tmux.plugin.sh b/plugins/tmux/tmux.plugin.sh deleted file mode 100644 index ed18bc6..0000000 --- a/plugins/tmux/tmux.plugin.sh +++ /dev/null @@ -1,3 +0,0 @@ -# @chopnico 2021 - -[ -z "$TMUX" ] && { tmux -2 -u attach || exec tmux -2 -u new-session && exit;}