Skip to content

Instantly share code, notes, and snippets.

@xiaowei65321
Created November 15, 2022 13:28
Show Gist options
  • Save xiaowei65321/28fbc9f484d21f31c80fe94958c71110 to your computer and use it in GitHub Desktop.
Save xiaowei65321/28fbc9f484d21f31c80fe94958c71110 to your computer and use it in GitHub Desktop.
zsh #zsh #linux #shell

install fzf

sudo apt install fzf

sudo apt install zsh
zsh --version

# 设置zsh作为默认shell, 替代`/bin/bash`
echo $SHELL && chsh -s $(which zsh) && echo $SHELL
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

plugins

# [syntax-highlighting](https://github.com/zsh-users/zsh-syntax-highlighting)
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# 输入至少一个字符之后触发auto complete
echo 'zstyle ':autocomplete:*' min-input 1 ' >> .zshrc
# check full config from https://github.com/marlonrichert/zsh-autocomplete/blob/main/.zshrc

# [auto-complete](https://github.com/marlonrichert/zsh-autocomplete#installing--updating)
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autocomplete
echo 'skip_global_compinit=1' >> ~/.zshenv

# [auto-suggestion](https://github.com/zsh-users/zsh-autosuggestions)
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

# [abbr](https://github.com/olets/zsh-abbr)
# ~/.config/zsh/abbreviations
git clone https://github.com/olets/zsh-abbr.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-abbr

~/.zshrc 中开启 plugin, 保持zsh-syntax-highlighting在列表末尾.

plugins=(zsh-autosuggestions zsh-autocomplete zsh-abbr zsh-syntax-highlighting)

https://github.com/zsh-users/zsh-autosuggestions#suggestion-strategy open file ~/.zsh/zsh-autosuggestions/src/config.zsh

# Strategies to use to fetch a suggestion
# Will try each strategy in order until a suggestion is returned
(( ! ${+ZSH_AUTOSUGGEST_STRATEGY} )) && {
	typeset -ga ZSH_AUTOSUGGEST_STRATEGY
	ZSH_AUTOSUGGEST_STRATEGY=(history completion)
}

zsh 3.1 之后的版本自带 zpty 模块

配置 zsh 使用 starship, 将以下内容添加到~/.zshrc

eval "$(starship init zsh)"

~/.zshrc 示例

# 开启plugins
plugins=(
    zsh-autosuggestions
    zsh-autocomplete
    zsh-abbr
    zsh-syntax-highlighting
)

# Generated for envman. Do not edit.
[ -s "$HOME/.config/envman/load.sh" ] && source "$HOME/.config/envman/load.sh"

# nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# golang
export PATH="/usr/local/go/bin:$PATH"

# Put windows ip address to env
export WslHostIp=$(ipconfig.exe | grep 'vEthernet (WSL)' -A4 | cut -d":" -f 2 | tail -n1 | sed -e 's/\s*//g')

eval "$(starship init zsh)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment