1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-12-23 07:58:00 +00:00
prezto/modules/utility/init.zsh

168 lines
4.1 KiB
Bash
Raw Normal View History

2012-02-01 04:37:51 +00:00
#
2012-06-03 18:02:05 +00:00
# Defines general aliases and functions.
2012-02-01 04:37:51 +00:00
#
# Authors:
# Robby Russell <robby@planetargon.com>
# Suraj N. Kurapati <sunaku@gmail.com>
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
2012-06-03 18:02:05 +00:00
# Load dependencies.
omodload 'spectrum'
# Correct commands.
setopt CORRECT
# Aliases
2012-06-10 23:35:15 +00: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'
alias scp='nocorrect scp'
# Disable globbing.
alias fc='noglob fc'
alias find='noglob find'
alias history='noglob history'
alias locate='noglob locate'
alias rake='noglob rake'
# Define general aliases.
alias _='sudo'
alias b='${(z)BROWSER}'
alias cp="${aliases[cp]:-cp} -i"
alias e='${(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
2012-06-03 18:02:05 +00:00
if is-callable 'dircolors'; then
2012-06-10 23:35:15 +00:00
# GNU Core Utilities
2012-06-03 18:02:05 +00:00
alias ls='ls --group-directories-first'
if zstyle -t ':omz: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
2012-06-10 23:35:15 +00:00
# BSD Core Utilities
2012-06-03 18:02:05 +00:00
if zstyle -t ':omz:module:utility:ls' color; then
export LSCOLORS="exfxcxdxbxegedabagacad"
alias ls="ls -G"
else
alias ls='ls -F'
fi
fi
2012-06-10 23:35:15 +00: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.
alias lp='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.
2012-06-03 18:02:05 +00:00
alias sl='ls' # I often screw this up.
2012-06-10 23:35:15 +00:00
# Mac OS X Everywhere
2012-06-03 18:02:05 +00: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 23:35:15 +00:00
# Resource Usage
alias df='df -kh'
alias du='du -kh'
2012-06-03 18:02:05 +00:00
if (( $+commands[htop] )); then
alias top=htop
else
alias topc='top -o cpu'
2012-06-10 23:35:15 +00:00
alias topm='top -o vsize'
2012-06-03 18:02:05 +00:00
fi
# Miscellaneous
2011-10-12 03:13:58 +00:00
# Serves a directory via HTTP.
alias http-serve='python -m SimpleHTTPServer'
2009-08-31 22:00:38 +00:00
2012-06-03 18:02:05 +00:00
# Functions
# Makes a directory and changes to it.
function mkdcd {
[[ -n "$1" ]] && mkdir -p "$1" && builtin cd "$1"
2009-08-31 13:03:56 +00:00
}
# 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 {
2012-04-15 00:28:28 +00:00
awk "{ print ${(j:,:):-\$${^@}} }"
}
# Finds files and executes a command on them.
function find-exec {
find . -type f -iname "*${1:-}*" -exec "${2:-file}" '{}' \;
}
2012-06-10 23:35:15 +00:00
# Displays user owned processes status.
function psu {
ps -{U,u}" ${1:-$USER}" -o 'pid,%cpu,%mem,command' "${(@)argv[2,-1]}"
}