我将 bash 和 zsh 与一个 .bashrc、.bash_aliases 和 .zshrc 文件一起使用。
将其放入 .zshrc 以加载 bash 文件:
# shortcut to refresh .zshrc
alias refz="source ~/.zshrc"
# Load bash files to zsh
test -f $HOME/.bashrc && . $HOME/.bashrc
test -f $HOME/.bash_aliases && . $HOME/.bash_aliases
如果您有许多 bash 别名和函数,您可能会收到一些错误消息,例如:
/proc/self/fd/13:12310: bad option: -t
由 .bash_aliases 或 .bashrc 文件中的 bash 特定行引起
您可以使用以下方法跳过那些有问题的:
if [ -n "$BASH" ] ;then
lines to ignore by zsh
fi
例如 kubectl 自动补全
# To fix error massage .bashrc:16: command not found: shopt
# Check if bash is the current shell, if not, skip it
if [ -n "$BASH" ] ;then
# kubectl and bash completions
if [ -x "$(command -v kubectl)" ]; then
source <(kubectl completion bash)
complete -F __start_kubectl k
fi
if ! shopt -oq posix; then
if [ -f /etc/profile.d/bash_completion.sh ]; then
. /etc/profile.d/bash_completion.sh
fi
fi
fi
# Instead I need to put this line somewhere in my zshrc
# to have kubectl autocompletion replacing the skipped bash one:
plugins=(git git-flow brew history node npm kubectl)
# To fix error message .bash_aliases:4: parse error: condition expected: =
# Change these to this syntax to be used by zhs
# Not compatible with zsh:
if [ $HOSTNAME = "x1" ]; then
# Compatible with bash and zsh:
if [[ $HOSTNAME == "x1" ]]; then