diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2024-01-06 13:40:21 -0500 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2024-01-06 13:40:21 -0500 |
commit | 5f7928a2581036ce5ef400ed376e05d05d3ac966 (patch) | |
tree | a0c55012e1bfe494ec3efc360689ef2f15719f09 | |
parent | a2f318ff5c3140f0855df179ec7edef5dae87293 (diff) |
update
-rw-r--r-- | emacs/.config/emacs-kj/init.el | 6 | ||||
-rw-r--r-- | emacs/.config/emacs-kj/lisp/kj-history.el | 47 | ||||
-rw-r--r-- | zsh/.zshenv | 4 | ||||
-rw-r--r-- | zsh/.zshrc | 4 |
4 files changed, 54 insertions, 7 deletions
diff --git a/emacs/.config/emacs-kj/init.el b/emacs/.config/emacs-kj/init.el index 1168cc5..b596c39 100644 --- a/emacs/.config/emacs-kj/init.el +++ b/emacs/.config/emacs-kj/init.el @@ -254,7 +254,7 @@ (use-package consult ;; Replace bindings. Lazily loaded due by `use-package'. :bind (;; C-c bindings (mode-specific-map) - ("C-c h" . consult-history) + ("C-c h" . kj/consult-history) ;;("C-c m" . consult-mode-command) ("C-c k" . consult-kmacro) ;; C-x bindings (ctl-x-map) @@ -303,8 +303,8 @@ ("M-s L" . consult-line-multi) ;; needed by consult-line to detect isearch ;; Minibuffer history :map minibuffer-local-map - ("M-s" . consult-history) ;; orig. next-matching-history-element - ("M-r" . consult-history)) ;; orig. previous-matching-history-element + ("M-s" . kj/consult-history) ;; orig. next-matching-history-element + ("M-r" . kj/consult-history)) ;; orig. previous-matching-history-element ;; Enable automatic preview at point in the *Completions* buffer. This is ;; relevant when you use the default completion UI. diff --git a/emacs/.config/emacs-kj/lisp/kj-history.el b/emacs/.config/emacs-kj/lisp/kj-history.el new file mode 100644 index 0000000..4119c92 --- /dev/null +++ b/emacs/.config/emacs-kj/lisp/kj-history.el @@ -0,0 +1,47 @@ +(defvar kj/history-command "fc -R $HISTFILE && fc -l 1" + "History command used to get shell history.") + +(defvar kj/history-regexp + (rx bol (* " ") + ;; Index + (* digit) + (* " ") + ;; Command + (group (1+ (not "\n"))))) + +(defun kj/get-shell-history () + (with-temp-buffer + (unless (process-file + "zsh" + nil + (current-buffer) + nil + "-c" + kj/history-command) + (error "Getting history failed: %s" (buffer-string))) + (goto-char (point-min)) + (let ((result)) + (save-match-data + (while (re-search-forward kj/history-regexp nil t) + (push (match-string-no-properties 1) result))) + result))) + +(defun kj/consult-history () + (interactive) + (if (not + (or (and (minibufferp) + (eq minibuffer-history-variable 'shell-command-history)) + (derived-mode-p '(term-mode shell-mode)) + )) + (call-interactively 'consult-history) + (consult--read + (kj/get-shell-history) + :prompt "Shell history: " + :history t + :sort nil + :initial (if (minibufferp) + (buffer-substring-no-properties + (minibuffer-prompt-end) (point-max)) + nil)))) + +(provide 'kj-history) diff --git a/zsh/.zshenv b/zsh/.zshenv index 017e009..6e878b1 100644 --- a/zsh/.zshenv +++ b/zsh/.zshenv @@ -1,3 +1,7 @@ +# History settings +HISTFILE=~/.zsh_history +HISTSIZE=1000000 +SAVEHIST=$HISTSIZE export TZ=America/New_York export ALTERNATE_EDITOR=vim export EDITOR=emacsclient @@ -1,7 +1,3 @@ -# History settings -HISTFILE=~/.zsh_history -HISTSIZE=1000000 -SAVEHIST=$HISTSIZE setopt inc_append_history share_history histignorealldups if [[ ${INSIDE_EMACS} == *comint* ]]; then |