38 lines
1.0 KiB
Bash
38 lines
1.0 KiB
Bash
# shell.sh — detect current interactive shell and its rc file
|
|
# Depends-On: colors.sh os.sh
|
|
# Requires-Vars: (none)
|
|
# Sets-Vars: $CURRENT_SHELL $SHELL_RC
|
|
# Include via: @include lib/shell.sh
|
|
|
|
# Sets CURRENT_SHELL (zsh | bash | fish) and SHELL_RC (path to rc file)
|
|
detect_shell() {
|
|
local shell_name
|
|
shell_name=$(basename "$SHELL")
|
|
|
|
case "$shell_name" in
|
|
zsh)
|
|
CURRENT_SHELL="zsh"
|
|
SHELL_RC="$HOME/.zshrc"
|
|
;;
|
|
fish)
|
|
CURRENT_SHELL="fish"
|
|
SHELL_RC="$HOME/.config/fish/config.fish"
|
|
;;
|
|
bash)
|
|
CURRENT_SHELL="bash"
|
|
# macOS uses ~/.bash_profile; Linux uses ~/.bashrc
|
|
if is_macos; then
|
|
SHELL_RC="$HOME/.bash_profile"
|
|
else
|
|
SHELL_RC="$HOME/.bashrc"
|
|
fi
|
|
;;
|
|
*)
|
|
CURRENT_SHELL="bash"
|
|
SHELL_RC="$HOME/.bashrc"
|
|
;;
|
|
esac
|
|
|
|
print_info "Detected shell: $CURRENT_SHELL (rc file: $SHELL_RC)"
|
|
}
|