Last active
December 19, 2015 04:29
-
-
Save nathanlippi/5897747 to your computer and use it in GitHub Desktop.
Based on the following blog post:
http://bradylove.com/blog/2013/05/24/commanding-tmux-with-emacs/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun tmux-display-message(arg) | |
(s-trim-right (shell-command-to-string (format "tmux display-message -p '#%s'" arg)))) | |
(defun tmux-get-current-session-name() (tmux-display-message "S")) | |
(defun tmux-get-current-window-number() (tmux-display-message "I")) | |
(defun tmux-get-current-pane() (tmux-display-message "P")) | |
(defun tmux-get-runner-pane() | |
"Get # of current pane, and then use that to guess the # of the runner/term pane. | |
I wonder if there is a better way to do this?" | |
(+ (string-to-number (tmux-get-current-pane)) 1)) | |
;; http://ergoemacs.org/emacs/modernization_elisp_lib_problem.html | |
(defun s-trim-right (s) | |
"Remove whitespace at the end of S." | |
(if (string-match "[ \t\n\r]+\\'" s) | |
(replace-match "" t t s) | |
s)) | |
(defun tmux-exec (command &optional pane-number) | |
"Execute command in tmux current tmux session, window and pane." | |
(interactive) | |
(shell-command-to-string | |
(format "tmux send-keys -t %s:%s.%s '%s' Enter" | |
(tmux-get-current-session-name) (tmux-get-current-window-number) | |
(if pane-number pane-number (tmux-get-current-pane)) command))) | |
(defun tmux-exec-in-runner-pane-or-without (command) | |
"Tries to execute in runner pane; if output indicates no success, execute w/o tmux." | |
(if (string-prefix-p "can't find pane:" (tmux-exec command (tmux-get-runner-pane))) | |
(shell-command command))) | |
(defun tmux-exec-in-runner-pane-or-without-interactive(command) | |
(interactive "sTmux/Shell Command: ") | |
(tmux-exec-in-runner-pane-or-without command)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment