将 macOS 升级到 Catalina 并将默认 Shell 从 Bash 迁移到 Zsh 的指南
指数
- 从 Bash 到 Zsh
- 配置 Zsh
- 最小配置
- 启用 Git 补全
- 定义别名
- 使用 Starship 美化控制台
从 Bash 到 Zsh
将 macOS 升级到 Catalina(哈哈)后,以下命令将默认 shell 更改为 zsh:
$ chsh -s /bin/zsh
就是这样!
配置 Zsh
最小配置
要配置 zsh,只需~/.zshrc
像这样填充:
# enable the default zsh completions!
autoload -Uz compinit && compinit
启用 Git 补全
要启用 git 完成,请尝试以下命令:
# make the `.zsh` directory
$ mkdir -p ~/.zsh
$ cd ~/.zsh
# download the scripts for completion
$ curl -o git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
$ curl -o _git https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.zsh
之后,我们可以在中加载脚本~/.zshrc
:
zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash
fpath=(~/.zsh $fpath)
最后,删除缓存:
$ rm ~/.zcompdump
定义别名
我最喜欢和最少的别名是:
alias ..='cd ..'
alias ...='cd ../..'
alias ls='ls -GwF'
alias ll='ls -alh'
ll
使用 zsh 时未定义Yes 。
如果我们使用VSCode,我们可以~/.zshrc
通过运行以下命令进行编辑zshrc
:
alias zshrc='code ~/.zshrc'
以同样的方式,要~/.gitconfig
通过命令进行编辑gitconfig
,请在中添加以下行~/.zshrc
:
alias gitconfig='code ~/.gitconfig'
使用 Starship 美化控制台
你知道星舰吗?
TLDR,看看我漂亮的控制台:)
我太喜欢这个游戏机了!哈哈
安装
$ brew install starship
并将初始化脚本添加到~/.zshrc
:
eval "$(starship init zsh)"
配置
欲了解完整信息,请参阅文档。
作为一名 TypeScript 开发人员、一名爱猫人士和一名篮球爱好者,我的最低配置是:
# in `~/.config/starship.toml`
[character]
symbol = "🐈💕"
[directory]
fish_style_pwd_dir_length = 10
[git_branch]
symbol = "🏀 "
[nodejs]
symbol = "⚡ "
[package]
symbol = "🎉 "
象征 | 为什么或什么 |
---|---|
🐈💕 | 太可爱了——日语中的“nyaaan”/英语中的“meow” |
🏀 大师 | git 分支 |
⚡ v12.11.1 | nodejs 版本 |
🎉 v6.6.0 | 软件包版本 |
结论
没有控制台,没有开发人员:)
文章来源:https://dev.to/saltyshiomix/a-guide-for-upgrading-macos-to-catalina-and-migration-the-default-shell-from-bash-to-zsh-4ep3