Skip to content

Commit

Permalink
Allow overriding some keys through options
Browse files Browse the repository at this point in the history
  • Loading branch information
farzadmf committed Jul 26, 2021
1 parent fef77c8 commit bb13878
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Tmux Tilish

## Changes in this fork:

- A lot of keybindings are configurable through `set -g @tilish-<option> "<val>"`

---

This is a plugin that makes [`tmux`][6] behave more like a typical
[dynamic window manager][7]. It is heavily inspired by [`i3wm`][8], and
most keybindings are taken [directly from there][1]. However, I have made
Expand Down Expand Up @@ -101,6 +107,8 @@ Finally, here is a list of the actual keybindings. Most are [taken from `i3wm`][
Below, a "workspace" is what `tmux` would call a "window" and `vim` would call a "tab",
while a "pane" is what `i3wm` would call a "window" and `vim` would call a "split".

NOTE: a bunch of the following keys can be overridden through the options (see below).

| Keybinding | Description |
| ---------- | ----------- |
| <kbd>Alt</kbd> + <kbd>0</kbd>-<kbd>9</kbd> | Switch to workspace number 0-9 |
Expand All @@ -123,6 +131,17 @@ while a "pane" is what `i3wm` would call a "window" and `vim` would call a "spli
The <kbd>Alt</kbd> + <kbd>0</kbd> and <kbd>Alt</kbd> + <kbd>Shift</kbd> + <kbd>0</kbd>
bindings are "smart": depending on `base-index`, they either act on workspace 0 or 10.

The following options can be used to override some keys mentioned in the above table (if they're not
set, the default value will be used):
- `set -g @tilish-split_vsplit "..."` (default <kbd>s</kbd>)
- `set -g @tilish-split_only "..."` (default <kbd>S</kbd>)
- `set -g @tilish-vsplit_split "..."` (default <kbd>v</kbd>)
- `set -g @tilish-vsplit_only "..."` (default <kbd>V</kbd>)
- `set -g @tilish-tiled "..."` (default <kbd>t</kbd>)
- `set -g @tilish-zoom "..."` (default <kbd>z</kbd>)
- `set -g @tilish-refresh "..."` (default <kbd>r</kbd>)
- `set -g @tilish-rename "..."` (default <kbd>n</kbd>)

The keybindings that move panes between workspaces assume a US keyboard layout.
However, you can configure `tilish` for international keyboards by providing a string
`@tilish-shiftnum` prepared by pressing <kbd>Shift</kbd> +
Expand Down
39 changes: 26 additions & 13 deletions tilish.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
legacy="$(tmux -V | grep -E 'tmux (1\.|2\.[0-6])')"

# Read user options.
for opt in default dmenu easymode navigate navigator prefix shiftnum
for opt in \
default dmenu easymode navigate navigator prefix shiftnum \
split_vsplit split_only vsplit_split vsplit_only \
tiled zoom refresh rename
do
export "$opt"="$(tmux show-option -gv @tilish-"$opt" 2>/dev/null)"
done
Expand All @@ -30,6 +33,15 @@
shiftnum='!@#$%^&*()'
fi

if [ -z "$split_vsplit" ]; then split_vsplit="s" ; fi
if [ -z "$split_only" ]; then split_only="S" ; fi
if [ -z "$vsplit_split" ]; then vsplit_split="v" ; fi
if [ -z "$vsplit_only" ]; then vsplit_only="V" ; fi
if [ -z "$tiled" ]; then tiled="t" ; fi
if [ -z "$zoom" ]; then zoom="z" ; fi
if [ -z "$refresh" ]; then refresh="r" ; fi
if [ -z "$rename" ]; then rename="n" ; fi

# Determine "arrow types".
if [ "${easymode:-}" = "on" ]
then
Expand Down Expand Up @@ -148,22 +160,23 @@ else
bind_move "${mod}$(char_at "$shiftnum" 10)" 0
fi

# Switch layout with Alt + <mnemonic key>. The mnemonics are `s` and `S` for
# layouts Vim would generate with `:split`, and `v` and `V` for `:vsplit`.
# Switch layout with Alt + <mnemonic key>.
# The keys can be overridden, but the default mnemonics are
# `s` and `S` for layouts Vim would generate with `:split`, and `v` and `V` for `:vsplit`.
# The remaining mappings based on `z` and `t` should be quite obvious.
bind_layout "${mod}s" 'main-horizontal'
bind_layout "${mod}S" 'even-vertical'
bind_layout "${mod}v" 'main-vertical'
bind_layout "${mod}V" 'even-horizontal'
bind_layout "${mod}t" 'tiled'
bind_layout "${mod}z" 'zoom'
bind_layout "${mod}${split_vsplit}" 'main-horizontal'
bind_layout "${mod}${split_only}" 'even-vertical'
bind_layout "${mod}${vsplit_split}" 'main-vertical'
bind_layout "${mod}${vsplit_only}" 'even-horizontal'
bind_layout "${mod}${tiled}" 'tiled'
bind_layout "${mod}${zoom}" 'zoom'

# Refresh the current layout (e.g. after deleting a pane).
if [ -z "$legacy" ]
then
tmux $bind "${mod}r" select-layout -E
tmux $bind "${mod}${refresh}" select-layout -E
else
tmux $bind "${mod}r" run-shell 'tmux select-layout'\\\; send escape
tmux $bind "${mod}${refresh}" run-shell 'tmux select-layout'\\\; send escape
fi

# Switch to pane via Alt + hjkl.
Expand Down Expand Up @@ -199,8 +212,8 @@ else
send escape
fi

# Name a window with Alt + n.
tmux $bind "${mod}n" \
# Name a window with Alt + n (or the key set through the options)
tmux $bind "${mod}${rename}" \
command-prompt -p 'Workspace name:' 'rename-window "%%"'

# Close a window with Alt + Shift + q.
Expand Down

0 comments on commit bb13878

Please sign in to comment.