carapace-sh / carapace-bridge

completion bridge
https://carapace.sh
MIT License
8 stars 1 forks source link

bash bridge spams a script to bash history #197

Closed name-snrl closed 5 months ago

name-snrl commented 5 months ago

Any idea why this entire script, line by line, goes into the bash history when I try to complete a command using bash bridge in both nushell and fish?

https://github.com/carapace-sh/carapace-bridge/blob/a3a0a4692b57b22a52ee7f3ca0612ef72984f759/pkg/actions/bridge/bash.sh#L1-L25

Every time I try to get a complete for the arguments of nix-store, it causes the bash history to be filled with the contents of the script:

# ~/.bash_history
j n c
fish
git st
fish
bash
vi ~/.bash_history
ls
#!/bin/bash
COMP_WORDS=($COMP_LINE)
if [ "${COMP_LINE: -1}" = " " ]; then   COMP_WORDS+=(""); fi
COMP_CWORD=$((${#COMP_WORDS[@]} - 1))
COMP_POINT=${#COMP_LINE}
# bash-completions
[ -f /data/data/com.termux/files/usr/share/bash-completion/bash_completion ] && source /data/data/com.termux/files/usr/share/bash-completion/bash_completion # termux
[ -f /usr/local/share/bash-completion/bash_completion ] && source /usr/local/share/bash-completion/bash_completion # osx
[ -f /usr/share/bash-completion/bash_completion ] && source /usr/share/bash-completion/bash_completion # linux
__load_completion "${COMP_WORDS[0]}"
$"$(complete -p "${COMP_WORDS[0]}" | sed -r 's/.* -F ([^ ]+).*/\1/')"
for i in "${COMPREPLY[@]}"; do   if [[ -d "${i}" && "${i}" != */ ]]; then     echo "${i}/";   else     echo "${i}";   fi; done
#!/bin/bash
COMP_WORDS=($COMP_LINE)
if [ "${COMP_LINE: -1}" = " " ]; then   COMP_WORDS+=(""); fi
COMP_CWORD=$((${#COMP_WORDS[@]} - 1))
COMP_POINT=${#COMP_LINE}
# bash-completions
[ -f /data/data/com.termux/files/usr/share/bash-completion/bash_completion ] && source /data/data/com.termux/files/usr/share/bash-completion/bash_completion # termux
[ -f /usr/local/share/bash-completion/bash_completion ] && source /usr/local/share/bash-completion/bash_completion # osx
[ -f /usr/share/bash-completion/bash_completion ] && source /usr/share/bash-completion/bash_completion # linux
__load_completion "${COMP_WORDS[0]}"
$"$(complete -p "${COMP_WORDS[0]}" | sed -r 's/.* -F ([^ ]+).*/\1/')"
for i in "${COMPREPLY[@]}"; do   if [[ -d "${i}" && "${i}" != */ ]]; then     echo "${i}/";   else     echo "${i}";   fi; done

workaround

#~/.config/carapace/bridge/bash/.bashrc
export HISTFILE=/dev/null

carapace version

> carapace --version
1.0.2

configuration

source <(/nix/store/3wrri355w1kdcd5rc0lg2jscq733hyy6-carapace-1.0.2/bin/carapace _carapace bash)

export CARAPACE_BRIDGES='fish,bash,zsh'
export CARAPACE_EXCLUDES='nix'
name-snrl commented 5 months ago

BTW, not all OS have /bin/bash, shouldn't we replace it with #!/usr/bin/env bash? p.s. NixOS is one of such non-fhs OS, there is no /bin/bash. although bash bridge works

https://github.com/carapace-sh/carapace-bridge/blob/a3a0a4692b57b22a52ee7f3ca0612ef72984f759/pkg/actions/bridge/bash.sh#L1

rsteube commented 5 months ago

Any idea why this entire script, line by line, goes into the bash history when I try to complete a command using bash bridge in both nushell and fish?

It is passed in interactive mode to bash. Seems this way it ends up in the history.


export HISTFILE=/dev/null

Turning it off in the script should indeed fix it.

set +o history # temporarily turn off history

#!/usr/bin/env bash?

Can do. I works either way in this case since it is passed directly to the bash command.

name-snrl commented 5 months ago

Turning it off in the script should indeed fix it.

I think a better solution would be to add +O history directly to the arguments when calling bash, instead of adding set +o history to the script, if I understand your suggestion correctly

edit: nvm, there is no history option in shopt :(

edit[2]: Yeah, you are right, when set +o history is the first line of the script, it is not added to history. As for shebang, I don't think it's needed at all if this file is only used in this way.