Skip to content

Instantly share code, notes, and snippets.

@lucaswhitman
Last active January 3, 2020 16:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lucaswhitman/59b5fb8a8167ef6cf728c9c2810e7910 to your computer and use it in GitHub Desktop.
Save lucaswhitman/59b5fb8a8167ef6cf728c9c2810e7910 to your computer and use it in GitHub Desktop.
Bash aliases
#colorized man pages
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
}
#colorized maven
function color_maven() {
local BLUE=""
local RED=""
local LIGHT_RED=""
local LIGHT_GRAY=""
local LIGHT_GREEN=""
local LIGHT_BLUE=""
local LIGHT_CYAN=""
local YELLOW=""
local WHITE=""
local NO_COLOUR=""
/usr/local/bin/mvn "$@" | sed \
-e "s/Tests run: \([^,]*\), Failures: \([^,]*\), Errors: \([^,]*\), Skipped: \([^,]*\)/${LIGHT_GREEN}Tests run: \1$NO_COLOUR, ${RED}Failures: \2$NO_COLOUR, ${YELLOW}Errors: \3$NO_COLOUR, ${LIGHT_BLUE}Skipped: \4$NO_COLOUR/g" \
-e "s/\(\[\{0,1\}WARN\(ING\)\{0,1\}\]\{0,1\}.*\)/$YELLOW\1$NO_COLOUR/g" \
-e "s/\(\[ERROR\].*\)/$RED\1$NO_COLOUR/g" \
-e "s/\(\(BUILD \)\{0,1\}FAILURE.*\)/$RED\1$NO_COLOUR/g" \
-e "s/\(\(BUILD \)\{0,1\}SUCCESS.*\)/$LIGHT_GREEN\1$NO_COLOUR/g" \
-e "s/\(\[INFO\] [^-].*\)/$LIGHT_GRAY\1$NO_COLOUR/g" \
-e "s/\(\[INFO\] -.*\)/$LIGHT_GREEN\1$NO_COLOUR/g"
return $PIPESTATUS
}
alias mvn=color_maven
# See http://www.shellperson.net/using-sudo-with-an-alias/
alias sudo='sudo '
# general linux navigation
alias ff='find . -iname'
alias ssh='ssh -q'
alias cp='cp -iv'
alias mv='mv -iv'
alias ll='ls -latr'
alias cd..='cd ../' # Go back 1 directory level (for fast typers)
alias ..='cd ../' # Go back 1 directory level
alias ...='cd ../../' # Go back 2 directory levels
alias .3='cd ../../../' # Go back 3 directory levels
alias .4='cd ../../../../' # Go back 4 directory levels
alias .5='cd ../../../../../' # Go back 5 directory levels
alias .6='cd ../../../../../../' # Go back 6 directory levels
alias ~='cd ~' # ~: Go Home
alias c='clear' # c: Clear terminal display
alias ghist='history | grep -i' # Search history
alias timestamp='date +%Y%m%d%H%M%S' # Generate timestamp
# network goodies
## to get my external IP
alias myip='curl icanhazip.com'
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
alias localip="ifconfig en0 inet | grep 'inet ' | awk ' { print $2 } '"
alias ips="ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'"
alias ports='sudo lsof -iTCP -sTCP:LISTEN -P'
alias dnsflush='sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache'
# git
alias ga='git add'
alias gc='git commit -m'
alias gd='git diff'
alias gfu='git fetch upstream'
# requires a branch after
alias grh='git reset --hard'
alias gl='git log'
alias gp='git push origin'
alias gs='git status'
alias gclean='git branch --merged | grep -v "\*" | grep -v master | grep -v dev | xargs -n 1 git branch -D'
alias go='git open'
alias gsl='git stash list'
alias gsd='git stash drop'
alias gfm='git stash && git fetch upstream && git rebase upstream/master && git stash pop'
alias gfd='git stash && git fetch upstream && git rebase upstream/develop && git stash pop'
alias gb1='git reset --soft HEAD~1'
alias gb2='git reset --soft HEAD~2'
alias gpof='git push origin --force'
# https://spindance.com/enable-git-tab-completion-bash-mac-os-x/
source /usr/local/etc/bash_completion.d/git-completion.bash
##
## the fuck (for correcting git command typos)
## brew install thefuck
##
alias fuck='eval $(thefuck $(fc -ln -1))'
# You can use whatever you want as an alias, like for Mondays:
alias fk='fuck'
alias FUCK='fuck'
# python
alias p='python3'
# misc
alias weather='curl wttr.in/denver'
# docker
alias dsa='docker stop $(docker ps -a -q)'
alias dra='docker rm $(docker ps -a -q)'
# code cov
alias cov='open coverage/*/index.html'
# grunt
alias gg='grunt serveFast --force'
# IntelliJ shortcut
alias ij='open -a /Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea .'
# helper function to change jdk
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
setjdk() {
export JAVA_HOME=$(/usr/libexec/java_home -v $1)
}
#default to 1.7
setjdk 1.7
#docker
alias dcu='docker-compose up'
alias dcd='docker-compose down'
alias dsa='docker stop $(docker ps -a -q)'
alias dra='docker rm $(docker ps -a -q)'
alias dclean='docker rm $(docker ps -a -q) && docker rmi $(docker images -q)'
alias drv='docker volume ls -qf dangling=true | xargs docker volume rm'
#mvn
alias mm='mvn clean install -DskipTests'
#ruby
alias rr='rbenv rehash'
eval "$(rbenv init -)"
alias rc='bundle exec rails c'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment