ohmyzsh使用指南

本文介绍一下ohmyzsh的学习和使用过程:

参考资料6和7为主要配置流程:

参考资料:

  1. [GitHub - ohmyzsh/ohmyzsh: 🙃 A delightful community-driven (with 2,100+ contributors) framework for managing your zsh configuration)
  2. Installing ZSH · ohmyzsh/ohmyzsh Wiki · GitHub
  3. windows subsystem for linux - [process exited with code 1], can’t open WSL, zsh - Stack Overflow
  4. 优雅简洁的zim美化你的zsh终端,媲美甚至超越 ohmyzsh - 勒勒乐了 - 博客园
  5. 优雅简洁的zim美化你的zsh终端,媲美甚至超越 ohmyzsh_哔哩哔哩_bilibili
  6. 终端神器ohmyzsh_哔哩哔哩_bilibili
  7. Linux/Mac OS下安装并配置oh my zsh | SunPages重点参考
  8. GitHub - unixorn/awesome-zsh-plugins: A collection of ZSH frameworks, plugins, themes and tutorials.
  9. oh-my-zsh让终端好用到飞起~ - 掘金

将.bashrc中的alias迁移到.zshrc

参考资料:

  1. macos - Easiest way to migrate aliases from bash to zsh - Ask Different

zsh在/mnt/…目录中的git仓库中prompt很慢

参考资料:

  1. Slow prompt command (oh-my-zsh) · Issue #1 · hsab/WSL-config · GitHub

代理配置

配置完成后:

  • proxy set:开启代理
  • proxy unset:关闭代理
  • proxy test:查看代理状态

参考资料:

  1. WSL2配置代理 - Leaos - 博客园

为指定用户安装zsh (不需要root权限)

下述安装过程主要参考资料5和资料6:

  1. 从源码安装zsh的依赖包ncurses
wget ftp://ftp.gnu.org/gnu/ncurses/ncurses-6.1.tar.gz tar xf ncurses-6.1.tar.gz 
cd ncurses-6.1 ./configure --prefix=$HOME/local CXXFLAGS="-fPIC" CFLAGS="-fPIC" 
make -j && make install
  1. 构建并安装zsh(将下述命令写入脚本zsh.sh并运行sh zsh.sh
ZSH_SRC_NAME=$HOME/packages/zsh.tar.xz
ZSH_PACK_DIR=$HOME/packages/zsh
ZSH_LINK="https://sourceforge.net/projects/zsh/files/latest/download"

if [[ ! -d "$ZSH_PACK_DIR" ]]; then
    echo "Creating zsh directory under packages directory"
    mkdir -p "$ZSH_PACK_DIR"
fi

if [[ ! -f $ZSH_SRC_NAME ]]; then
    curl -Lo "$ZSH_SRC_NAME" "$ZSH_LINK"
fi

tar xJvf "$ZSH_SRC_NAME" -C "$ZSH_PACK_DIR" --strip-components 1
cd "$ZSH_PACK_DIR"

./configure --prefix="$HOME/local" \
    CPPFLAGS="-I$HOME/local/include" \
    LDFLAGS="-L$HOME/local/lib"
make -j && make install
  1. 设置默认shell为zsh。创建~/.bash_profile文件并写入:
export PATH=$HOME/local/bin:$PATH 
export SHELL=`which zsh` 
[ -f "$SHELL" ] && exec "$SHELL" -l
  1. 运行source ~/.bash_profile启动zsh。选择q选项暂不进行配置,此时位于zsh shell。
  2. 直接采用资料6中的配置(可以将ohmyzsh.sh下载到本地运行sh ohmyzsh.sh
sh -c "$(curl -fsSL https://www.sunhanwu.top/upload/2022/12/ohmyzsh.sh)"
  1. 安装第三方插件:
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  1. .zshrc中配置所需要的插件(功能介绍见资料6):
bash plugins=( git extract fzf z zsh-autosuggestions zsh-syntax-highlighting wd sudo )
  1. 将原本.bashrc中的aliasexport配置写入~/.bash_aliases~/.bash_path文件。然后在.zshrc文件中写入生效:
if [ -f ~/.bash_aliases ]; then
   . ~/.bash_aliases
fi

if [ -f ~/.bash_path ]; then
   . ~/.bash_path
fi

运行source ~/.zshrc即可生效。

参考资料:

  1. zsh/INSTALL at master · zsh-users/zsh · GitHub
  2. software installation - Installing zsh from source file without root user access - Unix & Linux Stack Exchange
  3. Z-Shell Frequently-Asked Questions
  4. linux - Install zsh without root access? - Stack Overflow
  5. Building Zsh from Source and Configuring It on CentOS - jdhao’s digital space
  6. Linux/Mac OS下安装并配置oh my zsh | SunPages

git bash中安装zsh和ohmyzsh

参考资料:

  1. Zsh / Oh-my-zsh on Windows Git Bash · GitHub
  2. git - Strange characters for ohmyz in vscode - Stack Overflow
  3. Weird letter spacing in Integrated Terminal for VS Code · Issue #120004 · microsoft/vscode · GitHub
  4. weird cursor-word space issue with zsh, oh-my-zsh · Issue #67789 · microsoft/vscode · GitHub

安装autojump插件实现目录跳转

参考资料:

  1. GitHub - wting/autojump: A cd command that learns - easily navigate directories from the command line

安装powerlevel10k主题

  • 重置配置:p10k configure
  • 在git bash和MobaTermX中会出现某些配置直接被跳过的情况,其原因为这些终端不支持256colors,

参考资料:

  1. GitHub - romkatv/powerlevel10k: A Zsh theme
  2. How to reset the settings? · Issue #214 · romkatv/powerlevel10k · GitHub
  3. Configuration wizard missing · Issue #1840 · romkatv/powerlevel10k · GitHub

VSCode Icons图标显示

方案一: 安装MesloLGS NF字体并设置。
方案二:下载参考资料2中的扩展Fira Code字体。

参考资料:

  1. icons don’t display in VS code integrated terminal after setting terminal.integrated.fontFamily · Issue #671 · romkatv/powerlevel10k · GitHub
  2. Missing icons for oh-my-zsh · tonsky/FiraCode · Discussion #1285 · GitHub