akinomyoga / ble.sh

Bash Line Editor―a line editor written in pure Bash with syntax highlighting, auto suggestions, vim modes, etc. for Bash interactive sessions.
BSD 3-Clause "New" or "Revised" License
2.59k stars 82 forks source link

[histappend/Bash 5.1.4/Tilix/Debian 11] Duplicate entries in ~/.bash_history #277

Open thebahadir opened 1 year ago

thebahadir commented 1 year ago

After installing ble.sh, all commands I type into the shell are recorded twice in a row in the ~/.bash_history I added export HISTCONTROL=ignoreboth:erasedups in ~/.bashrc but nothing changed.

For example;

sudo apt update
apt list --upgradable 
sudo apt full-upgrade -y
sudo apt autoremove 
sudo apt update
apt list --upgradable 
sudo apt full-upgrade -y
sudo apt autoremove 

Thank you in advance for your help.

akinomyoga commented 1 year ago

Which version of ble.sh do you use? If you use 0.3, could you use 0.4. I don't remember the command-history issues (and their situations) caused with v0.3, but there are many improvements in 0.4, and also I'm not planning to fix these minor issues in v0.3.

If you are already using ble-0.4 (in master), it doesn't happen in my environment, and also I haven't recognized the problem so far except in the case where one calls builtin history ... in the Bash configuration. If you don't have builtin history ... in your configuration, depending on the actual cause, maybe I can add some workarounds in ble.sh.

$ ble/widget/display-shell-version
thebahadir commented 1 year ago

Ble.sh version 0.4 and bash version 5.1.4

here is the output of ble/widget/display-shell-version;

GNU bash, version 5.1.4(1)-release (x86_64-pc-linux-gnu) [Debian GNU/Linux 11 (bullseye)]
ble.sh, version 0.4.0-devel3+46ac426 (noarch) [git 2.30.2, GNU Make 4.3, GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.1.0, GNU MP 6.2.1)]
bash-completion, version 2.11 (hash:b4ace8972c413e37d2d899f7a840b5fd7c042685, 76578 bytes) (noarch)
locale: LANG=tr_TR.UTF-8
terminal: TERM=xterm-256color wcwidth=14.0-west/15.0-2+ri, vte:6203 (65;6203;1)

~/.bashrc https://pastebin.mozilla.org/saPFjTBQ

akinomyoga commented 1 year ago

Thank you! I tried your bashrc with Bash-5.1.0 and Bash-5.1.16, but it doesn't seem to reproduce in both versions of Bash.

$ cd
$ mv .bashrc .bashrc.backup20230210 # <-- please save your original .bashrc before testing

$ cat .bashrc      # ... please edit .bashrc to make it have the following contents
export HISTCONTROL=ignoreboth:erasedups
shopt -s histappend
HISTSIZE=1000
HISTFILESIZE=2000
source ~/.local/share/blesh/ble.sh --norc

$ bash   # <-- start a new Bash session
$ echo test2023 # <-- run some command
$ echo test2024 # <-- run some command
$ exit
$ tail .bash_history
thebahadir commented 1 year ago

I did what you said and the problem persists despite this simple ~/.bashrc configuration.

akinomyoga commented 1 year ago

Thank you for testing. Hmm, so maybe some other differences between your environment and mine are causing the issue.

HISTCONTROL=ignoreboth:erasedups
HISTSIZE=1000
HISTFILESIZE=2000
source ~/.local/share/blesh/ble.sh --norc
HISTCONTROL=
shopt -s histappend
HISTSIZE=1000
HISTFILESIZE=2000
source ~/.local/share/blesh/ble.sh --norc
thebahadir commented 1 year ago

This configuration fixed the problem. I'll try to edit bashrc with that in mind. Thank you very much for your interest.

HISTCONTROL=ignoreboth:erasedups
HISTSIZE=1000
HISTFILESIZE=2000
source ~/.local/share/blesh/ble.sh --norc
akinomyoga commented 1 year ago

Thank you for the information! So this means that histappend is related. However, the problem still doesn't seem to reproduce in my environment with shopt -s histappend. Hmm, ...

thebahadir commented 1 year ago

Maybe the problem is with the OS. I am using Debian 11 (Bullseye) on my physical machine. I also have a Debian 11 installed on my virtual machine for testing purposes. I tested it on both physical and virtual machine and both had the same issue.

