Redo tmux library + ex commands

This commit is contained in:
Henrik Lissner 2015-12-09 01:17:08 -05:00
parent ae391a3356
commit 4882df4847
2 changed files with 47 additions and 10 deletions

View file

@ -1,21 +1,55 @@
;;; defuns-tmux.el
(defun narf--send-to-tmux (command)
(shell-command (format "tmux send-keys %s" command)))
;;;###autoload
(defun tmux (command &optional run)
(shell-command (format (concat "tmux send-keys " (if run "C-u %s Enter" "%s"))
(shell-quote-argument command))))
(evil-define-interactive-code "<term>"
"Ex tmux argument (a mix between <sh> <f> and <fsh>)"
:ex-arg shell
(list (when (evil-ex-p) (evil-ex-file-arg))))
;;;###autoload (autoload 'narf:send-to-tmux "defuns-term" nil t)
(evil-define-command narf:send-to-tmux (command &optional bang)
;;;###autoload (autoload 'narf:tmux-cd "defuns-term" nil t)
(evil-define-command narf:tmux-cd (&optional bang)
(interactive "<!>")
(if bang
(narf/tmux-cd-to-project)
(narf/tmux-cd-to-here)))
;;;###autoload (autoload 'narf:tmux "defuns-term" nil t)
(evil-define-operator narf:tmux (beg end &optional command bang)
"Sends input to tmux. Use `bang' to append to tmux"
(interactive "<term><!>")
(narf--send-to-tmux (format (if bang "%s" "C-u %s Enter")
(shell-quote-argument command)))
:type inclusive
:repeat t
(interactive "<r><term><!>")
(if (not command)
(os-switch-to-term)
(when (use-region-p)
(setq command (concat command (buffer-substring-no-properties beg end))))
(tmux command bang)
(when (evil-ex-p)
(message "[Tmux] %s" command)))
(message "[Tmux] %s" command))))
;;;###autoload
(defun narf/tmux-new-window ()
(interactive)
(tmux "tmux new-window" t))
;;;###autoload
(defun narf/tmux-split-window (&optional vertical)
(interactive)
(tmux (concat "tmux split-window" (if vertical " -h"))))
;;;###autoload
(defun narf/tmux-cd-to-here (&optional dir)
(interactive)
(tmux (format "cd '%s'" (or dir default-directory))))
;;;###autoload
(defun narf/tmux-cd-to-project ()
(interactive)
(narf/tmux-cd-to-here (narf/project-root)))
(provide 'defuns-tmux)
;;; defuns-tmux.el ends here

View file

@ -47,7 +47,10 @@
(exmap "@" 'narf/evil-macro-on-all-lines)
(exmap "t[mux]" 'narf:send-to-tmux)
(exmap "tcd" (λ (narf:send-to-tmux (format "cd '%s'" default-directory))))
(exmap "t[mux]w" 'narf/tmux-new-window)
(exmap "t[mux]s" 'narf/tmux-split-window)
(exmap "t[mux]v" (λ (narf/tmux-split-window t)))
(exmap "tcd" 'narf:tmux-cd)
(exmap "cont[act]" 'narf:org-crm-contact)
(exmap "proj[ect]" 'narf:org-crm-project)