shell美化
# 前言
最近使用终端的频率越来越高了,已经变成常用的工具了就想着磨合磨合使其变得更加顺手一些,免得用的糟心。
# 我心中的终端
- 漂亮的界面
- 高效的自动补全
- 实用的额外信息
- 自动推荐
- 语法高亮
- 随时唤起
- 远程时可以直接进行
sftp
,在线编辑 ...
本文推荐使用
iTerm2
,只是因为矮个子里面挑将军这玩意还能凑活着用吧
# 改造开始
# 安装 Oh My Zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
1
# 主题
以 Powerlevel10k
为例
# 安装
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k
1
# 配置
- 在
zsh
的配置文件~/.zshrc
中设置ZSH_THEME="powerlevel10k/powerlevel10k"
。配置完成后重启shell
客户端即可看到效果 - 重启后会提示进行配置,按照提示进行配置即可
如果遭遇网络问题不要慌,把终端的网络配置一下,然后再执行下面两个命令即可
- 执行
echo 'POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD=true' >>! ~/.zshrc
- 执行
p10k configure
重新配置 - 执行完毕后按提示重启终端
- 重启终端后再次执行
pk10k configure
进行显示上面的配置 - 会先问一堆图案像不像的问题,如果不像的话就说明字体没有安装成功,重新安装即可
- 图案显示问题问完后就是终端命令的显示问题了,按照自己的喜好进行配置即可
# 配置其它 App
iTerm2
:Preferences
->Profiles
->Text
->Font
->Change Font
->MesloLGS NF
vs code
:Preferences
->Settings
->Terminal › Integrated: Font Family
->MesloLGS NF
JetBrains
系列:Preferences
->Editor
->Color Scheme
->Console Font
->MesloLGS NF
# 插件
如果想看
Oh-my-zsh
自带那些插件,也可以Web
上查看:https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins (opens new window)
配置插件的时候基本上是在
~/.zshrc
文件中找到plugins=(git)
这一行,然后在git
后面加上需要的插件即可
autojump
:自动跳转到指定目录,使用j
命令brew install autojump
1zsh-autosuggestions
:自动补全,使用Tab
键git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
1zsh-syntax-highlighting
:语法高亮git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
1
# 错误经验
# Insecure completion-dependent directories detected
[oh-my-zsh] Insecure completion-dependent directories detected:
drwxrwxrwx 7 symbol admin 224 10 17 2022 /opt/homebrew/share/zsh
drwxrwxrwx 6 symbol admin 192 1 31 14:53 /opt/homebrew/share/zsh/site-functions
[oh-my-zsh] For safety, we will not load completions from these directories until
[oh-my-zsh] you fix their permissions and ownership and restart zsh.
[oh-my-zsh] See the above list for directories with group or other writability.
[oh-my-zsh] To fix your permissions you can do so by disabling
[oh-my-zsh] the write permission of "group" and "others" and making sure that the
[oh-my-zsh] owner of these directories is either root or your current user.
[oh-my-zsh] The following command may help:
[oh-my-zsh] compaudit | xargs chmod g-w,o-w
[oh-my-zsh] If the above didn't help or you want to skip the verification of
[oh-my-zsh] insecure directories you can set the variable ZSH_DISABLE_COMPFIX to
[oh-my-zsh] "true" before oh-my-zsh is sourced in your zshrc file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
这个错误是因为 zsh
的安全机制导致的,解决办法如下:
# 禁用组用户和其他用户的写入权限
sudo chmod -R g-w,o-w /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions
# 将所有者设置为当前用户
sudo chown -R $(whoami) /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions
1
2
3
4
2
3
4
更新时间: 2024/7/31 14:14:52