Skip to content

Commit

Permalink
Enhance tmux mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Will committed Jan 10, 2022
1 parent 5b17c65 commit 918d977
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 27 deletions.
39 changes: 28 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,42 @@ Turn it on by setting `tmux: true` in `terminalle.yaml` (see [configuration][10]

The following shortcuts are enabled in tmux mode:

| tmux default | tmux mode | Command |
| -----------: | --------: | :------------------------- |
| `<Prefix> "` | `Ctrl+"` | `split-window` |
| `<Prefix> %` | `Ctrl+%` | `split-window -h` |
| `<Prefix> {` | `Ctrl+{` | `swap-pane -U` |
| `<Prefix> }` | `Ctrl+}` | `swap-pane -D` |
| `<Prefix> [` | `Ctrl+[` | `copy-mode` |
| `<Prefix> ]` | `Ctrl+]` | `paste-buffer` |
| tmux mode | tmux default | Command |
| --------: | -----------: | :------------------------------------------------------------------ |
| `Ctrl+!` | `<Prefix> !` | `break-pane` |
| `Ctrl+"` | `<Prefix> "` | `split-window` |
| `Ctrl+#` | `<Prefix> #` | `list-buffers` |
| `Ctrl+$` | `<Prefix> $` | `command-prompt -I "#S" "rename-session -- '%%'"` |
| `Ctrl+%` | `<Prefix> %` | `split-window -h` |
| `Ctrl+&` | `<Prefix> &` | `confirm-before -p "kill-window #W? (y/n)" kill-window` |
| `Ctrl+'` | `<Prefix> '` | `command-prompt -T window-target -p "index" "select-window -t ':%%'"` |
| `Ctrl+(` | `<Prefix> (` | `switch-client -p` |
| `Ctrl+)` | `<Prefix> )` | `switch-client -n` |
| `Ctrl+,` | `<Prefix> ,` | `command-prompt -I "#W" "rename-window -- '%%'"` |
| `Ctrl+:` | `<Prefix> :` | `command-prompt` |
| `Ctrl+;` | `<Prefix> ;` | `last-pane` |
| `Ctrl+=` | `<Prefix> =` | `choose-buffer -Z` |
| `Ctrl+[` | `<Prefix> [` | `copy-mode` |
| `Ctrl+]` | `<Prefix> ]` | `paste-buffer` |
| `Ctrl+{` | `<Prefix> {` | `swap-pane -U` |
| `Ctrl+}` | `<Prefix> }` | `swap-pane -D` |

To reap maximum benefits, add the following to your `.tmux.conf`,
taking care of other common tmux shortcuts that do not get mangled by typical terminal emulators:

```bash
# Generally shorten `Ctrl+b <X>` to `Ctrl+<X>` for various `<X>`.
# Note that `new-window` is not shortened because `Ctrl+c` should send `SIGINT`.
# Generally shorten `<Prefix> <X>` to `Ctrl+<X>` for various `<X>`.
# Note that some commands (e.g. `<Prefix> c` for `new-window`) would conflict with
# established control sequences (`Ctrl+c` should send `SIGINT`) if shortened.
bind -n C-f command-prompt "find-window -Z -- '%%'"
bind -n C-n next-window
bind -n C-o select-pane -t ":.+"
bind -n C-p previous-window
bind -n C-q display-panes
bind -n C-s choose-tree -Zs
bind -n C-t clock-mode
bind -n C-x confirm-before -p "kill-pane #P? (y/n)" kill-pane
bind -n C-Space next-layout
bind -n C-x confirm-before -p 'kill-pane #P? (y/n)' kill-pane

# Resize panes using arrow keys and either `Ctrl` or `Meta`.
bind -n C-Up resize-pane -U
Expand Down
2 changes: 1 addition & 1 deletion terminalle.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH terminalle 1 "2021-10-03" "v0.6"
.TH terminalle 1 "2021-10-03" "v0.7"

.SH NAME
Terminalle
Expand Down
9 changes: 1 addition & 8 deletions terminalle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,5 @@ colors:
- '#93a1a1' # bright cyan
- '#fdf6e3' # bright white
opacity: 0.75
# If enabled, the `tmux` option hardwires the following tmux shortcuts
# since it is impossible to bind them from `.tmux.conf`:
# Ctrl+" -> split-window
# Ctrl+% -> split-window -h
# Ctrl+{ -> swap-pane -U
# Ctrl+} -> swap-pane -D
# Ctrl+[ -> copy-mode
# Ctrl+] -> paste-buffer
# See the readme for an explanation of the `tmux` option.
tmux: true
2 changes: 1 addition & 1 deletion terminalle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from .terminalle import Terminalle
from .settings import load as load_settings

__version__ = '0.6'
__version__ = '0.7'
31 changes: 25 additions & 6 deletions terminalle/terminalle.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@
</node>
'''

# https://github.com/tmux/tmux/blob/28b6237c623f507188a782a016563c78dd0ffb85/key-bindings.c#L344
# https://cgit.freedesktop.org/xorg/proto/x11proto/plain/keysymdef.h
_default_tmux_commands = [
('exclam', 'break-pane'),
('quotedbl', 'split-window'),
('numbersign', 'list-buffers'),
('dollar', 'command-prompt -I "#S" "rename-session -- '"'"'%%'"'"'"'),
('percent', 'split-window -h'),
('ampersand', 'confirm-before -p "kill-window #W? (y/n)" kill-window'),
('apostrophe', 'command-prompt -T window-target -p "index" "select-window -t '"'"':%%'"'"'"'),
('parenleft', 'switch-client -p'),
('parenright', 'switch-client -n'),
('comma', 'command-prompt -I "#W" "rename-window -- '"'"'%%'"'"'"'),
# ('minus', 'delete-buffer'),
# ('period', 'command-prompt -T target "move-window -t '"'"'%%'"'"'"'),
('colon', 'command-prompt'),
('semicolon', 'last-pane'),
('equal', 'choose-buffer -Z'),
('bracketleft', 'copy-mode'),
('bracketright', 'paste-buffer'),
('braceleft', 'swap-pane -U'),
('braceright', 'swap-pane -D'),
]

class Terminalle:
""" Manages the D-Bus service and the terminal window. """

Expand Down Expand Up @@ -61,12 +85,7 @@ def __init__(self, settings: Dict[str, object], show: bool):
_init_ctrl_shift_handler('v', window, accel_group, self._paste_clipboard)
if settings['tmux']:
# Hardwire shortcuts that are generally impossible to configure in `.tmux.conf`.
for key_name, cmd in [('quotedbl', 'split-window'),
('percent', 'split-window -h'),
('braceleft', 'swap-pane -U'),
('braceright', 'swap-pane -D'),
('bracketleft', 'copy-mode'),
('bracketright', 'paste-buffer')]:
for key_name, cmd in _default_tmux_commands:
_init_ctrl_handler(key_name, window, accel_group, _tmux_cmd(cmd))
window.add_accel_group(accel_group)

Expand Down

0 comments on commit 918d977

Please sign in to comment.