From 88a0d1c5ccfd15811316ab40ea9bb5c47d9a3fa2 Mon Sep 17 00:00:00 2001 From: ncoop57 Date: Sat, 7 Dec 2024 10:41:25 -0600 Subject: [PATCH] Refactor tmux pane output function names --- nbs/00_core.ipynb | 104 +++++++++++++++++++++++++++++++++++++++--- shell_sage/_modidx.py | 4 +- shell_sage/core.py | 22 ++++----- 3 files changed, 110 insertions(+), 20 deletions(-) diff --git a/nbs/00_core.ipynb b/nbs/00_core.ipynb index 7cc68ae..6f0eae2 100644 --- a/nbs/00_core.ipynb +++ b/nbs/00_core.ipynb @@ -189,13 +189,58 @@ "outputs": [], "source": [ "#| exports\n", - "def get_pane_output(n, pid=None):\n", + "def get_pane(n, pid=None):\n", " \"Get output from a tmux pane\"\n", " cmd = ['tmux', 'capture-pane', '-p', '-S', f'-{n}']\n", " if pid: cmd += ['-t', pid]\n", " return co(cmd, text=True)" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "e799e039", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Writing objects: 100% (7/7), 702 bytes | 702.00 KiB/s, done.\n",
+       "Total 7 (delta 4), reused 0 (delta 0), pack-reused 0\n",
+       "remote: Resolving deltas: 100% (4/4), completed with 4 local objects.\n",
+       "To github.com:AnswerDotAI/shell_sage.git\n",
+       "   90bd427..77ca92e  main -> main\n",
+       "(py311)\n",
+       "shell_sage on  main via  v3.11.10 via  py311 on   (us-east-1) on ☁️  nc@answer.ai(us-west1)\n",
+       "❯ ssage --s Tell me about XDG Base Directory Specification\n",
+       "powers up documentation circuits with a slight whir\n",
+       "\n",
+       "Ah, the XDG Base Directory Specificat\n",
+       "
\n" + ], + "text/plain": [ + "Writing objects: \u001b[1;36m100\u001b[0m% \u001b[1m(\u001b[0m\u001b[1;36m7\u001b[0m/\u001b[1;36m7\u001b[0m\u001b[1m)\u001b[0m, \u001b[1;36m702\u001b[0m bytes | \u001b[1;36m702.00\u001b[0m KiB/s, done.\n", + "Total \u001b[1;36m7\u001b[0m \u001b[1m(\u001b[0mdelta \u001b[1;36m4\u001b[0m\u001b[1m)\u001b[0m, reused \u001b[1;36m0\u001b[0m \u001b[1m(\u001b[0mdelta \u001b[1;36m0\u001b[0m\u001b[1m)\u001b[0m, pack-reused \u001b[1;36m0\u001b[0m\n", + "remote: Resolving deltas: \u001b[1;36m100\u001b[0m% \u001b[1m(\u001b[0m\u001b[1;36m4\u001b[0m/\u001b[1;36m4\u001b[0m\u001b[1m)\u001b[0m, completed with \u001b[1;36m4\u001b[0m local objects.\n", + "To github.com:AnswerDotAI/shell_sage.git\n", + " 90bd427..77ca92e main -> main\n", + "\u001b[1m(\u001b[0mpy311\u001b[1m)\u001b[0m\n", + "shell_sage on  main via  v3.\u001b[1;36m11.10\u001b[0m via  py311 on  \u001b[1m(\u001b[0mus-east-\u001b[1;36m1\u001b[0m\u001b[1m)\u001b[0m on ☁️ nc@\u001b[1;35manswer.ai\u001b[0m\u001b[1m(\u001b[0mus-west1\u001b[1m)\u001b[0m\n", + "❯ ssage --s Tell me about XDG Base Directory Specification\n", + "powers up documentation circuits with a slight whir\n", + "\n", + "Ah, the XDG Base Directory Specificat\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "p = get_pane(20)\n", + "print(p[:512])" + ] + }, { "cell_type": "code", "execution_count": null, @@ -204,10 +249,55 @@ "outputs": [], "source": [ "#| exports\n", - "def get_pane_outputs(n):\n", - " current_id = co(['tmux', 'display-message', '-p', '#{pane_id}'], text=True).strip()\n", + "def get_panes(n):\n", + " cid = co(['tmux', 'display-message', '-p', '#{pane_id}'], text=True).strip()\n", " pids = [p for p in co(['tmux', 'list-panes', '-F', '#{pane_id}'], text=True).splitlines()] \n", - " return '\\n'.join(f\"{get_pane_output(n, p)}\" for p in pids) " + " return '\\n'.join(f\"{get_pane(n, p)}\" for p in pids) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a537f788", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
<pane id=%0 active>Writing objects: 100% (7/7), 702 bytes | 702.00 KiB/s, done.\n",
+       "Total 7 (delta 4), reused 0 (delta 0), pack-reused 0\n",
+       "remote: Resolving deltas: 100% (4/4), completed with 4 local objects.\n",
+       "To github.com:AnswerDotAI/shell_sage.git\n",
+       "   90bd427..77ca92e  main -> main\n",
+       "(py311)\n",
+       "shell_sage on  main via  v3.11.10 via  py311 on   (us-east-1) on ☁️  nc@answer.ai(us-west1)\n",
+       "❯ ssage --s Tell me about XDG Base Directory Specification\n",
+       "powers up documentation circuits with a slight whir\n",
+       "\n",
+       "Ah, the XDG Base D\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1m<\u001b[0m\u001b[1;95mpane\u001b[0m\u001b[39m \u001b[0m\u001b[33mid\u001b[0m\u001b[39m=%\u001b[0m\u001b[1;36m0\u001b[0m\u001b[39m active>Writing objects: \u001b[0m\u001b[1;36m100\u001b[0m\u001b[39m% \u001b[0m\u001b[1;39m(\u001b[0m\u001b[1;36m7\u001b[0m\u001b[39m/\u001b[0m\u001b[1;36m7\u001b[0m\u001b[1;39m)\u001b[0m\u001b[39m, \u001b[0m\u001b[1;36m702\u001b[0m\u001b[39m bytes | \u001b[0m\u001b[1;36m702.00\u001b[0m\u001b[39m KiB/s, done.\u001b[0m\n", + "\u001b[39mTotal \u001b[0m\u001b[1;36m7\u001b[0m\u001b[39m \u001b[0m\u001b[1;39m(\u001b[0m\u001b[39mdelta \u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;39m)\u001b[0m\u001b[39m, reused \u001b[0m\u001b[1;36m0\u001b[0m\u001b[39m \u001b[0m\u001b[1;39m(\u001b[0m\u001b[39mdelta \u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;39m)\u001b[0m\u001b[39m, pack-reused \u001b[0m\u001b[1;36m0\u001b[0m\n", + "\u001b[39mremote: Resolving deltas: \u001b[0m\u001b[1;36m100\u001b[0m\u001b[39m% \u001b[0m\u001b[1;39m(\u001b[0m\u001b[1;36m4\u001b[0m\u001b[39m/\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;39m)\u001b[0m\u001b[39m, completed with \u001b[0m\u001b[1;36m4\u001b[0m\u001b[39m local objects.\u001b[0m\n", + "\u001b[39mTo github.com:AnswerDotAI/shell_sage.git\u001b[0m\n", + "\u001b[39m 90bd427..77ca92e main -\u001b[0m\u001b[1m>\u001b[0m main\n", + "\u001b[1m(\u001b[0mpy311\u001b[1m)\u001b[0m\n", + "shell_sage on  main via  v3.\u001b[1;36m11.10\u001b[0m via  py311 on  \u001b[1m(\u001b[0mus-east-\u001b[1;36m1\u001b[0m\u001b[1m)\u001b[0m on ☁️ nc@\u001b[1;35manswer.ai\u001b[0m\u001b[1m(\u001b[0mus-west1\u001b[1m)\u001b[0m\n", + "❯ ssage --s Tell me about XDG Base Directory Specification\n", + "powers up documentation circuits with a slight whir\n", + "\n", + "Ah, the XDG Base D\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "ps = get_panes(20)\n", + "print(ps[:512])" ] }, { @@ -220,9 +310,9 @@ "#| exports\n", "def get_history(n, pid='current'):\n", " try:\n", - " if pid=='current': return get_pane_output(n)\n", - " if pid=='all': return get_pane_outputs(n)\n", - " return get_pane_output(n, pid)\n", + " if pid=='current': return get_pane(n)\n", + " if pid=='all': return get_panes(n)\n", + " return get_pane(n, pid)\n", " except subprocess.CalledProcessError: return None" ] }, diff --git a/shell_sage/_modidx.py b/shell_sage/_modidx.py index 367011e..316e7ae 100644 --- a/shell_sage/_modidx.py +++ b/shell_sage/_modidx.py @@ -6,6 +6,6 @@ 'git_url': 'https://github.com/AnswerDotAI/shell_sage', 'lib_path': 'shell_sage'}, 'syms': { 'shell_sage.core': { 'shell_sage.core.get_history': ('core.html#get_history', 'shell_sage/core.py'), - 'shell_sage.core.get_pane_output': ('core.html#get_pane_output', 'shell_sage/core.py'), - 'shell_sage.core.get_pane_outputs': ('core.html#get_pane_outputs', 'shell_sage/core.py'), + 'shell_sage.core.get_pane': ('core.html#get_pane', 'shell_sage/core.py'), + 'shell_sage.core.get_panes': ('core.html#get_panes', 'shell_sage/core.py'), 'shell_sage.core.main': ('core.html#main', 'shell_sage/core.py')}}} diff --git a/shell_sage/core.py b/shell_sage/core.py index 661c91c..0eb731e 100644 --- a/shell_sage/core.py +++ b/shell_sage/core.py @@ -1,7 +1,7 @@ # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb. # %% auto 0 -__all__ = ['print', 'sp', 'ssp', 'model', 'cli', 'ss', 'sss', 'get_pane_output', 'get_pane_outputs', 'get_history', 'main'] +__all__ = ['print', 'sp', 'ssp', 'model', 'cli', 'ss', 'sss', 'get_pane', 'get_panes', 'get_history', 'main'] # %% ../nbs/00_core.ipynb 3 from claudette import * @@ -103,27 +103,27 @@ sss = partial(cli, sp=ssp) # %% ../nbs/00_core.ipynb 10 -def get_pane_output(n, pid=None): +def get_pane(n, pid=None): "Get output from a tmux pane" cmd = ['tmux', 'capture-pane', '-p', '-S', f'-{n}'] if pid: cmd += ['-t', pid] return co(cmd, text=True) -# %% ../nbs/00_core.ipynb 11 -def get_pane_outputs(n): - current_id = co(['tmux', 'display-message', '-p', '#{pane_id}'], text=True).strip() +# %% ../nbs/00_core.ipynb 12 +def get_panes(n): + cid = co(['tmux', 'display-message', '-p', '#{pane_id}'], text=True).strip() pids = [p for p in co(['tmux', 'list-panes', '-F', '#{pane_id}'], text=True).splitlines()] - return '\n'.join(f"{get_pane_output(n, p)}" for p in pids) + return '\n'.join(f"{get_pane(n, p)}" for p in pids) -# %% ../nbs/00_core.ipynb 12 +# %% ../nbs/00_core.ipynb 14 def get_history(n, pid='current'): try: - if pid=='current': return get_pane_output(n) - if pid=='all': return get_pane_outputs(n) - return get_pane_output(n, pid) + if pid=='current': return get_pane(n) + if pid=='all': return get_panes(n) + return get_pane(n, pid) except subprocess.CalledProcessError: return None -# %% ../nbs/00_core.ipynb 13 +# %% ../nbs/00_core.ipynb 15 @call_parse def main( query: Param('The query to send to the LLM', str, nargs='+'),