Last active
September 27, 2023 09:30
-
-
Save scplay/5e2b68133f2a0486596f25fa45fc4c18 to your computer and use it in GitHub Desktop.
zeon util alias / shell func
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
# curl -L https://bit.ly/2Zc29Bd >> ~/.bashrc | |
# copy this to windows git bash ~/.bashrc file | |
# for iterm2 | |
# curl -L https://bit.ly/2Zc29Bd >> ~/.zshrc | |
alias szp='test -f ~/.zeon_profile.sh && . ~/.zeon_profile.sh' | |
urc() { | |
# 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 | |
test -f ~/.zeon_profile.sh && . ~/.zeon_profile.sh | |
# echo last update | |
echo "last update $(date)" | |
} | |
szp | |
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
####################### | |
# 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' | |
alias gp='git pull' | |
alias gpo='git pull origin' | |
alias gpc='git pull origin `git rev-parse --abbrev-ref HEAD`' | |
alias gpm='git pull origin master' | |
alias gpa='git pull origin `current_branch` --rebase --autostash' | |
alias gpb='git push --set-upstream origin `current_branch`' | |
alias gm='git merge' | |
alias gmn='git merge --no-ff' | |
alias gmc='git add . && git merge --continue' | |
alias gfa='git fetch --all' | |
alias gst='git status' | |
alias gck='git checkout' | |
alias gckd="git checkout dev" | |
alias gckm="git checkout master" | |
alias gckb='git checkout -B ' | |
alias gba='git branch -a' | |
alias glg="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative" | |
# git rollback | |
alias grb='git reset --soft HEAD~1' | |
# git fns | |
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" | |
} | |
# resolve conflict with Mac ZSH ~/.oh-my-zsh/plugins/git/git.plugin.zsh | |
alias gap='' && unalias gap | |
function giap() { | |
gam "$1" | |
git push | |
} | |
# git switch merge | |
function gsmn() { | |
curr_branch=`git branch --show-current` | |
git checkout $1 | |
git pull origin $1 | |
git merge --no-ff $curr_branch | |
} | |
function gsmnn() { | |
export GIT_MERGE_AUTOEDIT=no | |
gsmn | |
} | |
# git stash checkout | |
function gsck() { | |
# git add . | |
git stash | |
git checkout $1 | |
git stash pop | |
} | |
# git branch delete | |
alias gbd='git branch -D' | |
function gpd() { | |
git push origin ":$1" | |
} | |
## 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() { | |
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 cloc='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 " | |
alias drm='docker rm $(docker ps -a -q)' | |
### 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' | |
function nsh() { | |
filename=$1.sh | |
touch $filename | |
sudo chmod +x $filename | |
echo "#!/bin/sh\n\n" >> $filename | |
} | |
## mkdir & cd | |
function mcd() { | |
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 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 ' | |
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" | |
## 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() { | |
# eh http://localhost:7890 | |
host="http://localhost:1083" | |
export http_proxy=${1:-host} | |
export https_proxy=${1:-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