Skip to content

Instantly share code, notes, and snippets.

@rich1e
Last active October 25, 2024 07:40
Show Gist options
  • Select an option

  • Save rich1e/0c4b9f6b8ffbc0a1aea54176f5736455 to your computer and use it in GitHub Desktop.

Select an option

Save rich1e/0c4b9f6b8ffbc0a1aea54176f5736455 to your computer and use it in GitHub Desktop.
zsh config
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled # disable automatic updates
# zstyle ':omz:update' mode auto # update automatically without asking
# zstyle ':omz:update' mode reminder # just remind me to update when it's time
# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
autojump
vi-mode
ruby
rbenv
node
git
git-open
brew
extract
iterm2
macos
copypath
copyfile
zsh-better-npm-completion
yarn
sudo
fd
ag
fzf
fzf-tab
forgit
docker
web-search
zsh-syntax-highlighting
zsh-completions
zsh-autosuggestions
)
source $ZSH/oh-my-zsh.sh
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
# Zsh Extend
source '/Users/gongyuqi/zsh-extend.sh'
#!/bin/zsh
###
# @Author : yuqigong@outlook.com
# @Date : 2022-11-16 17:03:09
# @LastEditors : yuqigong@outlook.com
# @LastEditTime : 2023-05-11 20:01:21
###
# @see https://github.com/mathiasbynens/dotfiles/blob/main/.aliases
DEFAULT_USER='rich1e'
ZSH_DISABLE_COMPFIX=true
HOMEBREW_NO_AUTO_UPDATE="1"
# LANG=zh_CN.UTF-8
export LANG='en_US.UTF-8';
export LC_ALL='en_US.UTF-8';
### ---- history config -------------------------------------
export HISTFILE=$ZSH/.zsh_history
# How many commands zsh will load to memory.
export HISTSIZE=10000
# How many commands history will save on file.
export SAVEHIST=10000
# History won't save duplicates.
setopt HIST_IGNORE_ALL_DUPS
# History won't show duplicates on search.
setopt HIST_FIND_NO_DUPS
plugins+=(zsh-better-npm-completion)
# GITHUB_TOKEN
export GITHUB_TOKEN=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
# dotnet
export DOTNET_ROOT="/opt/homebrew/opt/dotnet/libexec"
# 添加 .NET Core SDK 工具
# export PATH="$PATH:/Users/gongyuqi/.dotnet/tools"
# NVM
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
# pnpm
export PNPM_HOME="/Users/gongyuqi/Library/pnpm"
export PATH="$PNPM_HOME:$PATH"
# curl
export PATH="/opt/homebrew/opt/curl/bin:$PATH"
# For compilers to find curl you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/curl/lib"
export CPPFLAGS="-I/opt/homebrew/opt/curl/include"
# brew-completions
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH
autoload -Uz compinit
compinit
fi
###-begin-npm-completion-###
#
# npm command completion script
#
# Installation: npm completion >> ~/.bashrc (or ~/.zshrc)
# Or, maybe: npm completion > /usr/local/etc/bash_completion.d/npm
#
if type complete &>/dev/null; then
_npm_completion () {
local words cword
if type _get_comp_words_by_ref &>/dev/null; then
_get_comp_words_by_ref -n = -n @ -n : -w words -i cword
else
cword="$COMP_CWORD"
words=("${COMP_WORDS[@]}")
fi
local si="$IFS"
if ! IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \
COMP_LINE="$COMP_LINE" \
COMP_POINT="$COMP_POINT" \
npm completion -- "${words[@]}" \
2>/dev/null)); then
local ret=$?
IFS="$si"
return $ret
fi
IFS="$si"
if type __ltrim_colon_completions &>/dev/null; then
__ltrim_colon_completions "${words[cword]}"
fi
}
complete -o default -F _npm_completion npm
elif type compdef &>/dev/null; then
_npm_completion() {
local si=$IFS
compadd -- $(COMP_CWORD=$((CURRENT-1)) \
COMP_LINE=$BUFFER \
COMP_POINT=0 \
npm completion -- "${words[@]}" \
2>/dev/null)
IFS=$si
}
compdef _npm_completion npm
elif type compctl &>/dev/null; then
_npm_completion () {
local cword line point words si
read -Ac words
read -cn cword
let cword-=1
read -l line
read -ln point
si="$IFS"
if ! IFS=$'\n' reply=($(COMP_CWORD="$cword" \
COMP_LINE="$line" \
COMP_POINT="$point" \
npm completion -- "${words[@]}" \
2>/dev/null)); then
local ret=$?
IFS="$si"
return $ret
fi
IFS="$si"
}
compctl -K _npm_completion npm
fi
###-end-npm-completion-###
# Proxy
function setProxy() {
export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890 no_proxy="localhost,127.0.0.1,localaddress,localdomain.com"
echo -e "Proxy is open"
}
function unProxy() {
unset https_proxy
unset http_proxy
unset all_proxy
echo -e "Proxy is close"
}
# Pnpm tabtab source for packages
# uninstall by removing these lines
[[ -f ~/.config/tabtab/zsh/__tabtab.zsh ]] && . ~/.config/tabtab/zsh/__tabtab.zsh || true
# autojump
[ -f /opt/homebrew/etc/profile.d/autojump.sh ] && . /opt/homebrew/etc/profile.d/autojump.sh
# fzf
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# forgit
[ -f ${ZSH_CUSTOM}/plugins/forgit/forgit.plugin.zsh ] && source ${ZSH_CUSTOM}/plugins/forgit/forgit.plugin.zsh
# zsh-completions
fpath=(${ZSH_CUSTOM}/plugins/zsh-completions/src $fpath)
# pyenv
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# zsh-autosuggestions
bindkey '∆' autosuggest-toggle
# web_search
ZSH_WEB_SEARCH_ENGINES=(
bi "https://search.bilibili.com/all?keyword="
douban "https://search.douban.com/book/subject_search?search_text="
reddit "https://www.reddit.com/search/?q="
)
# thefuck
eval $(thefuck --alias)
# navi
# @see https://github.com/denisidoro/navi/blob/master/docs/installation.md#installing-the-shell-widget
eval "$(navi widget zsh)"
# Easier navigation
alias ..='cd ..'
alias ~="cd ~" # `cd` is probably faster to type though
alias -- -="cd -"
# Shortcuts
alias glog='git log --oneline --decorate --graph'
# alias tldr="export LANG=zh && tldr"
alias lg='lazygit'
alias pn='pnpm'
alias cpp='copypath'
alias cpf='copyfile'
alias ws='web_search'
alias rm='trash'
alias cls='clear'
alias clear='clear && printf "\e[3J"'
alias editzshrc='code -a ${HOME}/zsh-extend.sh'
alias zshconfig='code -a ${HOME}/.zshrc'
alias cleannode='find . -name "node_modules" -type d -exec rm -rf '{}' +'
# Get week number
alias week='date +%V'
# Trim new lines and copy to clipboard
alias c="tr -d '\n' | pbcopy"
# Intuitive map function
# For example, to list all directories that contain a certain file:
# find . -name .gitattributes | map dirname
alias map="xargs -n1"
# Asciinema Settings
alias rec='asciinema rec'
alias recp='asciinema play'
alias recc='asciinema cat'
alias recup='asciinema upload'
alias reca='asciinema auth'
alias rech='asciinema -h'
# List files
alias ls='exa'
alias ll='exa -lh'
alias la='exa -lha'
alias lr='exa -lR'
# IP addresses
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
alias localip="ipconfig getifaddr en0"
alias ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"
# Show active network interfaces
alias ifactive="ifconfig | pcregrep -M -o '^[^\t:]+:([^\n]|\n\t)*status: active'"
# Flush Directory Service cache
alias flush="dscacheutil -flushcache && killall -HUP mDNSResponder"
# Get macOS Software Updates, and update installed Homebrew, npm, and their installed packages
alias update='sudo softwareupdate -i -a; brew update; brew upgrade; brew cleanup; npm install npm -g; npm update -g;omz update;'
# 更新 SHELL
alias renew="source ${HOME}/.zshrc"
# 重新启动 SHELL, 与 source 不同的是不会对 PATH 进行重新写入
alias reload="exec ${SHELL} -l"
# 删除重复的路径
alias cleanpath='typeset -aU path'
# 单独的一行上打印每个PATH条目
alias path='echo -e ${PATH//:/\\n}'
# disable sort when completing `git checkout`
zstyle ':completion:*:git-checkout:*' sort false
# set descriptions format to enable group support
zstyle ':completion:*:descriptions' format '[%d]'
# set list-colors to enable filename colorizing
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# preview directory's content with exa when completing cd
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'exa -1 --color=always $realpath'
# switch group using `,` and `.`
zstyle ':fzf-tab:*' switch-group ',' '.'
# Starship
eval "$(starship init zsh)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment