mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
bash: revert automatic shell integration changes (#5249)
The intention of #5075 was to create a less intrusive, more hermetic environment in which to source the bash startup files. This caused problems for multiple people, and I believe that's because the general expectation is that these files are sourced at global (not function) scope. For example, when a file is sourced from within a function scope, any variables that weren't explicitly exported into the global environment won't be available outside of the scope of the function. Most system and personal startup files aren't written with that constraint because it's not how bash itself loads these files. As a small improvement over the original code, `rcfile` has been renamed to `__ghostty_rcfile`. Avoiding leaking this variable while sourcing these files was a goal of #5075, and prefixing it make it much less of a potential issue. This change also reverts the $HOME -> ~/ change. While the ~/ notation is more concise, using $HOME is more common and easier to implement safely with regard to quoting. Fixes #5206
This commit is contained in:
@ -41,14 +41,11 @@ if [ -n "$GHOSTTY_BASH_INJECT" ]; then
|
|||||||
|
|
||||||
# Manually source the startup files. See INVOCATION in bash(1) and
|
# Manually source the startup files. See INVOCATION in bash(1) and
|
||||||
# run_startup_files() in shell.c in the Bash source code.
|
# run_startup_files() in shell.c in the Bash source code.
|
||||||
function __ghostty_bash_startup() {
|
|
||||||
builtin local rcfile
|
|
||||||
|
|
||||||
if builtin shopt -q login_shell; then
|
if builtin shopt -q login_shell; then
|
||||||
if [[ $__ghostty_bash_flags != *"--noprofile"* ]]; then
|
if [[ $__ghostty_bash_flags != *"--noprofile"* ]]; then
|
||||||
[ -r /etc/profile ] && builtin source "/etc/profile"
|
[ -r /etc/profile ] && builtin source "/etc/profile"
|
||||||
for rcfile in ~/.bash_profile ~/.bash_login ~/.profile; do
|
for __ghostty_rcfile in "$HOME/.bash_profile" "$HOME/.bash_login" "$HOME/.profile"; do
|
||||||
[ -r "$rcfile" ] && { builtin source "$rcfile"; break; }
|
[ -r "$__ghostty_rcfile" ] && { builtin source "$__ghostty_rcfile"; break; }
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@ -59,19 +56,16 @@ if [ -n "$GHOSTTY_BASH_INJECT" ]; then
|
|||||||
# Fedora uses /etc/bashrc sourced from ~/.bashrc instead of SYS_BASHRC
|
# Fedora uses /etc/bashrc sourced from ~/.bashrc instead of SYS_BASHRC
|
||||||
# Void Linux uses /etc/bash/bashrc
|
# Void Linux uses /etc/bash/bashrc
|
||||||
# Nixos uses /etc/bashrc
|
# Nixos uses /etc/bashrc
|
||||||
for rcfile in /etc/bash.bashrc /etc/bash/bashrc /etc/bashrc; do
|
for __ghostty_rcfile in /etc/bash.bashrc /etc/bash/bashrc /etc/bashrc; do
|
||||||
[ -r "$rcfile" ] && { builtin source "$rcfile"; break; }
|
[ -r "$__ghostty_rcfile" ] && { builtin source "$__ghostty_rcfile"; break; }
|
||||||
done
|
done
|
||||||
if [[ -z "$GHOSTTY_BASH_RCFILE" ]]; then GHOSTTY_BASH_RCFILE=~/.bashrc; fi
|
if [[ -z "$GHOSTTY_BASH_RCFILE" ]]; then GHOSTTY_BASH_RCFILE="$HOME/.bashrc"; fi
|
||||||
[ -r "$GHOSTTY_BASH_RCFILE" ] && builtin source "$GHOSTTY_BASH_RCFILE"
|
[ -r "$GHOSTTY_BASH_RCFILE" ] && builtin source "$GHOSTTY_BASH_RCFILE"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
__ghostty_bash_startup
|
builtin unset __ghostty_rcfile
|
||||||
|
builtin unset __ghostty_bash_flags
|
||||||
builtin unset -f __ghostty_bash_startup
|
|
||||||
builtin unset -v __ghostty_bash_flags
|
|
||||||
builtin unset GHOSTTY_BASH_RCFILE
|
builtin unset GHOSTTY_BASH_RCFILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user