Skip to content

Instantly share code, notes, and snippets.

@garlandkr
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save garlandkr/b4688665f87d4882e54a to your computer and use it in GitHub Desktop.

Select an option

Save garlandkr/b4688665f87d4882e54a to your computer and use it in GitHub Desktop.
bash prompt with updating epoch
umask 002
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias bp='vim ~/.bash_profile'
alias sbp='source ~/.bash_profile'
alias cls='clear'
alias pack='tar -czf'
alias unpack='tar -xzf'
alias l='ls -alh'
# cd + ls
function c () {
if [ \$# = 0 ]; then
cd
l
else
cd "\$*"
l
fi
}
function ver() { "$1" --version 2>&1 | head -1 | awk "{print "\$$2"}"; }
export GO_HOME="/usr/local/go"
export PYTHON_HOME="/opt/python2.7"
export PATH=$GO_HOME/bin:$PATH
export PATH=$PYTHON_HOME/bin:$PATH
# ------------------------------------------------------------------------------
# Docker aliases
# http://kartar.net/2014/03/some-useful-docker-bash-functions-and-aliases/
# ------------------------------------------------------------------------------
alias d='sudo docker'
# Inspect IP
alias dip="d inspect --format '{{ .NetworkSettings.IPAddress }}'"
# Run daemonized container
alias dkd="d run -d -P"
# Run interactive container
alias dki="d run -t -i -P"
# Remove Containers
function drm() { d rm $(docker ps -q -a); }
# Remove Images
function dri() { d rmi $(docker images -q); }
# Build
function db() { d build -t="$1" .; }
# ------------------------------------------------------------------------------
# Git aliases
# ------------------------------------------------------------------------------
alias gu='git up'
alias gs='git status'
alias gd='git diff'
alias ga='git gc --aggressive'
alias gl='git log --format=format:[%h]-[%cn]-[%cr]-[%s] -5 $*'
alias gcm='git commit -am'
alias gmf='git merge --ff-only'
alias amend='git commit -a --amend'
# Enhanced "git log"
function gll() {
git --no-pager log --graph --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative -10 $1
echo
}
# "git fetch" + enhanced "git log"
function ggll() {
git status
git remote update
git fetch
gll
}
# Git squash last N commits
function gsq()
{
git rebase -i HEAD~$1
}
echo "Time : $(date)"
echo "OS : $(lsb_release -a 2>/dev/null | grep Description | cut -d: -f2 | xargs), $(uname -mrs)"
echo "CPU : $(cat /proc/cpuinfo | grep "model name" | head -1 | cut -d':' -f2 | sed -E -s "s/^\s*//")"
echo "Memory : $(for j in $(cat /proc/meminfo | grep -E "MemTotal|MemFree" | awk '{print $2}'); do echo $(echo "scale=2; $j / 1048576" | bc -l)G; done | sed "N;s/\n/ \/ /") (Total / Available)"
echo "Disk : $(df -h . | tail -1 | awk '{print $2" / "$4}') (Total / Available)"
echo "Docker images : $(sudo docker images | grep -v REPOSITORY | grep -v '<none>' | awk '{print $1}' | sort | uniq | awk '{printf("%s, ",$0)}' | sed -E "s/, $//")"
echo "--------------------------------------------------------------------"
echo "docker : $(ver docker 3 | cut -d, -f1), $(which docker)"
echo "git : $(ver git 3), $(which git)"
echo "perl : $(perl -v | grep 'This is perl' | cut -d'(' -f2 | cut -d')' -f1 | sed s/^v//), $(which perl)"
echo "python : $(ver python 2), $(which python)"
echo "pip : $(ver pip 2), $(which pip)"
echo "aws : $(ver aws 1 | cut -d/ -f2), $(which aws)"
echo "ansible : $(ver ansible 2), $(which ansible)"
echo "--------------------------------------------------------------------"
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
PS1='[\u@\h].[\[\e[0;32m\]`date +%s`\[\e[0m\]]\n[\[\e[0;35m\]\w\[\e[0m\]]'
PS2='[..]'
# Start tmux, try to attach to a running session
tsesh=`tmux a 2>/dev/null`
if [[ ! ${tsesh} ]]; then
echo "no old tmux sessions"
tmux
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment