Centralize shell-command-to-string executions of tmux

hello-test
Allard Hendriksen 2018-07-16 13:49:36 +02:00
parent 40dfabed82
commit 0c8b054838
1 changed files with 16 additions and 14 deletions

View File

@ -103,6 +103,13 @@ must be created."
(apply 'start-process
"ob-tmux" "*Messages*" org-babel-tmux-location args))
(defun org-babel-tmux-execute-string (&rest args)
"Executes a tmux command with arguments as given.
Returns stdout as a string."
(shell-command-to-string
(concat org-babel-tmux-location " "
(s-join " " args))))
(defun org-babel-tmux-start-terminal-window (session terminal)
"Starts a terminal window with tmux attached to session."
(let* ((process-name (concat "org-babel: terminal (" session ")")))
@ -120,8 +127,7 @@ must be created."
(defun org-babel-tmux-create-session (session)
"Creates a tmux session if it does not yet exist."
(unless (org-babel-tmux-session-alive-p session)
(org-babel-tmux-execute
"new-session"
(org-babel-tmux-execute "new-session"
"-d" ;; just create the session, don't attach.
"-c" (expand-file-name "~") ;; start in home directory
"-s" (org-babel-tmux-session session)
@ -130,8 +136,7 @@ must be created."
(defun org-babel-tmux-create-window (session)
"Creates a tmux window in session if it does not yet exist."
(unless (org-babel-tmux-window-alive-p session)
(org-babel-tmux-execute
"new-window"
(org-babel-tmux-execute "new-window"
"-c" (expand-file-name "~") ;; start in home directory
"-n" (org-babel-tmux-window-default session)
"-t" (org-babel-tmux-session session))))
@ -140,8 +145,7 @@ must be created."
"If SESSION exists, set option for window."
(let ((alive (org-babel-tmux-session-alive-p session)))
(when alive
(org-babel-tmux-execute
"set-window-option"
(org-babel-tmux-execute "set-window-option"
"-t" (org-babel-tmux-target-session session)
option value))))
@ -204,8 +208,7 @@ If no window is specified, use first window."
(defun org-babel-tmux-session-alive-p (org-session)
"Check if SESSION exists by parsing output of \"tmux ls\"."
(let* ((tmux-ls (shell-command-to-string
(concat org-babel-tmux-location " ls -F '#S'"))
(let* ((tmux-ls (org-babel-tmux-execute-string "ls -F '#S'"))
(tmux-session (org-babel-tmux-session org-session)))
(car
(seq-filter (lambda (x) (string-equal tmux-session x))
@ -217,13 +220,12 @@ If no window is specified, use first window."
If no window is specified in org-session, returns 't."
(let* ((tmux-window (org-babel-tmux-window org-session))
(tmux-target (org-babel-tmux-target-session org-session))
(tmux-lws (shell-command-to-string
(concat org-babel-tmux-location
" list-panes -F 'yes_exists' -t '"
tmux-target "'"))))
(tmux-lws (org-babel-tmux-execute-string
"list-panes"
"-F 'yes_exists'"
"-t" (concat "'" tmux-target "'"))))
(if tmux-window
(progn
(string-equal "yes_exists\n" tmux-lws))
(string-equal "yes_exists\n" tmux-lws)
't)))
(defun org-babel-tmux-open-file (path)