emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/bash-completion ba2f7e922f 4/8: Fix history uncluttering w


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion ba2f7e922f 4/8: Fix history uncluttering when Bash version is >= 5.1 (#57)
Date: Sun, 15 Jan 2023 12:58:33 -0500 (EST)

branch: elpa/bash-completion
commit ba2f7e922f9492bd96d8237f65603cea66e194b5
Author: montag451 <montag451@laposte.net>
Commit: GitHub <noreply@github.com>

    Fix history uncluttering when Bash version is >= 5.1 (#57)
    
    Since Bash version 5.1, the behaviour of HISTCMD has been changed and
    it breaks history uncluttering. This commit solves this problem by
    checking the Bash major version and by using the appropriate command
    to unclutter the history.
---
 bash-completion.el | 85 +++++++++++++++++++++++++++++-------------------------
 1 file changed, 46 insertions(+), 39 deletions(-)

diff --git a/bash-completion.el b/bash-completion.el
index 8bb1a137d9..21eca7679c 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -1218,45 +1218,52 @@ completion in these cases."
           ;; interfere with bash-completion-send detecting the end
           ;; of a command. It disables prompt to avoid interference
           ;; from commands run by prompts.
-          (comint-send-string
-           process
-           (concat
-            "set +o emacs;"
-            "set +o vi;"
-            "if [[ -z \"$__emacs_complete_ps1\" ]]; then"
-            "  __emacs_complete_ps1=\"$PS1\";"
-            "  __emacs_complete_pc=\"$PROMPT_COMMAND\";"
-            "fi;"
-            "PS1='' PROMPT_COMMAND='';"
-            "history &>/dev/null -d $((HISTCMD - 1)) || true\n"))
-
-          ;; The following is a bootstrap command for
-          ;; bash-completion-send itself.
-          (bash-completion-send
-           (concat
-            "function __emacs_complete_pre_command {"
-            "  if [[ -z \"$__emacs_complete_ps1\" ]]; then"
-            "    __emacs_complete_ps1=\"$PS1\";"
-            "    __emacs_complete_pc=\"$PROMPT_COMMAND\";"
-            "  fi;"
-            "  PROMPT_COMMAND=__emacs_complete_prompt;"
-            "  history &>/dev/null -d $((HISTCMD - 1)) || true;"
-            "} &&"
-            "function __emacs_complete_prompt {"
-            "  PS1=" bash-completion--ps1 ";"
-            "  PROMPT_COMMAND=__emacs_complete_recover_prompt;"
-            "} &&"
-            "function __emacs_complete_recover_prompt {"
-            "  local r=$?;"
-            "  PS1=\"${__emacs_complete_ps1}\";"
-            "  PROMPT_COMMAND=\"${__emacs_complete_pc}\";"
-            "  unset __emacs_complete_ps1 __emacs_complete_pc;"
-            "  if [[ -n \"$PROMPT_COMMAND\" ]]; then"
-            "    (exit $r); eval \"$PROMPT_COMMAND\";"
-            "  fi;"
-            "} &&"
-            "__emacs_complete_pre_command")
-           process)
+          (let* ((history-unclutter-cmd
+                  (concat
+                   "if [[ ${BASH_VERSINFO[0]} -eq 5 && ${BASH_VERSINFO[1]} -ge 
1 || ${BASH_VERSINFO[0]} -gt 5 ]]; then"
+                   "  history -d $HISTCMD &>/dev/null || true;"
+                   "else"
+                   "  history -d $((HISTCMD - 1)) &>/dev/null || true;"
+                   "fi")))
+            (comint-send-string
+             process
+             (concat
+              "set +o emacs;"
+              "set +o vi;"
+              "if [[ -z \"$__emacs_complete_ps1\" ]]; then"
+              "  __emacs_complete_ps1=\"$PS1\";"
+              "  __emacs_complete_pc=\"$PROMPT_COMMAND\";"
+              "fi;"
+              "PS1='' PROMPT_COMMAND='';"
+              history-unclutter-cmd "\n"))
+
+            ;; The following is a bootstrap command for
+            ;; bash-completion-send itself.
+            (bash-completion-send
+             (concat
+              "function __emacs_complete_pre_command {"
+              "  if [[ -z \"$__emacs_complete_ps1\" ]]; then"
+              "    __emacs_complete_ps1=\"$PS1\";"
+              "    __emacs_complete_pc=\"$PROMPT_COMMAND\";"
+              "  fi;"
+              "  PROMPT_COMMAND=__emacs_complete_prompt;"
+              "  " history-unclutter-cmd ";"
+              "} &&"
+              "function __emacs_complete_prompt {"
+              "  PS1=" bash-completion--ps1 ";"
+              "  PROMPT_COMMAND=__emacs_complete_recover_prompt;"
+              "} &&"
+              "function __emacs_complete_recover_prompt {"
+              "  local r=$?;"
+              "  PS1=\"${__emacs_complete_ps1}\";"
+              "  PROMPT_COMMAND=\"${__emacs_complete_pc}\";"
+              "  unset __emacs_complete_ps1 __emacs_complete_pc;"
+              "  if [[ -n \"$PROMPT_COMMAND\" ]]; then"
+              "    (exit $r); eval \"$PROMPT_COMMAND\";"
+              "  fi;"
+              "} &&"
+              "__emacs_complete_pre_command")
+             process))
           (bash-completion--setup-bash-common process))
         process))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]