varemenos
3/18/2014 - 11:33 PM

oh-my-zsh Functions

oh-my-zsh Functions

# creates a directory and cds into it
function mkd() {
	mkdir -p "$@" && cd "$@"
}

# lists zombie processes
function zombie() {
	ps aux | awk '{if ($8=="Z") { print $2 }}'
}

#lists npm packages installed
function npmls() {
	npm ls --depth=0 "$@" 2>/dev/null
}

# Go up [n] directories
function up() {
    local cdir="$(pwd)"
    if [[ "${1}" == "" ]]; then
        cdir="$(dirname "${cdir}")"
    elif ! [[ "${1}" =~ ^[0-9]+$ ]]; then
        echo "Error: argument must be a number"
    elif ! [[ "${1}" -gt "0" ]]; then
        echo "Error: argument must be positive"
    else
        for i in {1..${1}}; do
            local ncdir="$(dirname "${cdir}")"
            if [[ "${cdir}" == "${ncdir}" ]]; then
                break
            else
                cdir="${ncdir}"
            fi
        done
    fi
    cd "${cdir}"
}