akinomyoga commented 1 year ago

Thank you. I had an instance of Deabin 10 in a virtual machine, so I tried it there, but the problem still doesn't seem to reproduce. Maybe I need to set up Deabin 11 in a new virtual machine.

But before that, I would like to check about the possibility that the prompt setting might be related.

$ echo "$PS1" | cat -v
$ echo "${PS1@P}" | cat -v
thebahadir commented 1 year ago

"$ echo "$PS1" | cat -v" output; \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$

"$ echo "${PS1@P}" | cat -v" output; ^A^[]0;bahadir@debian: ~^G^B^A^[[01;32m^Bbahadir@debian^A^[[00m^B:^A^[[01;34m^B~^A^[[00m^B$

akinomyoga commented 1 year ago

Hmm, thanks!

$ echo "$PROMPT_COMMAND"
thebahadir commented 1 year ago

$ echo "$PROMPT_COMMAND" output;

__vte_prompt_command

akinomyoga commented 1 year ago

Ah, I suspect this.

$ type __vte_prompt_command
thebahadir commented 1 year ago

I am using Tilix as terminal.

type __vte_prompt_command output;

__vte_prompt_command is a function
__vte_prompt_command()
{
     local pwd='~';
     [ "$PWD" != "$HOME" ] && pwd=${PWD/#$HOME\//\~\/};
     pwd="${pwd//[[:cntrl:]]}";
     printf "\033]0;%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${pwd}";
     __vte_osc7
}
akinomyoga commented 1 year ago

Thanks! Hmm, it doesn't seem to be related as far as I look at the result.

I think I need to later set up Debian 11. If it still doesn't reproduce in my Debian 11, I'll ask further questions later. Thank you!

thebahadir commented 1 year ago

Thank you for your interest and support.

akinomyoga commented 1 year ago

I now set up Debian 11 and tried ble.sh in Bash 5.1.4 / Tilix, but the problem doesn't reproduce. I don't even get the value PROMPT_COMMAND=__vte_prompt_command in https://github.com/akinomyoga/ble.sh/issues/277#issuecomment-1426067197. I suspect you have other Bash configurations.

With the following ~/.bashrc,

# bashrc
HISTCONTROL=ignoreboth:erasedups
HISTSIZE=1000
HISTFILESIZE=2000
shopt -s histappend
source ~/.local/share/blesh/ble.sh --norc

Could you see if the problem persists within a child Bash session started by

$ INPUTRC=/dev/null PS1='\$ ' bash --noprofile
$ echo 2025 # <-- some commands
$ echo 2026 # <-- some commands
$ exit # <-- exit the session
$ tail ~/.bash_history # <-- check if there are duplicate entries of the executed commands
thebahadir commented 1 year ago

I did what you said and saw that the problem did not persist. How can I have a different bash configuration on both my physical machine and virtual machine without my knowledge?

akinomyoga commented 1 year ago

Thank you! Now I guess we can identify the condition to reproduce it soon.

How can I have a different bash configuration on both my physical machine and virtual machine without my knowledge?

Other Bash configurations may be located in /etc/profile, /etc/bash.bashrc, /etc/profile.d, etc. depending on the Linux distributions. One possibility is that a particular package you install on both the physical machine and the virtual machine puts some non-trivial Bash configuration in /etc/profile.d.

$ PS1='\$ ' PS4='+$BASH_SOURCE:$LINENO: ' bash -x # start a new child session here

<--- Could you provide us with the output here?

$ echo 2027 # <-- some commands
$ echo 2028 # <-- some commands
$ exit # <-- exit the session
$ tail ~/.bash_history

<-- Could you again check if there are duplicate entries of the executed commands?
akinomyoga commented 1 year ago
thebahadir commented 1 year ago

Q11: As a next step, could you try the following with the same simple bashrc as https://github.com/akinomyoga/ble.sh/issues/277#issuecomment-1426558893?

The output of the command in question;

+/etc/bash.bashrc:7: '[' -z '\$ ' ']'
+/etc/bash.bashrc:11: shopt -s checkwinsize
+/etc/bash.bashrc:14: '[' -z '' ']'
+/etc/bash.bashrc:14: '[' -r /etc/debian_chroot ']'
+/etc/bash.bashrc:20: '[' -n '' -a -n '' ']'
+/etc/bash.bashrc:21: PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
+/etc/bash.bashrc:44: '[' -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ']'
+/home/bahadir/.bashrc:2: HISTCONTROL=ignoreboth:erasedups
+/home/bahadir/.bashrc:3: HISTSIZE=1000
+/home/bahadir/.bashrc:4: HISTFILESIZE=2000
+/home/bahadir/.bashrc:5: shopt -s histappend
+/home/bahadir/.bashrc:6: source /home/bahadir/.local/share/blesh/ble.sh --norc
++:0: ble/base/attach-from-PROMPT_COMMAND
++/home/bahadir/.local/share/blesh/ble.sh:2: local -a BLE_PIPESTATUS
++/home/bahadir/.local/share/blesh/ble.sh:3: BLE_PIPESTATUS=("${_ble_edit_exec_PIPESTATUS[@]}")
++/home/bahadir/.local/share/blesh/ble.sh:4: ble-edit/exec/.setexit /usr/bin/bash
++/home/bahadir/.local/share/blesh/ble.sh:2: return 0
++/home/bahadir/.local/share/blesh/ble.sh:: LINENO=
++/home/bahadir/.local/share/blesh/ble.sh:: BASH_COMMAND=/usr/bin/bash
++/home/bahadir/.local/share/blesh/ble.sh:5: blehook/invoke internal_PRECMD
++/home/bahadir/.local/share/blesh/ble.sh:2: local -a BLE_PIPESTATUS
++/home/bahadir/.local/share/blesh/ble.sh:3: BLE_PIPESTATUS=("${_ble_edit_exec_PIPESTATUS[@]}")
++/home/bahadir/.local/share/blesh/ble.sh:4: ble-edit/exec/.setexit /usr/bin/bash
++/home/bahadir/.local/share/blesh/ble.sh:2: return 0
++/home/bahadir/.local/share/blesh/ble.sh:: LINENO=
++/home/bahadir/.local/share/blesh/ble.sh:: BASH_COMMAND=/usr/bin/bash
++/home/bahadir/.local/share/blesh/ble.sh:5: blehook/invoke PRECMD
++/home/bahadir/.local/share/blesh/ble.sh:44: ble-attach force
++/home/bahadir/.local/share/blesh/ble.sh:2: (( 1 >= 2 ))
++/home/bahadir/.local/share/blesh/ble.sh:9: [[ -n '' ]]
++/home/bahadir/.local/share/blesh/ble.sh:15: [[ ! -n '' ]]
++/home/bahadir/.local/share/blesh/ble.sh:16: _ble_attached=1
++/home/bahadir/.local/share/blesh/ble.sh:17: BLE_ATTACHED=1
++/home/bahadir/.local/share/blesh/ble.sh:18: builtin eval -- '
    if [[ ! $_ble_bash_FUNCNEST_adjusted ]]; then
      _ble_bash_FUNCNEST_adjusted=1
      _ble_bash_FUNCNEST_set=${FUNCNEST+set}
      _ble_bash_FUNCNEST=${FUNCNEST-}
      builtin unset -v FUNCNEST
    fi 2>/dev/null'
++/home/bahadir/.local/share/blesh/ble.sh:19: ble/base/adjust-builtin-wrappers-1
++/home/bahadir/.local/share/blesh/ble.sh:20: ble/base/adjust-bash-options

I saw that the problem did not persist.

Q12: Do you have ~/.bash_profile or ~/.profile? If any, what are the contents of these files?

There is a ~/.profile file.

~/.profile file content;

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

# Added by Toolbox App
export PATH="$PATH:/home/bahadir/.local/share/JetBrains/Toolbox/scripts"
akinomyoga commented 1 year ago

I saw that the problem did not persist.

Hmm, ... Now I doubt the answer to Q3. Could you try Q3 in https://github.com/akinomyoga/ble.sh/issues/277#issuecomment-1425851115 again? Just to make sure, you need to start the Bash session as a child session as presented in https://github.com/akinomyoga/ble.sh/issues/277#issuecomment-1425851115 but not as a new terminal window.

Q12: Do you have ~/.bash_profile or ~/.profile? If any, what are the contents of these files?

There is a ~/.profile file.

~/.profile file content;

Thanks, this seems to be the same as mine in my Debian 11 instance.

akinomyoga commented 1 year ago

OK, I was checking the configuration of Tilix. It seems there is an option [Profiles] - [Current profile] - [Command] - [Run command as a login shell]. I guess you turned on it. Now I could reproduce your PROMPT_COMMAND=__vte_prompt_command.

However, the problem still doesn't seem to reproduce. Anyway, I currently suspect Bash configurations that are installed in /etc/profile.d in your system.

$ ls /etc/profile.d
$ PS1='\$ ' PS4='+$BASH_SOURCE:$LINENO: ' bash --rcfile /etc/profile -x # start a new child session (without ble.sh)

<--- Could you provide us with the output here?

$ echo 2029

<--- I'm also interested in outputs here.

$ echo 2030

<--- Also here.

$ exit 
akinomyoga commented 1 year ago
$ trap -p
$ builtin trap -p
thebahadir commented 1 year ago

I saw that the problem did not persist.

Hmm, ... Now I doubt the answer to Q3. Could you try Q3 in #277 (comment) again? Just to make sure, you need to start the Bash session as a child session as presented in #277 (comment) but not as a new terminal window.

Q12: Do you have ~/.bash_profile or ~/.profile? If any, what are the contents of these files?

There is a ~/.profile file. ~/.profile file content;

Thanks, this seems to be the same as mine in my Debian 11 instance.

I did what you said and saw that the problem did not persist.

OK, I was checking the configuration of Tilix. It seems there is an option [Profiles] - [Current profile] - [Command] - [Run command as a login shell]. I guess you turned on it. Now I could reproduce your PROMPT_COMMAND=__vte_prompt_command.

I checked and saw that [Run command as login shell] is not selected.

However, the problem still doesn't seem to reproduce. Anyway, I currently suspect Bash configurations that are installed in /etc/profile.d in your system.

  • Q13: What is the output of the following command?
$ ls /etc/profile.d

$ ls /etc/profile.d output;

apps-bin-path.sh    gawk.csh  im-config_wayland.sh  vte.csh
bash_completion.sh  gawk.sh   vte-2.91.sh       vte.sh
  • Q14: What is the result of the following command?

$ PS1='\$ ' PS4='+$BASH_SOURCE:$LINENO: ' bash --rcfile /etc/profile -x # start a new child session (without ble.sh)

Outpu; https://pastebin.mozilla.org/2Xqapocn

$ echo 2029

Output;

+:1: echo 2029
2029
++:1: __vte_prompt_command
++/etc/profile.d/vte.sh:2: local 'pwd=~'
++/etc/profile.d/vte.sh:3: '[' /home/bahadir '!=' /home/bahadir ']'
++/etc/profile.d/vte.sh:4: pwd='~'
++/etc/profile.d/vte.sh:5: printf '\033]0;%s@%s:%s\033\' bahadir debian '~'
++/etc/profile.d/vte.sh:6: __vte_osc7
+++/etc/profile.d/vte.sh:1: /usr/libexec/vte-urlencode-cwd
++/etc/profile.d/vte.sh:2: printf '\033]7;file://%s%s\033\' debian /home/bahadir

$ echo 2030

Output;

+:2: echo 2030
2030
++:2: __vte_prompt_command
++/etc/profile.d/vte.sh:2: local 'pwd=~'
++/etc/profile.d/vte.sh:3: '[' /home/bahadir '!=' /home/bahadir ']'
++/etc/profile.d/vte.sh:4: pwd='~'
++/etc/profile.d/vte.sh:5: printf '\033]0;%s@%s:%s\033\' bahadir debian '~'
++/etc/profile.d/vte.sh:6: __vte_osc7
+++/etc/profile.d/vte.sh:1: /usr/libexec/vte-urlencode-cwd
++/etc/profile.d/vte.sh:2: printf '\033]7;file://%s%s\033\' debian /home/bahadir
  • Q15: Could you also see the output of the following two commands? $ trap -p

Output;

+:3: trap -p
++:3: __vte_prompt_command
++/etc/profile.d/vte.sh:2: local 'pwd=~'
++/etc/profile.d/vte.sh:3: '[' /home/bahadir '!=' /home/bahadir ']'
++/etc/profile.d/vte.sh:4: pwd='~'
++/etc/profile.d/vte.sh:5: printf '\033]0;%s@%s:%s\033\' bahadir debian '~'
++/etc/profile.d/vte.sh:6: __vte_osc7
+++/etc/profile.d/vte.sh:1: /usr/libexec/vte-urlencode-cwd
++/etc/profile.d/vte.sh:2: printf '\033]7;file://%s%s\033\' debian /home/bahadir

$ builtin trap -p

Output;

+:4: builtin trap -p
++:4: __vte_prompt_command
++/etc/profile.d/vte.sh:2: local 'pwd=~'
++/etc/profile.d/vte.sh:3: '[' /home/bahadir '!=' /home/bahadir ']'
++/etc/profile.d/vte.sh:4: pwd='~'
++/etc/profile.d/vte.sh:5: printf '\033]0;%s@%s:%s\033\' bahadir debian '~'
++/etc/profile.d/vte.sh:6: __vte_osc7
+++/etc/profile.d/vte.sh:1: /usr/libexec/vte-urlencode-cwd
++/etc/profile.d/vte.sh:2: printf '\033]7;file://%s%s\033\' debian /home/bahadir
thebahadir commented 1 year ago
  • Q15: Could you also see the output of the following two commands?
$ trap -p
$ builtin trap -p

Sorry, I just realized I'm running these commands in child session now.

I didn't get the output of $ trap -p

$ builtin trap -p Output;

trap -- 'ble/builtin/trap/.handler 0 "$BASH_COMMAND" "$@"; builtin eval -- "${_ble_builtin_trap_postproc[0]}" \# "${_ble_builtin_trap_lastarg[0]}"' EXIT
trap -- 'ble/builtin/trap/.handler 2 "$BASH_COMMAND" "$@"; builtin eval -- "${_ble_builtin_trap_postproc[2]}" \# "${_ble_builtin_trap_lastarg[2]}"' SIGINT
trap -- 'ble/builtin/trap/.handler 28 "$BASH_COMMAND" "$@"; builtin eval -- "${_ble_builtin_trap_postproc[28]}" \# "${_ble_builtin_trap_lastarg[28]}"' SIGWINCH
akinomyoga commented 1 year ago

Thank you very much. Now I don't have an idea what is going on... Maybe the problem disappeared?

# bashrc
shopt -s histappend
HISTCONTROL=
HISTSIZE=1000
HISTFILESIZE=2000
source ~/.local/share/blesh/ble.sh --norc

  • Q15: Could you also see the output of the following two commands?
$ trap -p
$ builtin trap -p

Sorry now I realize I'm running these commands in child session.

I didn't get the output of $ trap -p

$ builtin trap -p Output;

trap -- 'ble/builtin/trap/.handler 0 "$BASH_COMMAND" "$@"; builtin eval -- "${_ble_builtin_trap_postproc[0]}" \# "${_ble_builtin_trap_lastarg[0]}"' EXIT
trap -- 'ble/builtin/trap/.handler 2 "$BASH_COMMAND" "$@"; builtin eval -- "${_ble_builtin_trap_postproc[2]}" \# "${_ble_builtin_trap_lastarg[2]}"' SIGINT
trap -- 'ble/builtin/trap/.handler 28 "$BASH_COMMAND" "$@"; builtin eval -- "${_ble_builtin_trap_postproc[28]}" \# "${_ble_builtin_trap_lastarg[28]}"' SIGWINCH

Don't worry, either works for me. The information that I wanted to check is if there are any DEBUG or other traps set by the external Bash configurations in /etc/profile.d. Now in both cases, I do not see any of external traps. Thank you!

thebahadir commented 1 year ago
  • Q16: Do you still experience the problem with the following simple bashrc now (in a new terminal window or a tile)?
# bashrc
shopt -s histappend
HISTCONTROL=
HISTSIZE=1000
HISTFILESIZE=2000
source ~/.local/share/blesh/ble.sh --norc

I have configured ~/.bashrc accordingly. My problem has resurfaced.

I don't think we should bother anymore. I made you very busy. Thank you very much for your concern. You noticed that when I removed shopt -s histappend from the ~/.bashrc config, the issue was resolved. For me this is enough. Thanks again.

akinomyoga commented 1 year ago

Hmm, OK.

Thank you for your help so far. If you have noticed something later, please feel free to come here again. Thank you very much!


Edit: For my note: