Last active
March 1, 2025 17:38
-
-
Save scplay/5e2b68133f2a0486596f25fa45fc4c18 to your computer and use it in GitHub Desktop.
zeon util alias / shell func
This file contains hidden or 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
# 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)" | |
} | |
This file contains hidden or 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
####################### | |
# 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 src="source ~/.zshrc" | |
alias orc='open -a "Google Chrome" $ZESH_URL' | |
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' | |
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 itrojan='source <(curl -sL https://git.io/trojan-install)' | |
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 | |
## vim rc | |
alias vzp="vim ~/.zeon_profile.sh" | |
alias vszp="vsc ~/.zeon_profile.sh" | |
###### | |
# git | |
###### | |
# git alias | |
alias g='git' | |
# 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 | |
alias gpsc='git push --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 gfa='git fetch --all' | |
# 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 ' | |
alias gba='git branch -a' | |
# 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 get_origin_default_branch="git remote show origin | sed -n '/HEAD branch/s/.*: //p'" | |
# 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" | |
} | |
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 | |
function giap() { | |
gam "$1" | |
git push | |
} | |
# git switch merge | |
function gsmn() { | |
curr_branch=`git branch --show-current` | |
echo "git switch to $1 and merge $curr_branch" | |
git checkout $1 | |
git pull origin $1 | |
git merge --no-ff $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 | |
} | |
# git branch delete | |
alias gbd='git branch -D' | |
function gpsd() { | |
echo "git push delete tag $1" | |
git push origin ":$1" | |
} | |
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 | |
} | |
# util for git alias | |
## 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' | |
############## | |
## frontent | |
############## | |
## node | |
alias n='node' | |
## npm | |
## 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' | |
# 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' | |
alias ..='cd ..' | |
alias ....='cd ../../' | |
# Parenting changing perms on / # | |
alias chown='chown --preserve-root' | |
alias chmod='chmod --preserve-root' | |
alias chgrp='chgrp --preserve-root' | |
# curl utils # | |
alias header='curl -I' | |
alias cip='curl ip.sb' | |
alias culoc='curl -X GET https://ipinfo.io/' | |
######### | |
# 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)' | |
### 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 --" | |
# | |
# one dir files | |
function laraAppDebug() { | |
for i in $(ls ~/tmp/*.env);do sed -i 's/APP_DEBUG=true/APP_DEBUG=false/g' $i;done | |
} | |
# User specific aliases and functions | |
# ubuntu | |
alias agt='apt-get install -y' | |
alias agr='apt-get remove -y' | |
# 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; | |
} | |
# 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' | |
# 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 ' | |
## 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 | |
} | |
## alias | |
alias fn="declare -f | gr" | |
## mercury hg shorcut | |
# 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;' | |
## python server | |
function p2server() { | |
port=${1:8000} | |
python2 -m SimpleHTTPServer $port | |
} | |
# version 3.x | |
function p3server() { | |
port=${1:8000} | |
python3 -m http.server $port | |
} | |
# ydl | |
alias ydl='youtube-dl' | |
alias ydm='youtube-dl -f "mp4"' | |
# 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=;' | |
# 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 | |
} | |
# others | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment