Centralize shell-command-to-string executions of tmux
parent
40dfabed82
commit
0c8b054838
30
ob-tmux.el
30
ob-tmux.el
|
@ -103,6 +103,13 @@ must be created."
|
||||||
(apply 'start-process
|
(apply 'start-process
|
||||||
"ob-tmux" "*Messages*" org-babel-tmux-location args))
|
"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)
|
(defun org-babel-tmux-start-terminal-window (session terminal)
|
||||||
"Starts a terminal window with tmux attached to session."
|
"Starts a terminal window with tmux attached to session."
|
||||||
(let* ((process-name (concat "org-babel: terminal (" session ")")))
|
(let* ((process-name (concat "org-babel: terminal (" session ")")))
|
||||||
|
@ -120,8 +127,7 @@ must be created."
|
||||||
(defun org-babel-tmux-create-session (session)
|
(defun org-babel-tmux-create-session (session)
|
||||||
"Creates a tmux session if it does not yet exist."
|
"Creates a tmux session if it does not yet exist."
|
||||||
(unless (org-babel-tmux-session-alive-p session)
|
(unless (org-babel-tmux-session-alive-p session)
|
||||||
(org-babel-tmux-execute
|
(org-babel-tmux-execute "new-session"
|
||||||
"new-session"
|
|
||||||
"-d" ;; just create the session, don't attach.
|
"-d" ;; just create the session, don't attach.
|
||||||
"-c" (expand-file-name "~") ;; start in home directory
|
"-c" (expand-file-name "~") ;; start in home directory
|
||||||
"-s" (org-babel-tmux-session session)
|
"-s" (org-babel-tmux-session session)
|
||||||
|
@ -130,8 +136,7 @@ must be created."
|
||||||
(defun org-babel-tmux-create-window (session)
|
(defun org-babel-tmux-create-window (session)
|
||||||
"Creates a tmux window in session if it does not yet exist."
|
"Creates a tmux window in session if it does not yet exist."
|
||||||
(unless (org-babel-tmux-window-alive-p session)
|
(unless (org-babel-tmux-window-alive-p session)
|
||||||
(org-babel-tmux-execute
|
(org-babel-tmux-execute "new-window"
|
||||||
"new-window"
|
|
||||||
"-c" (expand-file-name "~") ;; start in home directory
|
"-c" (expand-file-name "~") ;; start in home directory
|
||||||
"-n" (org-babel-tmux-window-default session)
|
"-n" (org-babel-tmux-window-default session)
|
||||||
"-t" (org-babel-tmux-session session))))
|
"-t" (org-babel-tmux-session session))))
|
||||||
|
@ -140,8 +145,7 @@ must be created."
|
||||||
"If SESSION exists, set option for window."
|
"If SESSION exists, set option for window."
|
||||||
(let ((alive (org-babel-tmux-session-alive-p session)))
|
(let ((alive (org-babel-tmux-session-alive-p session)))
|
||||||
(when alive
|
(when alive
|
||||||
(org-babel-tmux-execute
|
(org-babel-tmux-execute "set-window-option"
|
||||||
"set-window-option"
|
|
||||||
"-t" (org-babel-tmux-target-session session)
|
"-t" (org-babel-tmux-target-session session)
|
||||||
option value))))
|
option value))))
|
||||||
|
|
||||||
|
@ -204,8 +208,7 @@ If no window is specified, use first window."
|
||||||
|
|
||||||
(defun org-babel-tmux-session-alive-p (org-session)
|
(defun org-babel-tmux-session-alive-p (org-session)
|
||||||
"Check if SESSION exists by parsing output of \"tmux ls\"."
|
"Check if SESSION exists by parsing output of \"tmux ls\"."
|
||||||
(let* ((tmux-ls (shell-command-to-string
|
(let* ((tmux-ls (org-babel-tmux-execute-string "ls -F '#S'"))
|
||||||
(concat org-babel-tmux-location " ls -F '#S'"))
|
|
||||||
(tmux-session (org-babel-tmux-session org-session)))
|
(tmux-session (org-babel-tmux-session org-session)))
|
||||||
(car
|
(car
|
||||||
(seq-filter (lambda (x) (string-equal tmux-session x))
|
(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."
|
If no window is specified in org-session, returns 't."
|
||||||
(let* ((tmux-window (org-babel-tmux-window org-session))
|
(let* ((tmux-window (org-babel-tmux-window org-session))
|
||||||
(tmux-target (org-babel-tmux-target-session org-session))
|
(tmux-target (org-babel-tmux-target-session org-session))
|
||||||
(tmux-lws (shell-command-to-string
|
(tmux-lws (org-babel-tmux-execute-string
|
||||||
(concat org-babel-tmux-location
|
"list-panes"
|
||||||
" list-panes -F 'yes_exists' -t '"
|
"-F 'yes_exists'"
|
||||||
tmux-target "'"))))
|
"-t" (concat "'" tmux-target "'"))))
|
||||||
(if tmux-window
|
(if tmux-window
|
||||||
(progn
|
(string-equal "yes_exists\n" tmux-lws)
|
||||||
(string-equal "yes_exists\n" tmux-lws))
|
|
||||||
't)))
|
't)))
|
||||||
|
|
||||||
(defun org-babel-tmux-open-file (path)
|
(defun org-babel-tmux-open-file (path)
|
||||||
|
|
Loading…
Reference in New Issue