#################### # functions #################### # print available colors and their numbers function colours() { for i in {0..255}; do printf "\x1b[38;5;${i}m colour${i}" if (( $i % 5 == 0 )); then printf "\n" else printf "\t" fi done } # Create a new directory and enter it function md() { mkdir -p "$@" && cd "$@" } # find shorthand function f() { find . -name "$1" } # Start an HTTP server from a directory, optionally specifying the port function server() { local port="${1:-8000}" open "http://localhost:${port}/" # Set the default Content-Type to `text/plain` instead of `application/octet-stream` # And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files) python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port" } # git log with per-commit cmd-clickable GitHub URLs (iTerm) # function gf() { # local remote="$(git remote -v | awk '/^origin.*\(push\)$/ {print $2}')" # [[ "$remote" ]] || return # local user_repo="$(echo "$remote" | perl -pe 's/.*://;s/\.git$//')" # git log $* --name-status --color | awk "$(cat < # Credits to http://dotfiles.org/~pseup/.bashrc function extract() { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xjf $1 ;; *.tar.gz) tar xzf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) rar x $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 }