Skip to content

Instantly share code, notes, and snippets.

@ellisio ellisio/.functions
Created Dec 15, 2016

Embed
What would you like to do?
# Create a new directory and enter it
function mkd() {
mkdir -p "$@" && cd "$@"
}
# Determine size of a file or total size of a directory
function fs() {
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh
else
local arg=-sh
fi
if [[ -n "$@" ]]; then
du $arg -- "$@"
else
du $arg .[^.]* *
fi
}
# Use Git’s colored diff when available
hash git &>/dev/null
if [ $? -eq 0 ]; then
function diff() {
git diff --no-index --color-words "$@"
}
fi
# Syntax-highlight JSON strings or files
# Usage: `json '{"foo":42}'` or `echo '{"foo":42}' | json`
hash pygmentize &>/dev/null
if [ $? -eq 1 ]; then
sudo easy_install Pygments
fi
function json() {
if [ -t 0 ]; then # argument
python -mjson.tool <<< "$*" | pygmentize -l javascript
else # pipe
python -mjson.tool | pygmentize -l javascript
fi
}
# All the dig info
function digga() {
dig +nocmd "$1" any +multiline +noall +answer
}
# Docker Commands
function dc() {
docker-compose $@
}
function doc() {
docker $@
}
function doc-cleanup() {
docker rm -f $(docker ps -a | grep Exited | grep -v "(0)" | awk '{print $1}')
docker rmi $(docker images -f "dangling=true" -q)
docker images -q | xargs docker rmi
}
function doc-clear() {
docker rm -f $(docker ps -a -q)
docker rmi -f $(docker images -q)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.