summaryrefslogtreecommitdiff
path: root/emacs/.config
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2023-03-12 13:41:35 -0400
committerKjetil Orbekk <kj@orbekk.com>2023-03-12 13:41:35 -0400
commita51fef44dc43eb9212801cae211bd7d4de65a435 (patch)
treebedc56537ac5fceb01f9f6941908483aeed943a9 /emacs/.config
parented0ddaa8dcee82b8a03efabed17fc61aa4bd31dd (diff)
Update shell config
Diffstat (limited to 'emacs/.config')
-rw-r--r--emacs/.config/emacs-kj/init.el30
-rw-r--r--emacs/.config/emacs-kj/lisp/kj-bindings.el4
-rw-r--r--emacs/.config/emacs-kj/lisp/kj-popup.el4
3 files changed, 33 insertions, 5 deletions
diff --git a/emacs/.config/emacs-kj/init.el b/emacs/.config/emacs-kj/init.el
index bbc6640..bc28b8c 100644
--- a/emacs/.config/emacs-kj/init.el
+++ b/emacs/.config/emacs-kj/init.el
@@ -107,6 +107,35 @@
;; `M-x shell` settings
(setq shell-prompt-pattern "^[^#$%>\n]*[#$%>❯] *")
(setq explicit-shell-file-name "zsh")
+(defun kj/shell-buffer-name ()
+ (concat "*shell:" default-directory "*"))
+
+(defun kj/shell-here ()
+ (interactive)
+ (shell (kj/shell-buffer-name)))
+
+(add-hook 'shell-mode-hook
+ (defun kj/kill-shell-buffer-on-exit ()
+ (let* ((proc (get-buffer-process (current-buffer)))
+ (sentinel (process-sentinel proc)))
+ (set-process-sentinel
+ proc
+ `(lambda (proc signal)
+ (funcall ',sentinel proc signal)
+ (and (memq (process-status proc) '(exit signal))
+ (buffer-live-p (process-buffer proc))
+ (message "Shell died, killing buffer %s"
+ (process-buffer proc))
+ (kill-buffer (process-buffer proc))))))))
+
+(add-hook 'comint-output-filter-functions #'comint-osc-process-output)
+
+;; Update buffer name to reflect directory.
+(advice-add 'cd :after
+ (defun kj/maybe-rename-shell (&rest args)
+ (and (derived-mode-p 'shell-mode)
+ (rename-buffer
+ (kj/shell-buffer-name)))))
(use-package rainbow-delimiters
:defer t
@@ -808,4 +837,3 @@
;; Restore gc.
(setq gc-cons-threshold (* 16 1024 1024))
-
diff --git a/emacs/.config/emacs-kj/lisp/kj-bindings.el b/emacs/.config/emacs-kj/lisp/kj-bindings.el
index 37332f2..144ed43 100644
--- a/emacs/.config/emacs-kj/lisp/kj-bindings.el
+++ b/emacs/.config/emacs-kj/lisp/kj-bindings.el
@@ -3,8 +3,8 @@
(use-package emacs
:bind
(("C-w" . kj/kill-word-or-region)
- ("C-c s" . shell)
- ("C-c e" . eshell)
+ ("C-c s" . kj/shell-here)
+ ("C-c t" . eshell)
("C-c m" . smerge-ediff)
("C-c b r" . revert-buffer)
("C-c r l" . consult-flymake)
diff --git a/emacs/.config/emacs-kj/lisp/kj-popup.el b/emacs/.config/emacs-kj/lisp/kj-popup.el
index 60d0f23..f63fa29 100644
--- a/emacs/.config/emacs-kj/lisp/kj-popup.el
+++ b/emacs/.config/emacs-kj/lisp/kj-popup.el
@@ -39,8 +39,8 @@
(seq "fig: " (* anything))
(seq "*htop*" (* anything))
(seq "*Proced*" (* anything))
- (seq "*eshell*" (* anything))
- (seq "*shell*" (* anything))
+ (seq "*eshell" (* anything))
+ (seq "*shell" (* anything))
"*Occur*")) buffer)
(with-current-buffer buffer
(apply #'derived-mode-p