Skip to content

Instantly share code, notes, and snippets.

@scplay
Last active September 7, 2026 07:02
Show Gist options
  • Select an option

  • Save scplay/5e2b68133f2a0486596f25fa45fc4c18 to your computer and use it in GitHub Desktop.

Select an option

Save scplay/5e2b68133f2a0486596f25fa45fc4c18 to your computer and use it in GitHub Desktop.
zeon util alias / shell func
# 1 for Linux
# curl -L https://gist.githubusercontent.com/scplay/5e2b68133f2a0486596f25fa45fc4c18/raw/4aa4247f593c7d0987ff6a531be11b7d9dadbfd1/.bash_profile >> ~/.bashrc
# 1 for Win
# copy this file to windows git bash ~/.bashrc file
# 1 for Mac iterm2
# curl -L https://gist.githubusercontent.com/scplay/5e2b68133f2a0486596f25fa45fc4c18/raw/4aa4247f593c7d0987ff6a531be11b7d9dadbfd1/.bash_profile >> ~/.zshrc
# 2 open new terminal
# run `urc`
alias szp='test -f ~/.zeon_profile.sh && . ~/.zeon_profile.sh'
szp
urc() {
zp
# updateZeonProfile
profile_url="https://gist.githubusercontent.com/scplay/5e2b68133f2a0486596f25fa45fc4c18/raw/.zeon_profile.sh?t=$(date +%s)"
curl -H "Cache-Control: No-Cache" $profile_url > ~/.zeon_profile.sh
echo "alias zp='echo \"last update $(date)\"'" >> ~/.zeon_profile.sh
# source zeon profile
szp
# echo last update
echo "update => $(date)"
}
#######################
# ZEON UTIL RC FILE #
#######################
VSCODE_PATH=''
ZESH_URL='https://gist.github.com/scplay/5e2b68133f2a0486596f25fa45fc4c18'
# system detect
if [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
# application util
alias vsc="open -a 'Visual Studio Code' "
alias vrc="vim ~/.zshrc"
alias vzc="vim ~/.zeon_profile.sh"
alias src="source ~/.zshrc"
alias orc='open -a "Google Chrome" $ZESH_URL/edit'
alias copyssh="cat ~/.ssh/id_rsa.pub | pbcopy"
alias randhash="openssl rand -hex 12 | tr -d '\n' | pbcopy"
alias localip="ifconfig | grep 'inet\s'"
alias myip='ipconfig getifaddr en0'
alias ocs="open -a Cursor "
alias okr="open -a Kiro "
# echo and copy date string
alias dstr='date +"%y-%m-%d" | tee /dev/tty | pbcopy'
alias dfstr='date +"%y-%m-%d %H:%M:%S" | tee /dev/tty | pbcopy'
elif [[ "$OSTYPE" == "msys" ]]; then
# Windows (part of MinGW)
alias vrc='vim ~/.bashrc'
alias src='test -f ~/.bashrc && . ~/.bashrc'
# alias vsc="/d/Users/Administrator/AppData/Local/Programs/Microsoft\ VS\ Code/Code.exe "
alias vsc="cmd //C code $*"
alias vsrc='vsc ~/.bashrc'
alias orc='start chrome $ZESH_URL'
# /c exit after run & /k keep after run
alias wstart='cd "$USERPROFILE\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" && start . && cd -'
alias copyssh="cat ~/.ssh/id_rsa.pub | clip"
# alias wstart='start cmd "/c start %USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"'
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
alias scr='screen -r'
alias scd='screen -D'
alias scl='screen ls'
alias scz='screen -S zeon'
alias bench='wget -qO- bench.sh | bash'
alias sbench='wget -qO- sb.oldking.net | bash'
alias vrc='vim ~/.bashrc'
alias src='test -f ~/.bashrc && . ~/.bashrc'
alias myip='ip addr | gp eth0 | gp inet'
# elif [[ "$OSTYPE" == "cygwin" ]]; then
# POSIX compatibility layer and Linux environment emulation for Windows
# elif [[ "$OSTYPE" == "win32" ]]; then
# I'm not sure this can happen.
# elif [[ "$OSTYPE" == "freebsd"* ]]; then
# ...
# else
# Unknown.
fi
###############
# MARK: editor / rc
###############
## vim rc
alias vzp="vim ~/.zeon_profile.sh"
alias vszp="vsc ~/.zeon_profile.sh"
######
# MARK: git
######
# git alias
alias g='git'
# cd to top git root dir
alias gcd='cd `git rev-parse --show-toplevel`'
# git pull
# git pull current branch
alias gtp='git pull'
alias gpo='git pull origin'
alias gpc='git pull origin `git rev-parse --abbrev-ref HEAD`'
# pull and rebase current branch
alias gpcr='git pull origin `current_branch` --rebase --autostash'
# pull default branch and merge to current branch
alias gpm='git pull origin `get_origin_default_branch` --no-rebase --autostash'
# push
# push current branch with set upstream & push recent reachable tag
alias gpsc='git push --follow-tags --set-upstream origin `current_branch`'
alias gpso='git push origin'
# merge
alias gm='git merge'
alias gmn='git merge --no-ff'
alias gmc='git add . && git merge --continue'
alias grc='git add . && git rebase --continue'
alias gfa='git fetch --all'
alias gfp='git fetch --prune --prune-tags'
# tag
alias gtg='git tag'
# git checkout
alias gck='git checkout'
alias gckd="git checkout dev"
alias gckm="git checkout master"
alias gckb='git checkout -B '
# git branch
alias gba='git branch -a' # git branch all
alias gbg='git branch -a | grep ' # git branch all grep
# branch info retrieve
alias ghd='git symbolic-ref refs/remotes/origin/HEAD --short' # => origin/main | origin/master
alias bghd='basename $(ghd)' # main | master
# same as bghd
alias get_origin_default_branch="git remote show origin | sed -n '/HEAD branch/s/.*: //p'"
# git submodule
alias gsu='git submodule update --remote'
# git status
alias gst='git status'
alias gsl='git show --name-only HEAD'
# git log
alias glg="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset %C(dim white)- %an%C(reset)' --abbrev-commit --date=relative"
alias gla="git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)' --all"
# git rollback
alias grb='git reset --soft HEAD~1'
alias gckr='git checkout --'
alias gfd='git clean -fd .'
alias gcl='git reset --hard && gfd'
# util command for git alias usage, DO NOT DELETE or CHANGE NAME
function current_branch() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
echo ${ref#refs/heads/}
}
function gam() {
git add .
git commit -am "$1"
}
# git commit empty message
alias gce='git commit --allow-empty -m '
alias gcm='git commit -am '
alias grs='git rev-parse --short HEAD'
# resolve conflict with Mac ZSH ~/.oh-my-zsh/plugins/git/git.plugin.zsh
alias gap='' && unalias gap
# edit ~/.zshrc
# change plugins=(git) -> plugins=()
# run zsh in iterm2
# git add commit and push
function giap() {
gam "$1"
gpsc
}
# push empty commit
function gcep() {
gce "$1"
gpsc
}
# MARK: git switch
# git switch merge
function gsmn() {
curr_branch=`git branch --show-current`
echo "git switch to $1 and merge $curr_branch"
gpcr
git checkout $1
gpcr
git merge --no-ff $curr_branch
gpsc
git checkout $curr_branch
}
function gsmnn() {
export GIT_MERGE_AUTOEDIT=no
echo "git switch merge no open edtior"
gsmn $1
}
# git stash checkout
function gsck() {
echo "git stash and checkout to $1"
# git add .
git stash
git checkout $1
git stash pop
}
# MARK: git delete
# git branch delete
alias gbd='git branch -D'
function gpsd() {
echo "git push delete tag $1"
git push origin ":$1"
}
# git tag delete specific
function gtd() {
echo "delete git tags"
git tag | grep ${1:-UNKNOWN} | xargs git push -d origin
git tag | grep ${1:-UNKNOWN} | xargs git tag -d
}
# git clean remote gone branches | git clear branch | gbc
function gcb() {
echo "delete gone branches"
git fetch --prune
git branch -vv | grep ': gone]' | sed 's/^[* ]*//' | awk '{print $1}' | xargs -r git branch -d
}
alias gbc='`gcb`'
# util for git alias
################
# php / laravel
################
## php
alias pu='./vendor/bin/phpunit'
alias puf='./vendor/bin/phpunit --filter'
alias xd='export XDEBUG_CONFIG="idekey=PHPSTORM"'
alias pufmisc='./vendor/bin/phpunit -c phpunit-misc.xml -v --filter'
# laravel
alias pa='php artisan'
alias pat='php artisan tinker'
alias pac='php artisan route:clear;php artisan config:clear;php artisan clear-compiled;'
alias pao='php artisan route:cache;php artisan config:cache;php artisan optimize'
alias pmc='php artisan make:controller'
alias pmv='php artisan make:view'
##############
## MARK: frontend
##############
## node
alias n='node'
## npm
alias nvg='npm version from-git -m "chore: sync git version to %s"'
## test for js jasmine
function jf() {
jasmine --filter="$1"
}
function run_npm() {
cmd=$1
which $cmd &>/dev/null
if [[ $? -eq 0 ]];then
eval $@
else
npm i -g $cmd
eval $@
fi
}
alias lsd='live-server --entry-file=index.html'
alias ils='npm i -g live-server'
alias brs='browser-sync '
alias ibrs='npm i -g browser-sync'
alias hs='run_npm http-server'
## yarn
function yver() {
echo "yarn version"
yarn info "$1" versions
}
## deno
alias d='deno'
alias dr='deno run'
#########
# MARK: virtual machine vm
#########
## vagrant
alias vu='vagrant up'
alias vs='vagrant ssh'
alias vh='vagrant halt'
alias vr='vagrant reload'
# reload rerun script (eg. laravel/homestead change site)
alias vrp='vagrant reload --provision'
# docker
alias dps="docker ps -a "
alias dim="docker images "
# rm all stopped docker
alias drm='docker rm $(docker ps -a -q)'
# force stop and rm all docker
alias drf='docker rm -f $(docker ps -aq)'
#########
# server / ssh / machine info
#########
### my ecs
alias sshbwg='echo "!!! DO NOT expose vps ip in public gist !!!"'
### ssh
alias sid="ssh-copy-id "
alias sshr="ssh -o 'UserKnownHostsFile /dev/null' "
### machine info
alias minfo="curl -s https://gist.githubusercontent.com/scplay/382b88781bfef570961b3dd224b8fe18/raw/955d1feaf371741e767785df3cae05dd94d8bfd3/minfo.sh | sudo bash -s --"
# ubuntu
alias agt='apt-get install -y'
alias agr='apt-get remove -y'
#########
# MARK: file ops
#########
#
# one dir files
function laraAppDebug() {
for i in $(ls ~/tmp/*.env);do sed -i 's/APP_DEBUG=true/APP_DEBUG=false/g' $i;done
}
# do not delete / or prompt if deleting more than 3 files at a time #
# only use in Linux, Mac NOT OK
# alias rm='rm -I --preserve-root'
# confirmation #
alias mv='mv -i'
#alias cp='cp -i'
alias ln='ln -i'
# file ops
alias l.='ls --color -al'
#alias ll='ls --color -Al'
alias rm='rm -i'
alias cp='cp -ia'
alias mv='mv -i'
alias le='less -N'
# create a new shell file
function nsh() {
filename=$1.sh
touch $filename
sudo chmod +x $filename
echo "#!/bin/sh\n\n" >> $filename
}
function mcd() {
echo "mkdir & cd"
mkdir $1;cd $1;
}
## file utils
# fileswap a.file and b.file
function fswap()
{
# -z test string len zero
# -n test string has len
if [ -z $2 ]; then
return
fi
local SWAP="$1.swap"
mv -f $1 $SWAP
mv $2 $1
mv -f $SWAP $2
}
function cpf()
{
if [ -f $2 ];then
rm -rf $2
fi
# cp -n 不覆盖,cp 不能不交互打 yes 覆盖删除, 只能用 yes | cp xxx 或先删除对应文件再 cp
cp -r $@
}
function tmp()
{
local TMP="$1.tmp"
rm -rf $TMP
cp -r "$1" "$TMP"
}
function retmp()
{
local TMP="$1.tmp"
if [ -f $TMP ]; then
rm -rf "$1"
cp -rf $TMP "$1"
rm -rf $TMP
else
echo "temp file: $TMP not found"
fi
}
## MARK: alias finder
# fn: 按关键词查 function/alias 定义(名字或内容命中)
# 用法1: fn branch 搜已加载到 shell 的 function/alias,分段带来源文件
# 用法2: fn branch ~/.zeon_profile.sh 给第二参数则按文本 grep 该文件(带行号)
function fn() {
local kw="$1" file="$2"
if [[ -n "$file" ]]; then
print -P "%F{8}# grep '${kw}' in ${file}%f"
grep -niE --color=always "$kw" "$file"
return
fi
local name a
for name in ${(ko)functions}; do
if [[ "$name" == *"$kw"* || "${functions[$name]}" == *"$kw"* ]]; then
print -P "%F{8}────────────────────────────────────────%f"
print -P "%F{cyan}⌗ ${name}%f %F{8}(${functions_source[$name]:-unknown})%f"
whence -f "$name"
print ""
fi
done
for a in ${(ko)aliases}; do
if [[ "$a" == *"$kw"* || "${aliases[$a]}" == *"$kw"* ]]; then
print -P "%F{yellow}⌥ alias ${a}%f=${aliases[$a]}"
fi
done
}
# zfn: fn 的快捷方式,固定按文本搜本配置文件
# 用法: zfn branch
function zfn() { fn "$1" "$HOME/.zeon_profile.sh"; }
#########
# aliases: navigation & perms
#########
alias ..='cd ..'
alias ....='cd ../../'
# Parenting changing perms on / #
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'
#########
# MARK: grep
#########
# greps
alias gp='grep --color'
alias gpp='grep -P --color'
# grep around 5 lines
alias gr='grep -A 5 -B 5 --color'
alias hgp='history | gp'
alias hg='hgp'
alias ag='alias | gp'
#########
# MARK: linux utils
#########
alias udb='updatedb'
alias lct='locate'
alias sysrc='sysv-rc-conf'
alias lastba="lastb | awk '{print $3}' | sort | uniq -c | sort -n"
alias rmf='rm -rf'
alias pf='ps -ef'
alias psc='ps -eo pid,lstart,etime,cmd | grep '
#########
# MARK: network / proxy / curl
#########
# curl utils #
alias header='curl -I'
alias cip='curl ip.sb'
alias culoc='curl -X GET https://ipinfo.io/'
# proxy
function eh() {
echo "export http proxy with port"
# eh http://localhost:7890
host="http://localhost:${1:-7890}"
export http_proxy=${host}
export https_proxy=${host}
}
alias eH='export http_proxy=;export https_proxy=;'
#########
# MARK: python server
#########
## python server
function p2server() {
port=${1:8000}
python2 -m SimpleHTTPServer $port
}
# version 3.x
function p3server() {
port=${1:8000}
python3 -m http.server $port
}
#########
# MARK: wx miniapp
#########
# wx miniapp
function nwx() {
basename=$(basename $(pwd))
dir="./"
if [[ ! -z $1 ]];then
mkdir $1
dir="$1/"
basename=$1
fi
touch $dir$basename.{wxml,js,wxss,json}
}
function mwx() {
dist=${2:-$(basename $(pwd))}
extensions=("wxml" "js" "wxss" "json")
for ext in $extensions;
do
mv ./$1.$ext ./$dist.$ext;
done
}
function uwx() {
param=$1
dir_basename=$(dirname $(pwd))
new=${param:-$(basename $(pwd))}
# if 后面要有 then
if [[ ! -z "$param" ]];then
mv $(pwd) "$dir_basename/$new"
fi
for file in $(ls -p | grep -v /); do
# 用 cut 分割文件名还可以
ext=$(echo $file | cut -f 2 -d '.')
mv $file $new.$ext
done
}
#########
# MARK: media / download
#########
# ydl
alias ydl='youtube-dl'
alias ydm='youtube-dl -f "mp4"'
#########
# mercury hg (disabled)
#########
## mercury hg shortcut
# alias hst="hg status "
# alias had="hg add ."
# alias hrm="hg remove -A "
# alias hcm="hg commit -m $1"
# alias ham="had;hrm;hcm $1"
# alias hpp="hg pull --rebase;hg push "
# alias hpg="hg purge "
# alias hlg="hg log --style compact -G"
# alias hpr='hg pull --rebase'
# alias hps='hg shelve -A -n stash;hg pull --rebase;hg unshelve -n stash;'
# User specific aliases and functions
# others
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment