2012-01-31 23:37:51 -05:00
|
|
|
#
|
2012-06-03 14:02:05 -04:00
|
|
|
# Defines general aliases and functions.
|
2012-01-31 23:37:51 -05:00
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Robby Russell <robby@planetargon.com>
|
|
|
|
# Suraj N. Kurapati <sunaku@gmail.com>
|
|
|
|
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
|
|
|
#
|
|
|
|
|
2012-06-03 14:02:05 -04:00
|
|
|
# Load dependencies.
|
2012-09-08 18:47:57 -04:00
|
|
|
pmodload 'helper' 'spectrum'
|
2012-06-03 14:02:05 -04:00
|
|
|
|
|
|
|
# Correct commands.
|
|
|
|
setopt CORRECT
|
|
|
|
|
2012-08-04 14:48:32 -04:00
|
|
|
#
|
2012-06-03 14:02:05 -04:00
|
|
|
# Aliases
|
2012-08-04 14:48:32 -04:00
|
|
|
#
|
2012-06-03 14:02:05 -04:00
|
|
|
|
2012-06-10 19:35:15 -04:00
|
|
|
# Disable correction.
|
|
|
|
alias ack='nocorrect ack'
|
|
|
|
alias cd='nocorrect cd'
|
|
|
|
alias cp='nocorrect cp'
|
|
|
|
alias ebuild='nocorrect ebuild'
|
|
|
|
alias gcc='nocorrect gcc'
|
|
|
|
alias gist='nocorrect gist'
|
|
|
|
alias grep='nocorrect grep'
|
|
|
|
alias heroku='nocorrect heroku'
|
|
|
|
alias ln='nocorrect ln'
|
|
|
|
alias man='nocorrect man'
|
|
|
|
alias mkdir='nocorrect mkdir'
|
|
|
|
alias mv='nocorrect mv'
|
|
|
|
alias mysql='nocorrect mysql'
|
|
|
|
alias rm='nocorrect rm'
|
|
|
|
|
|
|
|
# Disable globbing.
|
|
|
|
alias fc='noglob fc'
|
|
|
|
alias find='noglob find'
|
2012-08-06 19:24:36 -04:00
|
|
|
alias ftp='noglob ftp'
|
2012-06-10 19:35:15 -04:00
|
|
|
alias history='noglob history'
|
|
|
|
alias locate='noglob locate'
|
|
|
|
alias rake='noglob rake'
|
2012-08-06 19:24:36 -04:00
|
|
|
alias rsync='noglob rsync'
|
|
|
|
alias scp='noglob scp'
|
|
|
|
alias sftp='noglob sftp'
|
2012-06-10 19:35:15 -04:00
|
|
|
|
|
|
|
# Define general aliases.
|
|
|
|
alias _='sudo'
|
|
|
|
alias b='${(z)BROWSER}'
|
|
|
|
alias cp="${aliases[cp]:-cp} -i"
|
2012-08-27 22:47:51 -04:00
|
|
|
alias e='${(z)VISUAL:-${(z)EDITOR}}'
|
2012-06-10 19:35:15 -04:00
|
|
|
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
|
2012-06-03 14:02:05 -04:00
|
|
|
if is-callable 'dircolors'; then
|
2012-06-10 19:35:15 -04:00
|
|
|
# GNU Core Utilities
|
2012-06-03 14:02:05 -04:00
|
|
|
alias ls='ls --group-directories-first'
|
|
|
|
|
2012-09-03 16:08:39 -04:00
|
|
|
if zstyle -t ':prezto:module:utility:ls' color; then
|
2012-06-03 14:02:05 -04:00
|
|
|
if [[ -s "$HOME/.dir_colors" ]]; then
|
|
|
|
eval "$(dircolors "$HOME/.dir_colors")"
|
|
|
|
else
|
|
|
|
eval "$(dircolors)"
|
|
|
|
fi
|
2012-09-11 02:03:32 -04:00
|
|
|
|
2012-06-03 14:02:05 -04:00
|
|
|
alias ls="$aliases[ls] --color=auto"
|
|
|
|
else
|
|
|
|
alias ls="$aliases[ls] -F"
|
|
|
|
fi
|
|
|
|
else
|
2012-06-10 19:35:15 -04:00
|
|
|
# BSD Core Utilities
|
2012-09-03 16:08:39 -04:00
|
|
|
if zstyle -t ':prezto:module:utility:ls' color; then
|
2012-09-11 01:57:06 -04:00
|
|
|
# Define colors for BSD ls.
|
2012-09-11 02:03:32 -04:00
|
|
|
export LSCOLORS='exfxcxdxbxGxDxabagacad'
|
2012-09-11 01:57:06 -04:00
|
|
|
|
|
|
|
# Define colors for the completion system.
|
2012-09-11 02:03:32 -04:00
|
|
|
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:'
|
2012-09-11 01:57:06 -04:00
|
|
|
|
2012-09-11 02:03:32 -04:00
|
|
|
alias ls='ls -G'
|
2012-06-03 14:02:05 -04:00
|
|
|
else
|
|
|
|
alias ls='ls -F'
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2012-06-10 19:35:15 -04:00
|
|
|
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.
|
2012-06-23 13:09:55 -04:00
|
|
|
alias lm='la | "$PAGER"' # Lists human readable sizes, hidden files through pager.
|
2012-06-10 19:35:15 -04:00
|
|
|
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.
|
2012-06-03 14:02:05 -04:00
|
|
|
alias sl='ls' # I often screw this up.
|
|
|
|
|
2012-06-10 19:35:15 -04:00
|
|
|
# Mac OS X Everywhere
|
2012-06-03 14:02:05 -04:00
|
|
|
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'
|
|
|
|
|
2012-06-10 19:35:15 -04:00
|
|
|
# Resource Usage
|
|
|
|
alias df='df -kh'
|
|
|
|
alias du='du -kh'
|
|
|
|
|
2012-06-03 14:02:05 -04:00
|
|
|
if (( $+commands[htop] )); then
|
|
|
|
alias top=htop
|
|
|
|
else
|
|
|
|
alias topc='top -o cpu'
|
2012-06-10 19:35:15 -04:00
|
|
|
alias topm='top -o vsize'
|
2012-06-03 14:02:05 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Miscellaneous
|
|
|
|
|
2011-10-11 23:13:58 -04:00
|
|
|
# Serves a directory via HTTP.
|
|
|
|
alias http-serve='python -m SimpleHTTPServer'
|
2009-08-31 18:00:38 -04:00
|
|
|
|
2012-08-04 14:48:32 -04:00
|
|
|
#
|
2012-06-03 14:02:05 -04:00
|
|
|
# Functions
|
2012-08-04 14:48:32 -04:00
|
|
|
#
|
2012-06-03 14:02:05 -04:00
|
|
|
|
2011-07-14 17:19:05 -04:00
|
|
|
# Makes a directory and changes to it.
|
2012-03-23 14:57:51 -04:00
|
|
|
function mkdcd {
|
2012-05-11 08:52:11 -04:00
|
|
|
[[ -n "$1" ]] && mkdir -p "$1" && builtin cd "$1"
|
2009-08-31 09:03:56 -04:00
|
|
|
}
|
2010-12-24 17:20:57 -05:00
|
|
|
|
2011-07-14 17:19:05 -04:00
|
|
|
# Changes to a directory and lists its contents.
|
2012-04-15 10:31:53 -04:00
|
|
|
function cdls {
|
|
|
|
builtin cd "$argv[-1]" && ls "${(@)argv[1,-2]}"
|
2011-05-30 18:39:04 -04:00
|
|
|
}
|
|
|
|
|
2011-07-14 17:19:05 -04:00
|
|
|
# Pushes an entry onto the directory stack and lists its contents.
|
2012-04-15 10:31:53 -04:00
|
|
|
function pushdls {
|
|
|
|
builtin pushd "$argv[-1]" && ls "${(@)argv[1,-2]}"
|
2011-05-30 18:39:04 -04:00
|
|
|
}
|
|
|
|
|
2011-07-14 17:19:05 -04:00
|
|
|
# Pops an entry off the directory stack and lists its contents.
|
2012-04-15 10:31:53 -04:00
|
|
|
function popdls {
|
|
|
|
builtin popd "$argv[-1]" && ls "${(@)argv[1,-2]}"
|
2011-05-30 18:39:04 -04:00
|
|
|
}
|
|
|
|
|
2011-07-14 17:19:05 -04:00
|
|
|
# Prints columns 1 2 3 ... n.
|
2012-03-23 14:57:51 -04:00
|
|
|
function slit {
|
2012-04-14 20:28:28 -04:00
|
|
|
awk "{ print ${(j:,:):-\$${^@}} }"
|
2011-07-14 17:19:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Finds files and executes a command on them.
|
2012-03-23 14:57:51 -04:00
|
|
|
function find-exec {
|
2011-07-14 17:19:05 -04:00
|
|
|
find . -type f -iname "*${1:-}*" -exec "${2:-file}" '{}' \;
|
2011-05-30 18:39:04 -04:00
|
|
|
}
|
|
|
|
|
2012-06-10 19:35:15 -04:00
|
|
|
# Displays user owned processes status.
|
|
|
|
function psu {
|
2012-09-06 23:43:40 -04:00
|
|
|
ps -U "${1:-$USER}" -o 'pid,%cpu,%mem,command' "${(@)argv[2,-1]}"
|
2012-06-10 19:35:15 -04:00
|
|
|
}
|
|
|
|
|