Skip to content

Instantly share code, notes, and snippets.

@xdamman
Last active December 15, 2016 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save xdamman/eefcc3a28231b5154e3d to your computer and use it in GitHub Desktop.
Save xdamman/eefcc3a28231b5154e3d to your computer and use it in GitHub Desktop.
alias reload="source ~/.profile"
#function ssh {
# ~/.scripts/iterm-setName $1
# /usr/bin/ssh $1
#}
# git alias
alias gco="git commit -am"
alias glog='git log --date-order --all --graph --format="%C(green)%h%Creset %C(yellow)%an%Creset %C(blue bold)%ar%Creset %C(red bold)%d %Creset%s"'
eval "$(hub alias -s)" # Wrap git with hub https://github.com/github/hub
# usage
alias battery='upower -i $(upower -e | grep 'BAT') | grep -E "state|to\ full|percentage|time\ to\ empty"'
alias top-cpu='ps -eo pcpu,pid,user,command | sort -k 1 -r | head -n 11 | sed -e "s/^\(.\{`tput cols`\}\).*/\1/g"'
alias top-memory='ps -eo %mem,rss,pid,user,cmd | sort -k 1,2 -r | head -n 11 | sed -e "s/^\(.\{180\}\).*/\1/g"'
# Put the screen to sleep (which also locks the computer)
alias lock="pmset displaysleepnow"
# Customizing the prompt to show "username:cwd (git-branch)>" with some colors
#function currentBranch {
# branch=$(git branch 2>/dev/null | grep "*" | sed -E "s/\* //") || return
# if [ -n "$branch" ]; then
# echo -e "(\[\e\033[36m\]"$branch"\[\e\033[m\])"
# fi
#}
#export PS1="\u\[\e\033[0;96m\]:\w\[\e\033[m\] "$(currentBranch)"> " # prompt
# up 'n' folders
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
# simple ip
alias ip='ifconfig | grep "inet " | grep -v 127.0.0.1 | sed -E "s/[^0-9]*([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}).*/\1/"'
alias localip=ip
# external ip
alias ip-external='curl http://wtfismyip.com/text'
alias externalip=ip-external
# grep with color
alias grep='grep --color=auto'
# auto completion (install first `brew install bash-completion` and `brew install git` to get the latest git version with auto complete)
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
# pretty json in color (`sudo npm install -g json`)
alias json="json -i"
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
### Aliases
# Open specified files in Sublime Text
# "s ." will open the current directory in Sublime
alias s='open -a "Sublime Text"'
# Color LS
colorflag="-G"
alias ls="command ls ${colorflag}"
alias ll="ls -l ${colorflag}"
alias l="ls -lF ${colorflag}" # all files, in long format
alias la="ls -laF ${colorflag}" # all files inc dotfiles, in long format
alias lsd='ls -lF ${colorflag} | grep "^d"' # only directories
# Quicker navigation
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
# Enable aliases to be sudo’ed
alias sudo='sudo '
# Colored up cat!
# You must install Pygments first - "sudo easy_install Pygments"
alias c='pygmentize -O style=monokai -f console256 -g'
# Git
# You must install Git first - ""
alias gs='git status'
alias ga='git add .'
alias gc='git commit -m' # requires you to type a commit message
alias gp='git push'
### Prompt Colors
# Modified version of @gf3’s Sexy Bash Prompt
# (https://github.com/gf3/dotfiles)
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi
if tput setaf 1 &> /dev/null; then
tput sgr0
if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
BLACK=$(tput setaf 37)
MAGENTA=$(tput setaf 35)
ORANGE=$(tput setaf 31)
GREEN=$(tput setaf 32)
PURPLE=$(tput setaf 34)
WHITE=$(tput setaf 37)
else
BLACK=$(tput setaf 190)
MAGENTA=$(tput setaf 5)
ORANGE=$(tput setaf 4)
GREEN=$(tput setaf 2)
PURPLE=$(tput setaf 1)
WHITE=$(tput setaf 7)
fi
BOLD=$(tput bold)
RESET=$(tput sgr0)
else
BLACK="\033[01;30m"
MAGENTA="\033[1;31m"
ORANGE="\033[1;33m"
GREEN="\033[1;32m"
PURPLE="\033[1;35m"
WHITE="\033[1;67m"
CUSTOM="\033[0;96m"
BOLD=""
RESET="\033[m"
fi
export BLACK
export MAGENTA
export ORANGE
export GREEN
export PURPLE
export WHITE
export BOLD
export RESET
# Git branch details
function parse_git_dirty() {
[[ $(git status 2> /dev/null | tail -n1) != *"working directory clean"* ]] && echo "*"
}
function parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
}
# Change this symbol to something sweet.
# (http://en.wikipedia.org/wiki/Unicode_symbols)
symbol="⚡ "
export PS1="\[${BOLD}${MAGENTA}\]\u \[$WHITE\]in \[$CUSTOM\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$WHITE\]\n$symbol\[$RESET\]"
export PS2="\[$ORANGE\]→ \[$RESET\]"
### Misc
# Only show the current directory's name in the tab
export PROMPT_COMMAND='echo -ne "\033]0;${PWD##*/}\007"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment