Last active
June 27, 2023 09:49
-
-
Save AmatsuZero/9399a994fe5684bc79c2f972bac02407 to your computer and use it in GitHub Desktop.
My Zsh Config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
a = add | |
amend = commit --amend | |
c = commit | |
ca = commit --amend | |
ci = commit -a | |
co = checkout | |
d = diff | |
dc = diff --changed | |
ds = diff --staged | |
f = fetch | |
loll = log --graph --decorate --pretty=oneline --abbrev-commit | |
m = merge | |
one = log --pretty=oneline | |
outstanding = rebase -i @{u} | |
s = status | |
unpushed = log @{u} | |
wc = whatchanged | |
wip = rebase -i @{u} | |
zap = fetch -p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Github | |
export GITHUB_USER=*** | |
export GITHUB_PASSWORD=*** | |
# Bandwagon server | |
export BANDWAGONIP=*** | |
export BANDWAGONPORT=*** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Xcode | |
export DEVELOPER_DIR="/Applications/Xcode.app/Contents/Developer" | |
export DERIVEDDATAPATH="$HOME/Library/Developer/Xcode/DerivedData" # APP 产生的缓存文件 | |
export ARCHIVESPATH="$HOME/Library/Developer/Xcode/Archives" # ipa历史版本 | |
export DEVICESCACHEPATH="$HOME/Library/Developer/CoreSimulator/Devices/" # 移除模拟器的缓存数据 | |
export PLAYGROUNDCACHE="$HOME/Library/Developer/XCPGDevices/" # Playground缓存 | |
export DEVICESSUPPORTPATH="$HOME/Library/Developer/Xcode/iOS DeviceSupport" # 旧设备的支持 | |
# about flutter | |
export FLUTTER_HOME=$HOME/flutter | |
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn | |
export PUB_HOSTED_URL=https://pub.flutter-io.cn | |
# Zsh highlight | |
export ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR=/usr/local/share/zsh-syntax-highlighting/highlighters | |
# About Golang | |
export GOPATH=$HOME/golang | |
export GOBIN=$GOPATH/bin | |
export GOROOT=/usr/local/opt/go/libexec | |
export GO111MODULE="on" | |
export GOPROXY=https://goproxy.io | |
# Electron | |
export ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/" | |
# Gloabl Path | |
export PATH=$FLUTTER_HOME/bin:$GOBIN:$GOROOT/bin:/usr/local/sbin:/usr/bin:/usr/local/bin:$PATH | |
#Zplug | |
export ZPLUG_HOME=/usr/local/opt/zplug | |
export PKG_CONFIG_PATH="/usr/local/opt/libpq/lib/pkgconfig" | |
#Android SDK | |
# export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk | |
# export ANDROID_HOME=$ANDROID_SDK_ROOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export ZSH=~/.oh-my-zsh | |
export TERM="xterm-256color" | |
ZSH_THEME="powerlevel9k/powerlevel9k" | |
POWERLEVEL9K_MODE='nerdfont-complete' | |
plugins=( | |
git | |
osx | |
xcode | |
npm | |
brew | |
# 彩色化查看manual | |
colored-man-pages | |
# github插件, 需要在环境变量设置用户名和密码 | |
github | |
# 自动纠正 | |
thefuck | |
# vscode | |
vscode | |
# react native | |
react-native | |
# 重新加载 | |
zsh_reload | |
# virtualenv | |
virtualenv | |
iterm2 | |
) | |
resolve() { | |
#Step1. 在本地仓库中, 更新并合并代码 | |
git fetch origin | |
# 如果没有指定分支名,则使用当前分支名 | |
local branch=$1 | |
if [ ! $1 ]; then | |
branch=$(git rev-parse --abbrev-ref HEAD) | |
fi | |
git rebase origin/${branch} | |
# Step2. 检查是否有冲突,有冲突则退出 | |
CONFLICTS=$(git ls-files -u | wc -l) | |
if [ "$CONFLICTS" -gt 0 ] ; then | |
echo "There is a conflict. Aborting" | |
exit 1 | |
fi | |
# Step3. 所有冲突都修改完毕后, 提交修改的代码 | |
git add -u | |
git rebase --continue | |
# # #Step4. 更新patch | |
git push origin HEAD:refs/for/${branch} | |
} | |
switch() { | |
# 先拉取,更新远端所有分支 | |
git fetch | |
local branch=$1 | |
# 切换分支并追踪 | |
git checkout -b ${branch} -t origin/${branch} | |
} | |
# 检查端口是否可用 | |
isPortAvailable() { | |
echo "Checking instance port ..." | |
if lsof -i:$1 2>/dev/null >/dev/null | |
then | |
echo "port exists" | |
exit 1 | |
fi | |
} | |
# checks if branch has something pending | |
parse_git_dirty() { | |
git diff --quiet --ignore-submodules HEAD 2>/dev/null; [ $? -eq 1 ] && echo "*" | |
} | |
# gets the current git branch | |
parse_git_branch() { | |
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" | |
} | |
# get last commit hash prepended with @ (i.e. @8a323d0) | |
parse_git_hash() { | |
git rev-parse --short HEAD 2> /dev/null | sed "s/\(.*\)/@\1/" | |
} | |
# 重新生成.xcodeproj文件 | |
# 我认为这是SPM的一个Bug,添加新的依赖以后,需要重现删除原来的.xcodeproj文件并重新生成,添加的依赖才会出现 | |
spmregen() { | |
# 删除原来的.xcodeproj文件 | |
local targetName=$1 | |
# 如果没有指定,则使用当前文件夹名称作为TargetName | |
if [ !$1 ]; then | |
targetName=$(basename $PWD) | |
fi | |
# .xcodeproj文件实际是一个文件夹 | |
rm -rf ${targetName}.xcodeproj | |
# 重新生成 | |
swift build && swift package generate-xcodeproj | |
} | |
#链接bandwagon服务器 | |
login() { | |
ssh $1@$BANDWAGONIP -p $BANDWAGONPORT | |
} | |
# 查看Markdown | |
rmd () { | |
pandoc $1 | lynx -stdin | |
} | |
# 彩色化支持pygments, 需要先pip install pygments | |
ccat() { | |
local style="monokai" | |
if [ $# -eq 0 ]; then | |
pygmentize -P style=$style -P tabsize=4 -f terminal256 -g | |
else | |
for NAME in $@; do | |
pygmentize -P style=$style -P tabsize=4 -f terminal256 -g "$NAME" | |
done | |
fi | |
} | |
source $ZSH/oh-my-zsh.sh | |
# Convenitent alias | |
alias zshconfig="code ~/.zshrc" | |
alias cls="clear" | |
# Crash文件符号解析,使用方法为 SYMBOL crash文件名.crash dSYM符号文件名.dsym > 倒出日志名 | |
alias SYMBOL="/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash"`` | |
alias safeback="git reset --soft" | |
alias de="deactivate" | |
# 当前文件夹大小 | |
alias cds="du -hs ." | |
# 解压 | |
alias untar="tar -zxvf" | |
# 生成随机密码 | |
alias getpass="openssl rand -base64 20" | |
# 普通的 ping 将永远持续下去。我们不希望这样。相反,让我们将其限制在五个 ping。 | |
alias ping='ping -c 5' | |
# 在任何你想要的文件夹中启动 Web 服务器 | |
alias www='python -m SimpleHTTPServer 8000' | |
# 获取外部IP地址 | |
alias ipe='curl ipinfo.io/ip' | |
# 本地IP地址 | |
alias ipi='ipconfig getifaddr en0' | |
# 测网速, 需要先安装speedtest-cli | |
alias speed='speedtest-cli --simple' | |
# 校验文件sum | |
alias sha='shasum -a 256 ' | |
# 断点续传下载 | |
alias wget='wget -c '· | |
# 系统Logo以及信息 | |
alias logo="screenfetch" | |
# 播放星球大战 | |
alias starwars="telnet towel.blinkenlights.nl" | |
# 打开格式 | |
alias -s html=code | |
alias -s rb=code | |
alias -s py=code | |
# brew cask upgrade | |
alias bua='brew cu -a' | |
# activate virtual env | |
alias srv='source venv/bin/activate' | |
# 更新oh-my-zsh | |
alias uz='upgrade_oh_my_zsh' | |
# .a文件支持平台 | |
alias plt='lipo -info' | |
# git 重置上次提交 | |
alias gre='git reset HEAD~' | |
# shutdown log | |
alias sdl="log show --predicate 'eventMessage contains "Previous shutdown cause"' --last 24h" | |
# 修改上次提交 | |
alias fix=git commit --amend --no-edit | |
# brew install without update | |
alias bi='HOMEBREW_NO_AUTO_UPDATE=1 brew install' | |
# My Powerlevel9 Config | |
prompt_zsh_battery_level() { | |
local percentage1=`pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p'` | |
local percentage=`echo "${percentage1//\%}"` | |
local color='%F{red}' | |
local symbol="\uf00d" | |
pmset -g ps | grep "discharging" > /dev/null | |
if [ $? -eq 0 ]; then | |
local charging="false"; | |
else | |
local charging="true"; | |
fi | |
if [ $percentage -le 20 ] | |
then symbol='\uf579' ; color='%F{red}' ; | |
#10% | |
elif [ $percentage -gt 19 ] && [ $percentage -le 30 ] | |
then symbol="\uf57a" ; color='%F{red}' ; | |
#20% | |
elif [ $percentage -gt 29 ] && [ $percentage -le 40 ] | |
then symbol="\uf57b" ; color='%F{yellow}' ; | |
#35% | |
elif [ $percentage -gt 39 ] && [ $percentage -le 50 ] | |
then symbol="\uf57c" ; color='%F{yellow}' ; | |
#45% | |
elif [ $percentage -gt 49 ] && [ $percentage -le 60 ] | |
then symbol="\uf57d" ; color='%F{blue}' ; | |
#55% | |
elif [ $percentage -gt 59 ] && [ $percentage -le 70 ] | |
then symbol="\uf57e" ; color='%F{blue}' ; | |
#65% | |
elif [ $percentage -gt 69 ] && [ $percentage -le 80 ] | |
then symbol="\uf57f" ; color='%F{blue}' ; | |
#75% | |
elif [ $percentage -gt 79 ] && [ $percentage -le 90 ] | |
then symbol="\uf580" ; color='%F{blue}' ; | |
#85% | |
elif [ $percentage -gt 89 ] && [ $percentage -le 99 ] | |
then symbol="\uf581" ; color='%F{blue}' ; | |
#85% | |
elif [ $percentage -gt 98 ] | |
then symbol="\uf578" ; color='%F{green}' ; | |
#100% | |
fi | |
if [ $charging = "true" ]; | |
then color='%F{green}'; if [ $percentage -gt 98 ]; then symbol='\uf584'; fi | |
fi | |
echo -n "%{$color%}$symbol" ; | |
} | |
zsh_internet_signal(){ | |
local color | |
local symbol="\uf7ba" | |
if ifconfig en0 | grep inactive &> /dev/null; then | |
color="%F{red}" | |
else | |
color="%F{blue}" | |
fi | |
echo -n "%{$color%}$symbol " | |
} | |
POWERLEVEL9K_PROMPT_ON_NEWLINE=true | |
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true | |
POWERLEVEL9K_RPROMPT_ON_NEWLINE=true | |
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 | |
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_beginning" | |
POWERLEVEL9K_RVM_BACKGROUND="black" | |
POWERLEVEL9K_RVM_FOREGROUND="249" | |
POWERLEVEL9K_RVM_VISUAL_IDENTIFIER_COLOR="red" | |
POWERLEVEL9K_TIME_BACKGROUND="black" | |
POWERLEVEL9K_TIME_FOREGROUND="249" | |
POWERLEVEL9K_TIME_FORMAT="\UF43A %D{%I:%M \UF133 %m.%d.%y}" | |
POWERLEVEL9K_RVM_BACKGROUND="black" | |
POWERLEVEL9K_RVM_FOREGROUND="249" | |
POWERLEVEL9K_RVM_VISUAL_IDENTIFIER_COLOR="red" | |
POWERLEVEL9K_STATUS_VERBOSE=false | |
POWERLEVEL9K_VCS_CLEAN_FOREGROUND='black' | |
POWERLEVEL9K_VCS_CLEAN_BACKGROUND='green' | |
POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND='black' | |
POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND='yellow' | |
POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='white' | |
POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='black' | |
POWERLEVEL9K_COMMAND_EXECUTION_TIME_BACKGROUND='black' | |
POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND='blue' | |
POWERLEVEL9K_FOLDER_ICON='' | |
POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE=true | |
POWERLEVEL9K_STATUS_VERBOSE=false | |
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0 | |
POWERLEVEL9K_VCS_UNTRACKED_ICON='\u25CF' | |
POWERLEVEL9K_VCS_UNSTAGED_ICON='\u00b1' | |
POWERLEVEL9K_VCS_INCOMING_CHANGES_ICON='\u2193' | |
POWERLEVEL9K_VCS_OUTGOING_CHANGES_ICON='\u2191' | |
POWERLEVEL9K_VCS_COMMIT_ICON="\uf417" | |
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="%F{blue}\u256D\u2500%f" | |
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%F{blue}\u2570\uf460%f " | |
POWERLEVEL9K_CUSTOM_BATTERY_STATUS="prompt_zsh_battery_level" | |
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=( | |
context | |
os_icon | |
custom_internet_signal | |
custom_battery_status_joined | |
ssh | |
root_indicator | |
dir | |
dir_writable | |
vcs | |
swift_version node_version go_version virtualenv) | |
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=( | |
command_execution_time | |
status | |
time) | |
HIST_STAMPS="mm/dd/yyyy" | |
DISABLE_UPDATE_PROMPT=false | |
# POWERLEVEL9K_VCS_GIT_HOOKS=(vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname) | |
# zsh-highlight | |
#Xcode清理缓存数据 | |
xcodeCleanup() { | |
echo "移除 Xcode 运行安装 APP 产生的缓存文件(DerivedData)" | |
if [ -d $DERIVEDDATAPATH ]; then | |
rm -rf $DERIVEDDATAPATH | |
fi | |
echo "移除 playground 的项目缓存(XCPGDevices)" | |
if [ -d $PLAYGROUNDCACHE ]; then | |
rm -rf $PLAYGROUNDCACHE | |
fi | |
echo "移除模拟器的缓存数据(Devices)" | |
if [ -d $DEVICESCACHEPATH ]; then | |
rm -rf $DEVICESCACHEPATH | |
fi | |
echo "移除对旧设备的支持(iOS DeviceSupport)" | |
if [ -d $DEVICESSUPPORTPATH ]; then | |
rm -rf $DEVICESSUPPORTPATH | |
fi | |
echo "移除 APP 打包的ipa历史版本(Archives)" | |
if [ -d $ARCHIVESPATH ]; then | |
rm -rf $ARCHIVESPATH | |
fi | |
} | |
# 彩色打印 | |
echo_color() { | |
case $1 in | |
green) | |
echo -e "\033[32;40m$2\033[0m" | |
;; | |
red) | |
echo -e "\033[31;40m$2\033[0m" | |
;; | |
*) | |
echo "Example: echo_color red string" | |
esac | |
} | |
# 检查网址是否可用 | |
check_url() { | |
local HTTP_CODE=$(curl -o /dev/null --connect-timeout 3 -s -w "%{http_code}" $1) | |
if [ $HTTP_CODE -ne 200 ]; then | |
echo "Warning: $1 Access failure!" | |
else | |
echo "Success" | |
fi | |
} | |
# proxy 快捷启动 | |
proxy() { | |
local port1=$1 | |
local port2=$2 | |
if [ ! $1 ]; then | |
port1=41091 | |
fi | |
if [ !$2 ]; then | |
port2=1090 | |
fi | |
echo_color green "HTTP PORT: $port1" | |
echo_color green "SOCKS PORT: $port2" | |
# 启动配置 | |
export https_proxy=http://127.0.0.1:$port1 http_proxy=http://127.0.0.1:$port1 all_proxy=socks5://127.0.0.1:$port2 | |
} | |
# 彩色日历 (需要安装boxes、lolcat、cal、gawk) | |
ccal() { | |
clear | |
cal | boxes -d diamonds -p a1t2l3 | boxes -a c -d scroll | lolcat | |
sleep 3 | |
while : | |
do echo $LINES $COLUMNS $(($RANDOM%$COLUMNS)) $(printf "\u2744\n") | |
sleep 0.1 | |
done | gawk '{a[$3]=0;for(x in a) {o=a[x];a[x]=a[x]+1;printf "\033[%s;%sH ",o,x;printf "\033[%s;%sH%s \033[0;0H",a[x],x,$4;}}' | |
} | |
# 创建virtualenv 环境 | |
ve() { | |
# 创建一个独立的Python运行环境,我们还加上了参数--no-site-packages,这样,已经安装到系统Python环境中的所有第三方包都不会复制过来 | |
virtualenv --no-site-packages venv | |
# 开始虚拟环境 | |
source venv/bin/activate | |
} | |
# 有道词典查询, 需要先安装w3m | |
youdao() { | |
if [ -z "$1" ] | |
then | |
echo 'Usage youdao <word>' | |
else | |
w3m -dump "http://dict.youdao.com/search?q=$1" | |
fi | |
} | |
[ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh | |
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh | |
source $ZPLUG_HOME/init.zsh | |
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment