-
Notifications
You must be signed in to change notification settings - Fork 234
Optionally disable shell history suppression #146
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
Changes from all commits
1c4dd17
67e9a2f
1ae194f
4785b5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| { | ||
| "windows": [ | ||
| { | ||
| "panes": [ | ||
| "echo 'window in the history!'" | ||
| ], | ||
| "focus": true, | ||
| "suppress_history": false, | ||
| "window_name": "appended" | ||
| }, | ||
| { | ||
| "panes": [ | ||
| "echo 'window not in the history!'" | ||
| ], | ||
| "suppress_history": true, | ||
| "window_name": "suppressed" | ||
| }, | ||
| { | ||
| "panes": [ | ||
| "echo 'session in the history!'" | ||
| ], | ||
| "window_name": "default" | ||
| }, | ||
| { | ||
| "panes": [ | ||
| { | ||
| "shell_command": "echo 'command in the history!'", | ||
| "suppress_history": false | ||
| }, | ||
| { | ||
| "shell_command": "echo 'command not in the history!'", | ||
| "suppress_history": true | ||
| }, | ||
| { | ||
| "shell_command": "echo 'window not in the history!'" | ||
| } | ||
| ], | ||
| "suppress_history": true, | ||
| "window_name": "mixed" | ||
| } | ||
| ], | ||
| "suppress_history": false, | ||
| "session_name": "suppress" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| session_name: suppress | ||
| suppress_history: false | ||
| windows: | ||
| - window_name: appended | ||
| focus: true | ||
| suppress_history: false | ||
| panes: | ||
| - echo "window in the history!" | ||
|
|
||
| - window_name: suppressed | ||
| suppress_history: true | ||
| panes: | ||
| - echo "window not in the history!" | ||
|
|
||
| - window_name: default | ||
| panes: | ||
| - echo "session in the history!" | ||
|
|
||
| - window_name: mixed | ||
| suppress_history: false | ||
| panes: | ||
| - shell_command: | ||
| - echo "command in the history!" | ||
| suppress_history: false | ||
| - shell_command: | ||
| - echo "command not in the history!" | ||
| suppress_history: true | ||
| - shell_command: | ||
| - echo "window in the history!" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,7 +75,7 @@ def cmd(self, cmd, *args, **kwargs): | |
|
|
||
| return self.server.cmd(cmd, *args, **kwargs) | ||
|
|
||
| def send_keys(self, cmd, enter=True): | ||
| def send_keys(self, cmd, enter=True, suppress_history=True): | ||
| """``$ tmux send-keys`` to the pane. | ||
|
|
||
| A leading space character is added to cmd to avoid polluting the | ||
|
|
@@ -85,9 +85,12 @@ def send_keys(self, cmd, enter=True): | |
| :type cmd: str | ||
| :param enter: Send enter after sending the input. | ||
| :type enter: bool | ||
| :param suppress_history: Don't add these keys to the shell history | ||
| :type suppress_history: bool | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
|
||
| """ | ||
| self.cmd('send-keys', ' ' + cmd) | ||
| prefix = ' ' if suppress_history else '' | ||
| self.cmd('send-keys', prefix + cmd) | ||
|
|
||
| if enter: | ||
| self.enter() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,12 +14,13 @@ | |
| import tempfile | ||
| import time | ||
| import unittest | ||
| import subprocess | ||
|
|
||
| import kaptan | ||
|
|
||
| from .helpers import TmuxTestCase | ||
| from .. import Window, config, exc | ||
| from .._compat import text_type | ||
| from .._compat import text_type, console_to_str | ||
| from ..workspacebuilder import WorkspaceBuilder | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
@@ -214,6 +215,63 @@ def test_focus_pane_index(self): | |
| self.assertEqual(p.get('pane_current_path'), pane_path) | ||
|
|
||
|
|
||
| class SuppressHistoryTest(TmuxTestCase): | ||
| yaml_config = """ | ||
| session_name: sampleconfig | ||
| start_directory: '~' | ||
| suppress_history: false | ||
| windows: | ||
| - window_name: inHistory | ||
| panes: | ||
| - echo inHistory | ||
| - window_name: isMissing | ||
| suppress_history: true | ||
| panes: | ||
| - echo isMissing | ||
| """ | ||
| def test_suppress_history(self): | ||
| s = self.session | ||
| sconfig = kaptan.Kaptan(handler='yaml') | ||
| sconfig = sconfig.import_config(self.yaml_config).get() | ||
| sconfig = config.expand(sconfig) | ||
| sconfig = config.trickle(sconfig) | ||
|
|
||
| builder = WorkspaceBuilder(sconf=sconfig) | ||
| builder.build(session=self.session) | ||
| time.sleep(0.2) # give .bashrc, etc. time to load | ||
|
|
||
| s.server._update_windows() | ||
| for w in s.windows: | ||
| w.server._update_panes() | ||
| w.select_window() | ||
| for p in w.panes: | ||
| p.select_pane() | ||
|
|
||
| # Print the last-in-history command in the pane | ||
| self.session.cmd('send-keys', ' fc -ln -1') | ||
| self.session.cmd('send-keys', 'Enter') | ||
| time.sleep(0.01) # give fc time to run | ||
|
|
||
| # Get the contents of the pane | ||
| self.session.cmd('capture-pane') | ||
| captured_pane = self.session.cmd('show-buffer') | ||
| self.session.cmd('delete-buffer') | ||
|
|
||
| # Parse the sent and last-in-history commands | ||
| sent_cmd = captured_pane.stdout[0].strip() | ||
| history_cmd = captured_pane.stdout[-2].strip() | ||
|
|
||
| # If it was in the history, sent == history | ||
| if 'inHistory' in sent_cmd: | ||
| self.assertEqual(sent_cmd, history_cmd) | ||
| # Otherwise, sent != history | ||
| elif 'isMissing' in sent_cmd: | ||
| self.assertNotEqual(sent_cmd, history_cmd) | ||
| # Something went wrong | ||
| else: | ||
| self.assertTrue(False) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wow
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not pretty 😁 .
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐒 |
||
|
|
||
| class WindowOptions(TmuxTestCase): | ||
|
|
||
| yaml_config = """ | ||
|
|
@@ -895,5 +953,6 @@ def suite(): | |
| suite.addTest(unittest.makeSuite(WindowAutomaticRename)) | ||
| suite.addTest(unittest.makeSuite(WindowIndexTest)) | ||
| suite.addTest(unittest.makeSuite(WindowOptions)) | ||
| suite.addTest(unittest.makeSuite(SuppressHistoryTest)) | ||
| suite.addTest(unittest.makeSuite(EnvironmentVariables)) | ||
| return suite | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstring here would be nice too (it ends up showing in api docs)