170 lines
4.1 KiB
Bash
170 lines
4.1 KiB
Bash
#
|
|
# Defines general aliases and functions.
|
|
#
|
|
# Authors:
|
|
# Robby Russell <robby@planetargon.com>
|
|
# Suraj N. Kurapati <sunaku@gmail.com>
|
|
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
|
#
|
|
|
|
# Load dependencies.
|
|
pmodload 'helper' 'spectrum'
|
|
|
|
# Correct commands.
|
|
setopt CORRECT
|
|
|
|
#
|
|
# Aliases
|
|
#
|
|
|
|
# Disable correction.
|
|
for command (ack cd cp ebuild gcc gist grep heroku ln man mkdir mv mysql rm); do
|
|
if is-callable $command; then
|
|
alias $command="nocorrect $command"
|
|
fi
|
|
done
|
|
|
|
# Disable globbing.
|
|
for command (fc find ftp history locate rake rsync scp sftp); do
|
|
if is-callable $command; then
|
|
alias $command="noglob $command"
|
|
fi
|
|
done
|
|
|
|
unset command
|
|
|
|
|
|
# Define general aliases.
|
|
alias _='sudo'
|
|
alias b='${(z)BROWSER}'
|
|
alias cp="${aliases[cp]:-cp} -i"
|
|
alias e='${(z)VISUAL:-${(z)EDITOR}}'
|
|
alias ln="${aliases[ln]:-ln} -i"
|
|
alias mkdir="${aliases[mkdir]:-mkdir} -p"
|
|
alias mv="${aliases[mv]:-mv} -i"
|
|
alias p='${(z)PAGER}'
|
|
alias po='popd'
|
|
alias pu='pushd'
|
|
alias rm="${aliases[rm]:-rm} -i"
|
|
alias type='type -a'
|
|
|
|
# ls
|
|
if is-callable 'dircolors'; then
|
|
# GNU Core Utilities
|
|
alias ls='ls --group-directories-first'
|
|
|
|
if zstyle -t ':prezto:module:utility:ls' color; then
|
|
if [[ -s "$HOME/.dir_colors" ]]; then
|
|
eval "$(dircolors "$HOME/.dir_colors")"
|
|
else
|
|
eval "$(dircolors)"
|
|
fi
|
|
|
|
alias ls="$aliases[ls] --color=auto"
|
|
else
|
|
alias ls="$aliases[ls] -F"
|
|
fi
|
|
else
|
|
# BSD Core Utilities
|
|
if zstyle -t ':prezto:module:utility:ls' color; then
|
|
# Define colors for BSD ls.
|
|
export LSCOLORS='exfxcxdxbxGxDxabagacad'
|
|
|
|
# Define colors for the completion system.
|
|
export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=36;01:cd=33;01:su=31;40;07:sg=36;40;07:tw=32;40;07:ow=33;40;07:'
|
|
|
|
alias ls='ls -G'
|
|
else
|
|
alias ls='ls -F'
|
|
fi
|
|
fi
|
|
|
|
alias l='ls -1A' # Lists in one column, hidden files.
|
|
alias ll='ls -lh' # Lists human readable sizes.
|
|
alias lr='ll -R' # Lists human readable sizes, recursively.
|
|
alias la='ll -A' # Lists human readable sizes, hidden files.
|
|
alias lm='la | "$PAGER"' # Lists human readable sizes, hidden files through pager.
|
|
alias lx='ll -XB' # Lists sorted by extension (GNU only).
|
|
alias lk='ll -Sr' # Lists sorted by size, largest last.
|
|
alias lt='ll -tr' # Lists sorted by date, most recent last.
|
|
alias lc='lt -c' # Lists sorted by date, most recent last, shows change time.
|
|
alias lu='lt -u' # Lists sorted by date, most recent last, shows access time.
|
|
alias sl='ls' # I often screw this up.
|
|
|
|
# Mac OS X Everywhere
|
|
if [[ "$OSTYPE" == darwin* ]]; then
|
|
alias o='open'
|
|
alias get='curl --continue-at - --location --progress-bar --remote-name --remote-time'
|
|
else
|
|
alias o='xdg-open'
|
|
alias get='wget --continue --progress=bar --timestamping'
|
|
|
|
if (( $+commands[xclip] )); then
|
|
alias pbcopy='xclip -selection clipboard -in'
|
|
alias pbpaste='xclip -selection clipboard -out'
|
|
fi
|
|
|
|
if (( $+commands[xsel] )); then
|
|
alias pbcopy='xsel --clipboard --input'
|
|
alias pbpaste='xsel --clipboard --output'
|
|
fi
|
|
fi
|
|
|
|
alias pbc='pbcopy'
|
|
alias pbp='pbpaste'
|
|
|
|
# Resource Usage
|
|
alias df='df -kh'
|
|
alias du='du -kh'
|
|
|
|
if (( $+commands[htop] )); then
|
|
alias top=htop
|
|
else
|
|
alias topc='top -o cpu'
|
|
alias topm='top -o vsize'
|
|
fi
|
|
|
|
# Miscellaneous
|
|
|
|
# Serves a directory via HTTP.
|
|
alias http-serve='python -m SimpleHTTPServer'
|
|
|
|
#
|
|
# Functions
|
|
#
|
|
|
|
# Makes a directory and changes to it.
|
|
function mkdcd {
|
|
[[ -n "$1" ]] && mkdir -p "$1" && builtin cd "$1"
|
|
}
|
|
|
|
# Changes to a directory and lists its contents.
|
|
function cdls {
|
|
builtin cd "$argv[-1]" && ls "${(@)argv[1,-2]}"
|
|
}
|
|
|
|
# Pushes an entry onto the directory stack and lists its contents.
|
|
function pushdls {
|
|
builtin pushd "$argv[-1]" && ls "${(@)argv[1,-2]}"
|
|
}
|
|
|
|
# Pops an entry off the directory stack and lists its contents.
|
|
function popdls {
|
|
builtin popd "$argv[-1]" && ls "${(@)argv[1,-2]}"
|
|
}
|
|
|
|
# Prints columns 1 2 3 ... n.
|
|
function slit {
|
|
awk "{ print ${(j:,:):-\$${^@}} }"
|
|
}
|
|
|
|
# Finds files and executes a command on them.
|
|
function find-exec {
|
|
find . -type f -iname "*${1:-}*" -exec "${2:-file}" '{}' \;
|
|
}
|
|
|
|
# Displays user owned processes status.
|
|
function psu {
|
|
ps -U "${1:-$USER}" -o 'pid,%cpu,%mem,command' "${(@)argv[2,-1]}"
|
|
}
|
|
|