-
-
Save egyleader/56558927db2a750853a0ee3ed673c5cc to your computer and use it in GitHub Desktop.
Super useful set of bash aliases for OS , git , dart , flutter , php , laravel and python , just run 'wget https://bit.ly/superBash -O ~/.bash_aliases && source ~/.bash_aliases' to get started
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
# Super Bash ⚡ | |
# this is a Super useful set of Bash & ZSH aliases for OS , git , dart , flutter , php , laravel . | |
# credit : this was forked originally from : https://gist.githubusercontent.com/hightemp/5071909 | |
# alot of modifications has been made to include , remove or modify aliases to suit the everyday | |
# developer and bash user needs and make an all in one .bash_aliases file . | |
# NOTE: for ZSH replace all .bashrc with .zshrc and all .bash_aliases with .zsh_aliases | |
# getting stated : | |
# 1. run 'wget https://bit.ly/superBash -O ~/.bash_aliases' in your triminal type | |
# 2. open ~/.bashrc in your editor | |
# 3. append this in the end (without the # .. this is for presisting the aliases ) | |
# if [ -f ~/.bash_aliases ]; then | |
# . ~/.bash_aliases | |
# fi | |
# 4. run 'source ~/.bash_aliases' in your bash treminal | |
# enjoy 🥳 | |
OS=`echo \`uname\` | tr '[:upper:]' '[:lower:]'` | |
AURL="https://bit.ly/superBash" | |
ANAME=".bash_aliases" | |
TMPAPATH="/tmp/$ANAME" | |
HOMEAPATH="~/$ANAME" | |
[ "$OS" = "windowsnt" ] && OS_WIN="yes" | |
[ "$OS" = "darwin" ] && OS_MAC="yes" | |
[ "$OS" = "linux" ] && OS_LIN="yes" | |
# Self-update | |
alias alias_update="rm -rf $TMPAPATH;wget $AURL -O $TMPAPATH;mv $TMPAPATH $HOMEAPATH;source $HOMEAPATH" | |
############################################################################ | |
# ------- OS & Filesystem Aliases -------- # | |
############################################################################ | |
# ls variants | |
alias la='ls -A' | |
alias l='ls -alFtr' | |
alias lsd='ls -d .*' | |
alias ll='ls -alF' | |
[ -n "$OS_LIN" ] && alias lt='ls --human-readable --size -1 -S --classify' # sort files by size | |
[ -n "$OS_MAC" ] && alias lt='du -sh * | sort -h' #sort files by size on MacOs | |
[ -n "$OS_LIN" ] && alias ls='ls --color=auto' | |
[ -n "$OS_MAC" ] && alias ls='ls -G' | |
# Various | |
alias h='history | tail' | |
alias hg='history | grep' | |
alias count='find . -type f | wc -l' # count files in current dir , including subfolders | |
alias mvi='mv -i' | |
alias rmi='rm -i' | |
alias rmcd='rm -r $(pwd) && cd .. ' | |
alias {ack,ak}='ack-grep' | |
alias {up,..}='cd ..' # goe up a level in filesystem | |
alias {hostname2ip,h2ip}='dig +short' | |
alias df="df -h" | |
alias du="du -h" | |
alias copyssh="pbcopy < $HOME/.ssh/id_rsa.pub" | |
# Grep | |
alias egrep='egrep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
alias grep='grep --color=auto' | |
# Clipboard | |
[ -n "$OS_MAC" ] && alias getcb='pbpaste' | |
[ -n "$OS_WIN" ] && alias getcb='cat /dev/clipboard' | |
[ -n "$OS_LIN" ] && alias getcb='xclip -o' | |
# Wget | |
alias wgetncc='wget --no-check-certificate' | |
alias wgetc='wget `getcb`' | |
alias wgetae='wget_archive_and_extract ' | |
alias wgetaec='wgetae getcb' | |
# Utils | |
alias sitecopy='wget -k -K -E -r -l 10 -p -N -F -nH ' | |
alias ytmp3='youtube-dl --extract-audio --audio-format mp3 ' | |
# MacOs Only | |
if [ -n "$OS_MAC" ]; then | |
alias free="free" | |
alias brewi='brew install' | |
alias brews='brew search' | |
alias porti='sudo port install' | |
alias ports='port search' | |
alias {dhcpup,dhcp-start}='sudo /bin/launchctl load -w /System/Library/LaunchDaemons/bootps.plist' | |
alias {dhcpdn,dhcp-stop}='sudo /bin/launchctl unload -w /System/Library/LaunchDaemons/bootps.plist' | |
fi | |
# Linux ubuntu based Only [apt package manager] | |
if [ -n "$OS_LIN" ]; then | |
alias aptcs='apt-cache search' | |
alias apti='sudo aptitude install' | |
alias aptr='sudo aptitude remove' | |
alias aptre='sudo aptitude reinstall' | |
alias apts='aptitude search' | |
alias aptu='sudo aptitude update' | |
alias aptuu='sudo aptitude update;sudo aptitude upgrade;' | |
fi | |
############################################################################ | |
# ------- Git Aliases -------- # | |
############################################################################ | |
alias gcl='git clone ' # clone a repo given the link | |
alias gst='git status' # status of git in current dir | |
alias {gbra,gb}='git branch' # make a new branch | |
alias {gco,go}='git checkout' | |
alias {gcob,gob}='git checkout -b ' | |
alias {gadd,ga}='git add ' | |
alias {gcom,gc}='git commit' | |
alias {gpul,gl}='git pull ' | |
alias {gpus,gh}='git push ' | |
alias glom='git pull origin master' | |
alias ghom='git push origin master' | |
alias gg='git grep ' | |
alias gl="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" | |
alias wip="git add . && git commit -m 'wip'" | |
alias nah="git reset --hard && git clean -df" | |
alias ifg="install_from_git " | |
alias cg='cd `git rev-parse --show-toplevel`' # takes you to the top of your Git project | |
############################################################################ | |
# ------- Python Aliases -------- # | |
############################################################################ | |
alias py='python3' | |
alias pip='pip3' | |
alias ve='python3 -m venv ./venv' # Create a Python virtual environment | |
alias va='source ./venv/bin/activate' | |
############################################################################ | |
# ------- PHP & Laravel Aliases -------- # | |
############################################################################ | |
alias serve='artisan serve' # serve laravel app | |
alias tinker='artisan tinker' # launche laravel tinker | |
alias p="phpunit" # run phpunit tests | |
alias pf="phpunit --filter " # run phpunit tests filtered | |
alias art="php artisan" # laravel artisan command | |
alias pam='php artisan migrate' # migrate all new db tables | |
alias pam:r='php artisan migrate:refresh' # migrate all tables [drops old ] | |
alias pam:rs='php artisan migrate:refresh --seed' # migrate all and seed | |
alias cdmp="composer dump-autoload -o" # refresh composer autoload | |
alias cu='composer update' # preform composer Update | |
alias ci='composer install' # preform composer Install | |
alias cr='composer require' # require a package | |
alias vu='cd ~/Homestead && vagrant up' # launch vagrant [mac os only] | |
alias vs='vagrant suspend' # suspend vargrant [mac os only] | |
alias vssh='vagrant ssh' # connect to a remote vagrant instance | |
############################################################################ | |
# ------- Flutter & Dart Aliases -------- # | |
############################################################################ | |
alias f='flutter' # just shorter | |
alias fget='flutter pub get' # get new packages in pupspec.yaml | |
alias dget='dart pub get' # get new packages in pupspec.yaml [dart project] | |
alias fcl='flutter clean && fget ' # refresh flutter build cache | |
alias fr='flutter run' # run program on default device | |
alias ft='flutter test' # run flutter tests | |
alias ftc='flutter test --coverage' # run flutter tests with coverage check | |
alias fa='flutter analyze' # analyze project for errors and warnings | |
############################################################################ | |
# ------- Docker Aliases -------- # | |
############################################################################ | |
alias daws=d-aws-cli-fn # docker with AWS | |
alias dc=dc-fn # docker-compose | |
alias dcu="docker-compose up -d" # docker-compose up | |
alias dcd="docker-compose down" # docker-compose down | |
alias dcr=dcr-fn # docker-compose run | |
alias dex=dex-fn # execute a bash shell inside the RUNNING <container> | |
alias di=di-fn # docker inspect <container> | |
alias dim="docker images" # docker images | |
alias dip=dip-fn # IP addresses of all running containers | |
alias dl=dl-fn # docker logs -f <container> | |
alias dnames=dnames-fn # names of all running containers | |
alias dps="docker ps" # docker ps | |
alias dpsa="docker ps -a" # docker ps -a | |
alias drmc=drmc-fn # remove all exited containers | |
alias drmid=drmid-fn # remove all dangling images | |
alias drun=drun-fn # execute a bash shell in NEW container from <image> | |
alias dsr=dsr-fn # stop then remove <container> | |
############################################################################ | |
# ------- OS & Filesystem Functions -------- # | |
############################################################################ | |
function wget_archive_and_extract { | |
URL=$1 | |
FILENAME=${URL##*/} | |
wget $URL -O $FILENAME | |
extract $FILENAME | |
rmi $FILENAME | |
} | |
############################################################################ | |
# ------- Docker Functions -------- # | |
############################################################################ | |
function dnames-fn { | |
for ID in `docker ps | awk '{print $1}' | grep -v 'CONTAINER'` | |
do | |
docker inspect $ID | grep Name | head -1 | awk '{print $2}' | sed 's/,//g' | sed 's%/%%g' | sed 's/"//g' | |
done | |
} | |
function dip-fn { | |
echo "IP addresses of all named running containers" | |
for DOC in `dnames-fn` | |
do | |
IP=`docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}' "$DOC"` | |
OUT+=$DOC'\t'$IP'\n' | |
done | |
echo -e $OUT | column -t | |
unset OUT | |
} | |
function dex-fn { | |
docker exec -it $1 ${2:-bash} | |
} | |
function di-fn { | |
docker inspect $1 | |
} | |
function dl-fn { | |
docker logs -f $1 | |
} | |
function drun-fn { | |
docker run -it $1 $2 | |
} | |
function dcr-fn { | |
docker-compose run $@ | |
} | |
function dsr-fn { | |
docker stop $1;docker rm $1 | |
} | |
function drmc-fn { | |
docker rm $(docker ps --all -q -f status=exited) | |
} | |
function drmid-fn { | |
imgs=$(docker images -q -f dangling=true) | |
[ ! -z "$imgs" ] && docker rmi "$imgs" || echo "no dangling images." | |
} | |
# in order to do things like dex $(dlab label) sh | |
function dlab { | |
docker ps --filter="label=$1" --format="{{.ID}}" | |
} | |
function dc-fn { | |
docker-compose $* | |
} | |
function d-aws-cli-fn { | |
docker run \ | |
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \ | |
-e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION \ | |
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \ | |
amazon/aws-cli:latest $1 $2 $3 | |
} | |
############################################################################ | |
# ------- MacOs functions -------- # | |
############################################################################ | |
function free() { | |
FREE_BLOCKS=$(vm_stat | grep free | awk '{ print $3 }' | sed 's/\.//') | |
INACTIVE_BLOCKS=$(vm_stat | grep inactive | awk '{ print $3 }' | sed 's/\.//') | |
SPECULATIVE_BLOCKS=$(vm_stat | grep speculative | awk '{ print $3 }' | sed 's/\.//') | |
FREE=$((($FREE_BLOCKS+SPECULATIVE_BLOCKS)*4096/1048576)) | |
INACTIVE=$(($INACTIVE_BLOCKS*4096/1048576)) | |
TOTAL=$((($FREE+$INACTIVE))) | |
echo "Free: $FREE MB" | |
echo "Inactive: $INACTIVE MB" | |
echo "Total free: $TOTAL MB" | |
} | |
############################################################################ | |
# ------- Git functions -------- # | |
############################################################################ | |
function install_from_git { | |
URL=$1 | |
DIRNAME="/tmp/${URL##*/}" | |
gcl $URL $DIRNAME | |
pushd $DIRNAME | |
make | |
sudo make install | |
popd | |
rm -rf $DIRNAME | |
} | |
############################################################################ | |
# ------- PHP & Laravel functions -------- # | |
############################################################################ | |
artisan() { | |
if [[ -f bin/artisan ]] | |
then | |
php bin/artisan "$@" | |
else | |
php artisan "$@" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment