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;}