Skip to content

Instantly share code, notes, and snippets.

@syohex
Created May 13, 2014 09:13
Show Gist options
  • Save syohex/3f4f7db05643ff5e1c54 to your computer and use it in GitHub Desktop.
Save syohex/3f4f7db05643ff5e1c54 to your computer and use it in GitHub Desktop.
Implement yank tmux buffer
diff --git a/emamux.el b/emamux.el
index 6428e26..706d5e8 100644
--- a/emamux.el
+++ b/emamux.el
@@ -149,6 +149,17 @@
(push (match-string-no-properties 1) sessions))
sessions)))
+(defun emamux:get-buffers ()
+ (with-temp-buffer
+ (emamux:tmux-run-command "list-buffers" t)
+ (goto-char (point-min))
+ (cl-loop while
+ (re-search-forward
+ "^\\(?:[0-9]+\\): +\\(?:[0-9]+\\) +\\(?:bytes\\): +[\"]\\(.*\\)[\"]" nil t)
+ for buffer-index = 0 then (+ buffer-index 1)
+ collect
+ (propertize (match-string-no-properties 1) 'index buffer-index))))
+
(defun emamux:get-window ()
(with-temp-buffer
(emamux:tmux-run-command (format "list-windows -t %s" emamux:session) t)
@@ -204,6 +215,20 @@
(data (substring-no-properties (car kill-ring))))
(emamux:set-buffer data index)))
+(defun emamux:show-buffer-by-index (index)
+ (with-temp-buffer
+ (emamux:tmux-run-command (format "show-buffer -b%d" index) t)
+ (buffer-string)))
+
+;;;###autoload
+(defun emamux:yank-from-list-buffers ()
+ "Yank text copied from tmux."
+ (interactive)
+ (let* ((candidates (emamux:get-buffers))
+ (buffer (emamux:completing-read "Buffers: " candidates)))
+ (insert
+ (emamux:show-buffer-by-index (get-text-property 0 'index buffer)))))
+
;;;###autoload
(defun emamux:kill-session ()
"Kill tmux session"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment