From a35a7e74c357a834197497b49cfdd7f53d71607c Mon Sep 17 00:00:00 2001
From: Tinashe <tkucherera@lenovo.com>
Date: Thu, 27 Apr 2023 15:39:32 -0400
Subject: [PATCH] tmux session resuse

---
 confluent_client/bin/nodeconsole | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/confluent_client/bin/nodeconsole b/confluent_client/bin/nodeconsole
index 3768b2a4..93818ed4 100755
--- a/confluent_client/bin/nodeconsole
+++ b/confluent_client/bin/nodeconsole
@@ -282,8 +282,13 @@ if options.tile:
             sys.exit(1)
         nodes.append(node)
     initial = True
+    in_tmux = False
     pane = 0
     sessname = 'nodeconsole_{0}'.format(os.getpid())
+    if os.environ.get("TMUX"):
+        initial = False
+        in_tmux = True
+        subprocess.call(['tmux', 'rename-session', sessname])
     for node in sortutil.natural_sort(nodes):
         panename = '{0}:{1}'.format(sessname, pane)
         if initial:
@@ -304,7 +309,8 @@ if options.tile:
             pane += 1
     subprocess.call(['tmux', 'select-pane', '-t', sessname])
     subprocess.call(['tmux', 'set-option', '-t', panename, 'pane-border-status', 'top'], stderr=null)
-    os.execlp('tmux', 'tmux', 'attach', '-t', sessname)
+    if not in_tmux:
+        os.execlp('tmux', 'tmux', 'attach', '-t', sessname)
 else:
     os.execl(confettypath, confettypath, 'start',
              '/nodes/{0}/console/session'.format(args[0]))
\ No newline at end of file