zsh##
是一款强大的shell!
- 安装:用包管理器安装就行啦
- for Windows:WSL
oh_my_zsh
是zsh的一款插件管理器,有好多很好用的插件和好康的主题
- 安装:
sh -c “$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)”
powerlevel10k
是一款主题,但是超好看!
- 安装:
git clone –depth=1 https://gitee.com/romkatv/powerlevel10k.git $/themes/powerlevel10k
- 再开心地配置自己的终端吧!
- 先装一下相关的字体,这里用的是 Consolas Nerd Font(Github上有哦
- 然后安装p10k的本体
配置 p10k
第一次安装好之后应该会弹出配置向导,只要按它说的选就可以生成基础的配置文件啦(如果没有弹出的话输入 p10k configure
配置完之后大概长这样子:(上面的一言是自己弄的脚本x
但是!我们怎么能满足于默认配置呢?所以当然要魔改啦ww
魔改 .p10k.zsh
首先用编辑器打开 ~/.p10k.zsh,进去之后会发现,配置文件大体分成两部分:prompt开关以及prompt设置(配置文件里的注释其实把配置解释得很详细,如果有不懂可以仔细康康!
prompt的开关
不要被几千行的配置吓到,其实很简单哦!(还是只有我被吓到qaq只要保留自己喜欢的prmopt,然后注释掉不喜欢的prompt,就可以啦~ 比如,我们看到这里:
1 | typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=( # =========================[ Line #1 ]========================= os_icon # os identifier dir # current directory vcs # git status # =========================[ Line #2 ]========================= newline # \n # prompt_char # prompt symbol) |
如果我不想显示os标志,只要注掉os_icon就可以了:#os_icon然后保存之后,在终端输入 source ~/.p10k.zsh 就可以看见效果啦
下面是配置的翻译:(窝用的是双行的,所以选择了单行的人应该和我有点不一样
1 | typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=( #这是左边要显示的prompt # =========================[ Line #1 ]========================= os_icon # 系统标识,苹果下是一个🍎 vcs # 如果在git文件夹里,显示git信息 # =========================[ Line #2 ]========================= newline # 双行用到的新一行 dir # 显示当前目录 # prompt_char # 一个绿色小三角)typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=( #这是右边要显示的prompt # =========================[ Line #1 ]========================= status # 上一个命令的exit code command_execution_time # 命令执行时间 background_jobs # 后台有任务时,显示一个小齿轮 direnv # direnv状态 (https://direnv.net/) asdf # asdf版本控制 (https://github.com/asdf-vm/asdf) virtualenv # python虚拟环境 (https://docs.python.org/3/library/venv.html) anaconda # 显示conda的版本信息 (https://conda.io/) pyenv # 用pyenv时显示python版本 (https://github.com/pyenv/pyenv) goenv # goenv 的 go 版本 (https://github.com/syndbg/goenv) nodenv # nodenv 的 node 版本 (https://github.com/nodenv/nodenv) nvm # nvm 的 node 版本 (https://github.com/nvm-sh/nvm) nodeenv # nodeenv 的 node 版本 (https://github.com/ekalinin/nodeenv) # node_version # node.js 版本,在project里才显示 # go_version # go 版本(https://golang.org) # rust_version # rustc 版本(https://www.rust-lang.org) # dotnet_version # .NET 版本(https://dotnet.microsoft.com) # php_version # php 版本 (https://www.php.net/) # laravel_version # laravel php framework 版本 (https://laravel.com/) # java_version # java 版本 (https://www.java.com/) package # 显示 package.json 里的“项目名@版本号” (https://docs.npmjs.com/files/package.json) rbenv # rbenv 里的 ruby 版本 (https://github.com/rbenv/rbenv) rvm # 同上,rvm (https://rvm.io) fvm # flutter 版本控制 (https://github.com/leoafarias/fvm) luaenv # luaenv 的 lu a版本 (https://github.com/cehoffman/luaenv) jenv # jenv 的 Java 版本 (https://github.com/jenv/jenv) plenv # plenv 的 perl 版本 (https://github.com/tokuhirom/plenv) phpenv # phpenv 的 php 版本 (https://github.com/phpenv/phpenv) scalaenv # scalaenv 的 scala 版本 (https://github.com/scalaenv/scalaenv) haskell_stack # stack 的 haskell 版本 (https://haskellstack.org/) kubecontext # 当前的 kubernetes 上下文(?) (https://kubernetes.io/) terraform # terraform 工作环境 (https://www.terraform.io) # terraform_version # terraform 版本 (https://www.terraform.io) aws # aws 配置文件 (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) aws_eb_env # aws elastic beanstalk 环境 (https://aws.amazon.com/elasticbeanstalk/) azure # azure 账户名 (https://docs.microsoft.com/en-us/cli/azure) gcloud # google cloud cli 账号和项目 (https://cloud.google.com/) google_app_cred # google 应用证书 (https://cloud.google.com/docs/authentication/production) toolbox # toolbox 名 (https://github.com/containers/toolbox) # context # 用户@主机名 nordvpn # nordvpn 连接状态, linux only (https://nordvpn.com/) ranger # ranger shell (https://github.com/ranger/ranger) nnn # nnn shell (https://github.com/jarun/nnn) xplr # xplr shell (https://github.com/sayanarijit/xplr) vim_shell # vim shell 指示器 (:sh) midnight_commander # midnight commander shell (https://midnight-commander.org/) nix_shell # nix shell (https://nixos.org/nixos/nix-pills/developing-with-nix-shell.html) vi_mode # vi 模式 (如果开了 prompt_char 就不用开这个了) # vpn_ip # vpn指示器(开了vpn会显示一把小绿锁 # load # CPU 负载 # disk_usage # 硬盘负载 # ram # 可用内存 # swap # 已用交换内存 todo # todo 项目 (https://github.com/todotxt/todo.txt-cli) timewarrior # timewarrior 跟踪状态 (https://timewarrior.net/) taskwarrior # taskwarrior 任务计数 (https://taskwarrior.org/) time # current time # =========================[ Line #2 ]========================= newline # ip # 某个网卡的ip和网络上传/下载速度 # public_ip # 公网ip地址 wifi # wifi速度 battery # 电池电量 # proxy # 如果设置了http_proxy,就显示一个双箭头 example # 用户自定义的prompt) |
TIPS:可以把本来显示在后面的东西挪到前面显示!
prompt设置
但是,如果不喜欢某个prompt默认显示出来的效果要怎么办呢?那当然是选择魔改啦!
拿wifi举例:
1 | #####################################[ wifi: wifi speed ]###################################### WiFi color.typeset -g POWERLEVEL9K_WIFI_FOREGROUND=0typeset -g POWERLEVEL9K_WIFI_BACKGROUND=4# Custom icon.# typeset -g POWERLEVEL9K_WIFI_VISUAL_IDENTIFIER_EXPANSION='⭐'# Use different colors and icons depending on signal strength ($P9K_WIFI_BARS).## # Wifi colors and icons for different signal strength levels (low to high).# typeset -g my_wifi_fg=(0 0 0 0 0) # <-- change these values# typeset -g my_wifi_icon=('WiFi' 'WiFi' 'WiFi' 'WiFi' 'WiFi') # <-- change these values## typeset -g POWERLEVEL9K_WIFI_CONTENT_EXPANSION='%F}$P9K_WIFI_LAST_TX_RATE Mbps'# typeset -g POWERLEVEL9K_WIFI_VISUAL_IDENTIFIER_EXPANSION='%F}$'## The following parameters are accessible within the expansions:## Parameter | Meaning# ----------------------+---------------# P9K_WIFI_SSID | service set identifier, a.k.a. network name# P9K_WIFI_LINK_AUTH | authentication protocol such as "wpa2-psk" or "none"; empty if unknown# P9K_WIFI_LAST_TX_RATE | wireless transmit rate in megabits per second# P9K_WIFI_RSSI | signal strength in dBm, from -120 to 0# P9K_WIFI_NOISE | noise in dBm, from -120 to 0# P9K_WIFI_BARS | signal strength in bars, from 0 to 4 (derived from P9K_WIFI_RSSI and P9K_WIFI_NOISE) |
首先要看注释,一般都很清楚注明了可以怎么修改这里我们把原来的效果改成显示SSID,按着注释的提示,我们添加这一行:
1 | typeset -g POWERLEVEL9K_WIFI_CONTENT_EXPANSION='$P9K_WIFI_SSID' |
登登!
关于自定义prompt
往下翻可以找到 prompt_example 函数,相信聪明的小读者一定能明白怎么改了吧?(逃这里是我自己的例子:
1 | function prompt_example() |