summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2021-11-03 03:41:16 +0000
committerjao <jao@gnu.org>2021-11-03 03:41:56 +0000
commit4699bf61a37f044d0bf3035fc0907d8ecd5bea12 (patch)
treea462728f6a69f3dc40449374ab29c686efedfeef
parent2ed606540fd3a4302aae86a838f61650a7e2725e (diff)
downloadelibs-4699bf61a37f044d0bf3035fc0907d8ecd5bea12.tar.gz
elibs-4699bf61a37f044d0bf3035fc0907d8ecd5bea12.tar.bz2
vterm-toggle, eshell-vterm
-rw-r--r--exwm.org2
-rw-r--r--init.org102
2 files changed, 59 insertions, 45 deletions
diff --git a/exwm.org b/exwm.org
index 352c8b0..c6ef897 100644
--- a/exwm.org
+++ b/exwm.org
@@ -549,7 +549,6 @@
([?\s-a] . jao-first-window)
([?\s-b] . jao-transient-org-blog)
([?\s-e] . jao-exwm-firefox-1)
- ([?\s-t] . jao-term-here-toggle)
([?\s-m] . jao-transient-media)
([?\s-O] . jao-transpose-windows)
([?\s-o] . jao-other-window)
@@ -557,6 +556,7 @@
([?\s-p] . jao-prev-window)
([?\s-r] . app-launcher-run-app)
([?\s-s] . jao-transient-spotify)
+ ([?\s-t] . vterm)
([?\s-w] . jao-transient-exwm)
([?\s-z] . jao-transient-sleep)
([XF86AudioMute] . jao-mixer-master-toggle)
diff --git a/init.org b/init.org
index 03280df..c6e9ad5 100644
--- a/init.org
+++ b/init.org
@@ -1739,7 +1739,7 @@
;; (transient-get-suffix 'jao-transient-pdf-view '(0 -1))
#+end_src
-* Shells
+* Shells and terms
*** shell modes
#+begin_src emacs-lisp
(setq sh-basic-offset 2)
@@ -1747,24 +1747,56 @@
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
#+end_src
+*** vterm
+ #+begin_src emacs-lisp
+ (use-package vterm-toggle
+ :ensure t
+ :config
+ (defun jao-vterm--toggle (cd)
+ (interactive "P")
+ (if cd (vterm-toggle-cd) (vterm-toggle)))
+ :bind (("C-<f3>" . jao-vterm--toggle)))
+
+ (use-package vterm
+ :ensure t
+ :config
+ :custom ((vterm-kill-buffer-on-exit t)))
+
+ (use-package eshell-vterm
+ :ensure t
+ :config (eshell-vterm-mode))
+
+ (defun jao-exec-in-vterm (cmd bname)
+ (if (string-blank-p (or cmd ""))
+ (vterm)
+ (let ((vterm-shell cmd)
+ (vterm-kill-buffer-on-exit t)
+ (buff (generate-new-buffer bname)))
+ (switch-to-buffer buff)
+ (vterm-mode))))
+
+ #+end_src
*** term
#+begin_src emacs-lisp
(defvar-local jao-term--cmd nil)
+ (defvar jao-use-vterm t)
(defun jao-term--find (cmd)
(seq-find (lambda (b)
(with-current-buffer b
- (and (derived-mode-p 'term-mode)
+ (and (derived-mode-p 'term-mode 'vterm-mode)
(string= (or jao-term--cmd "") cmd))))
(buffer-list)))
(defun jao-exec-in-term (cmd &optional name)
- (ansi-term "bash" name)
- (set-process-sentinel (get-buffer-process (current-buffer))
- (lambda (process event)
- (when (string= event "finished\n")
- (kill-buffer (process-buffer process)))))
- (term-send-string nil (concat cmd ";exit\n")))
+ (if jao-use-vterm
+ (jao-exec-in-vterm cmd name)
+ (ansi-term "bash" name)
+ (set-process-sentinel (get-buffer-process (current-buffer))
+ (lambda (process event)
+ (when (string= event "finished\n")
+ (kill-buffer (process-buffer process)))))
+ (term-send-string nil (concat cmd " ; exit\n"))))
(defmacro jao-def-exec-in-term (name cmd &rest prelude)
`(defun ,(intern (format "jao-term-%s" name)) ()
@@ -1804,7 +1836,7 @@
(eshell-syntax-highlighting-global-mode +1))
#+end_src
***** Visual commands
- #+BEGIN_SRC emacs-lisp
+ #+begin_src emacs-lisp
(require 'em-term)
;;; commands using ansi scape seqs
(dolist (c '("editor" "more" "wget" "dict" "vim" "links" "w3m"
@@ -1813,10 +1845,12 @@
(add-to-list 'eshell-visual-commands c))
(setq eshell-visual-subcommands '(("git" "log" "diff" "show")
- ("sudo" "vim"))
+ ("sudo" "vim")
+ ("rebar3" "shell"))
eshell-destroy-buffer-when-process-dies nil
eshell-escape-control-x t)
- #+END_SRC
+
+ #+end_src
***** bol
#+begin_src emacs-lisp
(defun jao-eshell-maybe-bol ()
@@ -1938,43 +1972,30 @@
*** shell here
#+begin_src emacs-lisp
(defun jao-shell-here--find-window (b)
- (when-let ((w (car (cl-remove-if-not
- `(lambda (w) (eq (window-buffer w) ,b))
- (window-list)))))
+ (when-let (w (seq-find (lambda (w) (eq (window-buffer w) b))
+ (window-list)))
(select-window w)))
- (defvar jao-shell-here-use-term nil)
-
- (defun jao-shell-frame-buffer (&optional b vt)
- (let ((p (if (or vt jao-shell-here-use-term)
- 'jao-term-buffer
- 'jao-eshell-buffer)))
+ (defun jao-shell-frame-buffer (&optional b)
+ (let ((p 'jao-eshell-buffer))
(if b (set-frame-parameter nil p b) (frame-parameter nil p))))
(defun jao-shell--cd-here (dir)
- (if jao-shell-here-use-term
- (progn (term-send-raw-string "\C-a\C-k")
- (term-send-string (format "cd %s\n" dir)))
- (eshell-kill-input)
- (eshell/cd dir)
- (insert "\n")
- (eshell-send-input)))
+ (eshell-kill-input)
+ (eshell/cd dir)
+ (insert "\n")
+ (eshell-send-input))
(defun jao-shell-here (&optional stay)
(interactive)
(let* ((dir default-directory)
(b (jao-shell-frame-buffer)))
- (jao-with-attached-buffer "^\\*\\(ansi-term\\|eshell\\)" 35
+ (jao-with-attached-buffer "^\\*eshell" 35
(if (buffer-live-p b)
(pop-to-buffer b nil t)
- (if jao-shell-here-use-term
- (jao-exec-in-term "")
- (eshell (when (and (boundp 'jao-exwm--use-afio)
- (not jao-exwm--use-afio))
- exwm-workspace-current-index)))
- (jao-shell-frame-buffer (current-buffer))))
- (when (not jao-shell-here-use-term)
- (eshell-save-some-history))
+ (eshell)
+ (jao-shell-frame-buffer (current-buffer))))
+ (eshell-save-some-history)
(unless stay (jao-shell--cd-here dir))))
(defun eshell/x ()
@@ -1982,9 +2003,7 @@
(when (fboundp 'eshell-autojump-save)
(eshell-autojump-save))
(eshell-save-some-history))
- (if (> (frame-height) (window-height))
- (delete-window)
- (bury-buffer)))
+ (if (> (frame-height) (window-height)) (delete-window) (bury-buffer)))
(defun jao-shell-here-toggle ()
(interactive)
@@ -1993,11 +2012,6 @@
(eshell/x)
(jao-shell-here t)))
- (defun jao-term-here-toggle ()
- (interactive)
- (let ((jao-shell-here-use-term t))
- (call-interactively 'jao-shell-here-toggle)))
-
(global-set-key (kbd "C-!") #'jao-shell-here)
(global-set-key [(f1)] #'jao-shell-here-toggle)
#+end_src