Skip to content

Instantly share code, notes, and snippets.

@shaoner
Last active October 6, 2015 09:24
Show Gist options
  • Save shaoner/8a24266b773e796165c3 to your computer and use it in GitHub Desktop.
Save shaoner/8a24266b773e796165c3 to your computer and use it in GitHub Desktop.
emacs tmux navigator
(defun tmux-command (dir)
(shell-command-to-string
(concat "tmux select-pane -" dir)))
(defun last-window-send-tmux (dir tmuxdir)
(let ((other-window (windmove-find-other-window 'right)))
(cond ((null other-window)
(tmux-command tmuxdir))
((and (window-minibuffer-p other-window)
(not (minibuffer-window-active-p other-window)))
(tmux-command tmuxdir))
)
))
(defadvice windmove-right (before windmove-window activate)
(last-window-send-tmux 'right "R"))
(defadvice windmove-left (before windmove-window activate)
(last-window-send-tmux 'left "L"))
(defadvice windmove-up (before windmove-window activate)
(last-window-send-tmux 'up "U"))
(defadvice windmove-down (before windmove-window activate)
(last-window-send-tmux 'down "D"))
is_cmd_prior='echo "#{pane_current_command}" | grep -iqE ".*(emacs(client)?)|(irssi).*"'
bind -n M-Right if-shell "$is_cmd_prior" "send-keys M-Right" "select-pane -R"
bind -n M-Left if-shell "$is_cmd_prior" "send-keys M-Left" "select-pane -L"
bind -n M-Up if-shell "$is_cmd_prior" "send-keys M-Up" "select-pane -U"
bind -n M-Down if-shell "$is_cmd_prior" "send-keys M-Down" "select-pane -D"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment