Skip to content

Instantly share code, notes, and snippets.

@guelau
Last active July 1, 2019 09:55
Show Gist options
  • Save guelau/5765391 to your computer and use it in GitHub Desktop.
Save guelau/5765391 to your computer and use it in GitHub Desktop.
My .bashrc add on
# User specific aliases and functions
# @VAR
KUBE_NS_PREPROD="preprodns"
KUBE_NS_DEV="devns"
KUBE_NS_PROD="prodns"
function parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOUR="\[\033[0m\]"
PS1="$GREEN\u@\h$NO_COLOUR:\w$YELLOW\$(parse_git_branch)$NO_COLOUR\n\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias h='history'
alias j='jobs -l'
alias which='type -a'
alias ..='cd ..'
# Pretty-print of some PATH variables:
alias path='echo -e ${PATH//:/\\n}'
alias libpath='echo -e ${LD_LIBRARY_PATH//:/\\n}'
alias du='du -kh' # Makes a more readable output.
alias df='df -kTh'
#-------------------------------------------------------------
# The 'ls' family (this assumes you use a recent GNU ls).
#-------------------------------------------------------------
# Add colors for filetype and human-readable sizes by default on 'ls':
alias ls='ls -h --color'
alias lx='ls -lXB' # Sort by extension.
alias lk='ls -lSr' # Sort by size, biggest last.
alias lt='ls -ltr' # Sort by date, most recent last.
alias lc='ls -ltcr' # Sort by/show change time,most recent last.
alias lu='ls -ltur' # Sort by/show access time,most recent last.
# The ubiquitous 'll': directories first, with alphanumeric sorting:
alias ll="ls -lv --group-directories-first"
alias lm='ll |more' # Pipe through 'more'
alias lr='ll -R' # Recursive ls.
alias la='ll -A' # Show hidden files.
alias tree='tree -Csuh' # Nice alternative to 'recursive ls' ...
# Extract most know archives with one command
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# Visualise git log (like gitk, in the terminal)
alias lg='git log --graph --full-history --all --color --pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s"'
# Colorized git log
alias gl="git log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
# Show all unmerged remote branche
alias gunmerged="git branch -r --no-merged | grep -v HEAD | xargs -L1 git --no-pager log --pretty=tformat:'%Cgreen%d%Creset - %h by %an (%Cblue%ar%Creset)' -1"
# Show all merged remote branche
alias gmerged="git branch -r --merged | grep -v HEAD | xargs -L1 git --no-pager log --pretty=tformat:'%Cgreen%d%Creset - %h by %an (%Cblue%ar%Creset)' -1"
# Screen helper (create, list and resume
alias sc="screen -S"
alias sl="screen -ls"
alias sr="screen -r"
# Docker
# Removes all stopped containers, not used networks, all dangling images and cache.
alias doclean='docker system prune'
# Removes all containers, volumes, images, networks and cache
alias docreset='docker system prune -a --volumes'
# alternative to grep and find
alias g='ack'
alias f='fd'
# Kubernetes (kubectl alias and tools)
# kubectl completion bash > /etc/bash_completion.d/kubectl OR # kubectl completion bash > $(brew --prefix)/etc/bash_completion.d/kubectl
source <(kubectl completion bash)
alias k="kubectl"
complete -F __start_kubectl k
# kubectl completion bash | sed 's|__start_kubectl kubectl|__start_kubectl k|g' > /etc/bash_completion.d/k
# OR kubectl completion bash | sed 's|__start_kubectl kubectl|__start_kubectl k|g' > $(brew --prefix)/etc/bash_completion.d/k
alias kx="kubectl config use-context"
alias kxdev="kubectl config use-context development && kubens KUBE_NS_DEV"
alias kxstaging="kubectl config use-context staging && kubens KUBE_NS_PREPROD"
alias kxprod="kubectl config use-context production && kubens KUBE_NS_PROD"
alias kg='kubectl get'
alias kd='kubectl describe'
alias kgp='kubectl get pods'
alias kgns='kubectl get namespaces'
alias kgall='kubectl get ingress,service,deployment,pod,statefulset'
# Display current context and namespace (context)(namespace)
kc()
{
kubectl config get-contexts | gawk '/^\*/ { print "(" $2 ")" "(" $5 ")" }'
}
# Get a shell to a running pod container
ksh()
{
# use : kubectl config use-context CONTEXT && kubens NAMESPACE before
# or kxdev / kxstaging / kxprod
kubectl exec -it $1 -- /bin/bash
}
@guelau
Copy link
Author

guelau commented Oct 23, 2014

Installation

mkdir .config && cd .config
git clone https://gist.github.com/5765391.git
echo -e "\nsource `pwd`/5765391/bashrc\n" >> ~/.bashrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment