Skip to content

Add tmux fallback in case output of last cmd is not available #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion xontrib/output_search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env xonsh

import re
import re, subprocess
from tokenize_output.tokenize_output import tokenize_output

_key_meta = __xonsh__.env.get('XONTRIB_OUTPUT_SEARCH_KEY_META', 'escape')
Expand Down Expand Up @@ -56,9 +56,19 @@ def _xontrib_output_search_completer(prefix, line, begidx, endidx, ctx):
__xonsh__.completers['xontrib_output_search'] = _xontrib_output_search_completer
__xonsh__.completers.move_to_end('xontrib_output_search', last=False)

def _tmux_current_pane_contents():
if not "TMUX" in __xonsh__.env:
return None
else:
try:
return subprocess.check_output(["tmux", "capture-pane", "-p"], timeout=1).decode()
except:
return None

_color_regexp = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')
@events.on_postcommand
def _save_output(cmd: str, rtn: int, out: str or None, ts: list, **kwargs):
out = out or _tmux_current_pane_contents()
if out is not None:
out = out.strip()
if out:
Expand Down