phi*_*her 5 bash zsh oh-my-zsh macos-catalina
你们中有些人可能知道,升级到 Mac OS Catalina 后,Apple 提示用户迁移到 zsh 作为默认 shell。
现在,每次打开 bash 时都会出现一条警告。可以将以下行添加到您的 ~/.bash_profile 中(对于感兴趣的人),以禁用它。
export BASH_SILENCE_DEPRECATION_WARNING=1
Run Code Online (Sandbox Code Playgroud)
然而,我认为很多人(包括我)都想转向 zsh。
我当前的 ~/.bash_profile 如下所示:
# searches this directory for executables first
export PATH="/usr/local/bin:$PATH"
# jenv
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
# rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
# pyenv
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
# nodenv
export PATH="$HOME/.nodenv/bin:$PATH"
eval "$(nodenv init -)"
# node-build-definitions
export NODE_BUILD_DEFINITIONS="/usr/local/opt/node-build-update-defs/share/node-build"
# bash auto-completion
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
# git branch in prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
# bash profile theme
export PS1="\[\e[1;37m\]parthnaik:\[\033[33;1m\]\w\[\033[m\]\$(parse_git_branch) \n$ "
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
# firevault memory security
alias sleepsafe='sudo pmset -a destroyfvkeyonstandby 1 hibernatemode 25 standby 0 standbydelay 0'
alias sleepdefault='sudo pmset -a destroyfvkeyonstandby 0 hibernatemode 3 standby 1 standbydelay 10800'
# enable / disable captive portal
alias disablecaptiveportal='sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.captive.control Active -bool false'
alias enablecaptiveportal='sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.captive.control Active -bool true'
Run Code Online (Sandbox Code Playgroud)
我希望比我更有知识的人可以帮助我了解什么发生在哪里,因为网上似乎存在一些相互矛盾的信息。
到目前为止,根据我所读到的内容,以下是我看到的不同建议:
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile;
fi
Run Code Online (Sandbox Code Playgroud)
除此之外,我还有一个 .sh 脚本,每天通过以下命令自动运行:
sh script_name.sh
Run Code Online (Sandbox Code Playgroud)
我应该将其更改为使用 zsh 吗?如下所示?如果所有 .sh 脚本都带有 bash 和 zsh,则应该是这种情况。
zsh script_name.sh
Run Code Online (Sandbox Code Playgroud)
尽管我知道上述任何一种都可以在功能方面发挥作用,但仍在寻找迁移的建议和最佳实践。理想情况下,希望我的主题、自动完成和 git 分支设置(如上面的 ~/.bash_profile 所示)以与现在相同的方式工作。
对于主题,我知道还有一个名为“oh-my-zsh”的插件可用。是否建议安装这个?
感谢您的帮助!
我决定使用 zsh 的纯主题。我的脚本正常工作,它们现在只是通过 zsh 运行。这是我的 ~/.zshrc 文件的样子:
# PATHS AND ALIASES
# searches this directory for executables first
export PATH="/usr/local/bin:$PATH"
# jenv
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
# rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
# pyenv
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
# nodenv
export PATH="$HOME/.nodenv/bin:$PATH"
eval "$(nodenv init -)"
# node-build-definitions
export NODE_BUILD_DEFINITIONS="/usr/local/opt/node-build-update-defs/share/node-build"
# firevault memory security
alias sleepsafe='sudo pmset -a destroyfvkeyonstandby 1 hibernatemode 25 standby 0 standbydelay 0'
alias sleepdefault='sudo pmset -a destroyfvkeyonstandby 0 hibernatemode 3 standby 1 standbydelay 10800'
# enable / disable captive portal
alias disablecaptiveportal='sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.captive.control Active -bool false'
alias enablecaptiveportal='sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.captive.control Active -bool true'
# CLI SETTINGS
# enable the default zsh completions
autoload -Uz compinit && compinit
# set colors for displaying directories and files when the ls command is used
export LSCOLORS='GxFxCxDxBxegedabagaced'
export CLICOLOR=1
# theme
fpath+=("$HOME/.zsh/pure")
autoload -U promptinit && promptinit
prompt pure
# change the path color
zstyle :prompt:pure:path color white
Run Code Online (Sandbox Code Playgroud)