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.
|
2012-09-08 22:47:57 +00:00
|
|
|
pmodload 'helper' 'spectrum'
|
2012-06-03 18:02:05 +00:00
|
|
|
|
|
|
|
# Correct commands.
|
2019-01-19 10:54:49 +00:00
|
|
|
if zstyle -T ':prezto:module:utility' correct; then
|
|
|
|
setopt CORRECT
|
|
|
|
fi
|
2012-06-03 18:02:05 +00:00
|
|
|
|
2021-04-29 22:44:26 +00:00
|
|
|
# Load 'run-help' function.
|
|
|
|
autoload -Uz run-help-{ip,openssl,sudo}
|
|
|
|
|
2012-08-04 18:48:32 +00:00
|
|
|
#
|
2012-06-03 18:02:05 +00:00
|
|
|
# Aliases
|
2012-08-04 18:48:32 +00:00
|
|
|
#
|
2012-06-03 18:02:05 +00:00
|
|
|
|
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'
|
|
|
|
|
|
|
|
# Disable globbing.
|
2014-02-16 23:29:01 +00:00
|
|
|
alias bower='noglob bower'
|
2012-06-10 23:35:15 +00:00
|
|
|
alias fc='noglob fc'
|
|
|
|
alias find='noglob find'
|
2012-08-06 23:24:36 +00:00
|
|
|
alias ftp='noglob ftp'
|
2012-06-10 23:35:15 +00:00
|
|
|
alias history='noglob history'
|
|
|
|
alias locate='noglob locate'
|
|
|
|
alias rake='noglob rake'
|
2017-12-18 21:35:19 +00:00
|
|
|
alias rsync='noglob rsync'
|
|
|
|
alias scp='noglob scp'
|
2012-08-06 23:24:36 +00:00
|
|
|
alias sftp='noglob sftp'
|
2012-06-10 23:35:15 +00:00
|
|
|
|
|
|
|
# Define general aliases.
|
|
|
|
alias _='sudo'
|
|
|
|
alias b='${(z)BROWSER}'
|
2017-07-11 03:40:37 +00:00
|
|
|
|
2017-04-15 21:06:05 +00:00
|
|
|
alias diffu="diff --unified"
|
2012-08-28 02:47:51 +00:00
|
|
|
alias e='${(z)VISUAL:-${(z)EDITOR}}'
|
2012-06-10 23:35:15 +00:00
|
|
|
alias mkdir="${aliases[mkdir]:-mkdir} -p"
|
|
|
|
alias p='${(z)PAGER}'
|
|
|
|
alias po='popd'
|
|
|
|
alias pu='pushd'
|
2016-05-25 23:31:11 +00:00
|
|
|
alias sa='alias | grep -i'
|
2012-06-10 23:35:15 +00:00
|
|
|
alias type='type -a'
|
|
|
|
|
2017-07-11 18:52:47 +00:00
|
|
|
# Safe ops. Ask the user before doing anything destructive.
|
|
|
|
alias cpi="${aliases[cp]:-cp} -i"
|
|
|
|
alias lni="${aliases[ln]:-ln} -i"
|
2021-05-01 06:28:09 +00:00
|
|
|
alias mvi="${aliases[mv]:-mv} -i"
|
|
|
|
alias rmi="${aliases[rm]:-rm} -i"
|
2017-07-11 18:52:47 +00:00
|
|
|
if zstyle -T ':prezto:module:utility' safe-ops; then
|
2019-09-22 00:29:18 +00:00
|
|
|
alias cp="${aliases[cp]:-cp} -i"
|
|
|
|
alias ln="${aliases[ln]:-ln} -i"
|
2021-05-01 06:28:09 +00:00
|
|
|
alias mv="${aliases[mv]:-mv} -i"
|
|
|
|
alias rm="${aliases[rm]:-rm} -i"
|
2017-07-11 18:52:47 +00:00
|
|
|
fi
|
|
|
|
|
2012-06-10 23:35:15 +00:00
|
|
|
# ls
|
2021-05-01 06:28:09 +00:00
|
|
|
if [[ ${(@M)${(f)"$(ls --version 2>&1)"}:#*GNU *} ]]; then
|
2012-06-10 23:35:15 +00:00
|
|
|
# GNU Core Utilities
|
2018-10-15 12:56:41 +00:00
|
|
|
|
|
|
|
if zstyle -T ':prezto:module:utility:ls' dirs-first; then
|
|
|
|
alias ls="${aliases[ls]:-ls} --group-directories-first"
|
|
|
|
fi
|
2012-06-03 18:02:05 +00:00
|
|
|
|
2012-09-03 20:08:39 +00:00
|
|
|
if zstyle -t ':prezto:module:utility:ls' color; then
|
2021-05-01 06:28:09 +00:00
|
|
|
# Define colors for GNU ls if they're not already defined
|
|
|
|
if (( ! $+LS_COLORS )); then
|
|
|
|
# Try dircolors when available
|
|
|
|
if is-callable 'dircolors'; then
|
|
|
|
eval "$(dircolors --sh $HOME/.dir_colors(.N))"
|
2018-03-31 00:47:05 +00:00
|
|
|
else
|
2021-05-01 06:28:09 +00: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:'
|
2018-03-31 00:47:05 +00:00
|
|
|
fi
|
2012-06-03 18:02:05 +00:00
|
|
|
fi
|
2012-09-11 06:03:32 +00:00
|
|
|
|
2015-05-19 22:24:04 +00:00
|
|
|
alias ls="${aliases[ls]:-ls} --color=auto"
|
2012-06-03 18:02:05 +00:00
|
|
|
else
|
2015-05-19 22:24:04 +00:00
|
|
|
alias ls="${aliases[ls]:-ls} -F"
|
2012-06-03 18:02:05 +00:00
|
|
|
fi
|
|
|
|
else
|
2012-06-10 23:35:15 +00:00
|
|
|
# BSD Core Utilities
|
2021-05-01 06:28:09 +00:00
|
|
|
|
2012-09-03 20:08:39 +00:00
|
|
|
if zstyle -t ':prezto:module:utility:ls' color; then
|
2018-03-31 00:47:05 +00:00
|
|
|
# Define colors for BSD ls if they're not already defined
|
2021-05-01 06:28:09 +00:00
|
|
|
if (( ! $+LSCOLORS )); then
|
2018-03-31 00:47:05 +00:00
|
|
|
export LSCOLORS='exfxcxdxbxGxDxabagacad'
|
|
|
|
fi
|
2012-09-11 05:57:06 +00:00
|
|
|
|
2015-05-19 22:24:04 +00:00
|
|
|
alias ls="${aliases[ls]:-ls} -G"
|
2012-06-03 18:02:05 +00:00
|
|
|
else
|
2015-05-19 22:24:04 +00:00
|
|
|
alias ls="${aliases[ls]:-ls} -F"
|
2012-06-03 18:02:05 +00:00
|
|
|
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.
|
2012-06-23 17:09:55 +00:00
|
|
|
alias lm='la | "$PAGER"' # Lists human readable sizes, hidden files through pager.
|
2012-06-10 23:35:15 +00:00
|
|
|
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.
|
2021-05-01 06:28:09 +00:00
|
|
|
alias sl='ls' # Correction for common spelling error.
|
|
|
|
|
|
|
|
if [[ ${(@M)${(f)"$(ls --version 2>&1)"}:#*GNU *} ]]; then
|
|
|
|
alias lx='ll -XB' # Lists sorted by extension (GNU only).
|
|
|
|
fi
|
2012-06-03 18:02:05 +00:00
|
|
|
|
2014-11-24 18:05:34 +00:00
|
|
|
# Grep
|
|
|
|
if zstyle -t ':prezto:module:utility:grep' color; then
|
2021-05-09 02:26:03 +00:00
|
|
|
export GREP_COLOR=${GREP_COLOR:-'37;45'} # BSD.
|
|
|
|
export GREP_COLORS=${GREP_COLORS:-"mt=$GREP_COLOR"} # GNU.
|
2014-12-08 23:13:25 +00:00
|
|
|
|
2015-05-19 22:24:04 +00:00
|
|
|
alias grep="${aliases[grep]:-grep} --color=auto"
|
2014-11-24 18:05:34 +00:00
|
|
|
fi
|
|
|
|
|
2018-04-16 22:51:57 +00:00
|
|
|
# macOS Everywhere
|
2020-02-13 08:56:29 +00:00
|
|
|
if is-darwin; then
|
2012-06-03 18:02:05 +00:00
|
|
|
alias o='open'
|
2020-02-13 08:56:29 +00:00
|
|
|
elif is-cygwin; then
|
2014-01-03 19:46:30 +00:00
|
|
|
alias o='cygstart'
|
|
|
|
alias pbcopy='tee > /dev/clipboard'
|
|
|
|
alias pbpaste='cat /dev/clipboard'
|
2020-07-20 23:07:53 +00:00
|
|
|
elif is-termux; then
|
|
|
|
alias o='termux-open'
|
|
|
|
alias pbcopy='termux-clipboard-set'
|
|
|
|
alias pbpaste='termux-clipboard-get'
|
2012-06-03 18:02:05 +00:00
|
|
|
else
|
|
|
|
alias o='xdg-open'
|
|
|
|
|
|
|
|
if (( $+commands[xclip] )); then
|
|
|
|
alias pbcopy='xclip -selection clipboard -in'
|
|
|
|
alias pbpaste='xclip -selection clipboard -out'
|
2013-08-20 12:47:18 +00:00
|
|
|
elif (( $+commands[xsel] )); then
|
2012-06-03 18:02:05 +00:00
|
|
|
alias pbcopy='xsel --clipboard --input'
|
|
|
|
alias pbpaste='xsel --clipboard --output'
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
alias pbc='pbcopy'
|
|
|
|
alias pbp='pbpaste'
|
|
|
|
|
2013-08-20 12:46:37 +00:00
|
|
|
# File Download
|
2021-05-12 05:48:41 +00:00
|
|
|
zstyle -s ':prezto:module:utility:download' helper '_download_helper' || _download_helper='curl'
|
|
|
|
|
|
|
|
typeset -A _download_helpers=(
|
|
|
|
aria2c 'aria2c --continue --remote-time --max-tries=0'
|
|
|
|
curl 'curl --continue-at - --location --progress-bar --remote-name --remote-time'
|
|
|
|
wget 'wget --continue --progress=bar --timestamping'
|
|
|
|
)
|
|
|
|
|
|
|
|
if (( $+commands[$_download_helper] && $+_download_helpers[$_download_helper] )); then
|
|
|
|
alias get="$_download_helpers[$_download_helper]"
|
|
|
|
elif (( $+commands[curl] )); then
|
|
|
|
alias get="$_download_helpers[curl]"
|
2013-08-20 12:46:37 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-12 05:48:41 +00:00
|
|
|
unset _download_helper{,s}
|
|
|
|
|
2012-06-10 23:35:15 +00:00
|
|
|
# Resource Usage
|
2018-02-21 22:10:11 +00:00
|
|
|
alias df='df -kh'
|
2012-06-10 23:35:15 +00:00
|
|
|
alias du='du -kh'
|
|
|
|
|
2020-02-13 08:56:29 +00:00
|
|
|
if is-darwin || is-bsd; then
|
2017-06-21 21:37:03 +00:00
|
|
|
alias topc='top -o cpu'
|
|
|
|
alias topm='top -o vsize'
|
2012-06-03 18:02:05 +00:00
|
|
|
else
|
2017-06-21 21:37:03 +00:00
|
|
|
alias topc='top -o %CPU'
|
|
|
|
alias topm='top -o %MEM'
|
2012-06-03 18:02:05 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Miscellaneous
|
|
|
|
|
2011-10-12 03:13:58 +00:00
|
|
|
# Serves a directory via HTTP.
|
2021-05-09 02:39:16 +00:00
|
|
|
if (( $#commands[(i)python(|[23])] )); then
|
|
|
|
autoload -Uz is-at-least
|
|
|
|
if is-at-least 3 ${"$(python --version 2>&1)"[(w)2]}; then
|
|
|
|
alias http-serve='python -m http.server'
|
|
|
|
elif (( $+commands[python3] )); then
|
|
|
|
alias http-serve='python3 -m http.server'
|
|
|
|
else
|
|
|
|
alias http-serve='$commands[(i)python(|2)] -m SimpleHTTPServer'
|
|
|
|
fi
|
2017-04-03 20:27:06 +00:00
|
|
|
fi
|
2009-08-31 22:00:38 +00:00
|
|
|
|
2012-08-04 18:48:32 +00:00
|
|
|
#
|
2012-06-03 18:02:05 +00:00
|
|
|
# Functions
|
2012-08-04 18:48:32 +00:00
|
|
|
#
|
2012-06-03 18:02:05 +00:00
|
|
|
|
2011-07-14 21:19:05 +00:00
|
|
|
# Makes a directory and changes to it.
|
2012-03-23 18:57:51 +00:00
|
|
|
function mkdcd {
|
2012-05-11 12:52:11 +00:00
|
|
|
[[ -n "$1" ]] && mkdir -p "$1" && builtin cd "$1"
|
2009-08-31 13:03:56 +00:00
|
|
|
}
|
2010-12-24 22:20:57 +00:00
|
|
|
|
2011-07-14 21:19:05 +00:00
|
|
|
# Changes to a directory and lists its contents.
|
2012-04-15 14:31:53 +00:00
|
|
|
function cdls {
|
|
|
|
builtin cd "$argv[-1]" && ls "${(@)argv[1,-2]}"
|
2011-05-30 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2011-07-14 21:19:05 +00:00
|
|
|
# Pushes an entry onto the directory stack and lists its contents.
|
2012-04-15 14:31:53 +00:00
|
|
|
function pushdls {
|
|
|
|
builtin pushd "$argv[-1]" && ls "${(@)argv[1,-2]}"
|
2011-05-30 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2011-07-14 21:19:05 +00:00
|
|
|
# Pops an entry off the directory stack and lists its contents.
|
2012-04-15 14:31:53 +00:00
|
|
|
function popdls {
|
|
|
|
builtin popd "$argv[-1]" && ls "${(@)argv[1,-2]}"
|
2011-05-30 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2011-07-14 21:19:05 +00:00
|
|
|
# Prints columns 1 2 3 ... n.
|
2012-03-23 18:57:51 +00:00
|
|
|
function slit {
|
2012-04-15 00:28:28 +00:00
|
|
|
awk "{ print ${(j:,:):-\$${^@}} }"
|
2011-07-14 21:19:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Finds files and executes a command on them.
|
2012-03-23 18:57:51 +00:00
|
|
|
function find-exec {
|
2011-07-14 21:19:05 +00:00
|
|
|
find . -type f -iname "*${1:-}*" -exec "${2:-file}" '{}' \;
|
2011-05-30 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2012-06-10 23:35:15 +00:00
|
|
|
# Displays user owned processes status.
|
|
|
|
function psu {
|
2015-02-13 05:00:27 +00:00
|
|
|
ps -U "${1:-$LOGNAME}" -o 'pid,%cpu,%mem,command' "${(@)argv[2,-1]}"
|
2012-06-10 23:35:15 +00:00
|
|
|
}
|
2017-07-17 05:15:45 +00:00
|
|
|
|
|
|
|
# Enables globbing selectively on path arguments.
|
|
|
|
# Globbing is enabled on local paths (starting in '/' and './') and disabled
|
|
|
|
# on remote paths (containing ':' but not starting in '/' and './'). This is
|
|
|
|
# useful for programs that have their own globbing for remote paths.
|
|
|
|
# Currently, this is used by default for 'rsync' and 'scp'.
|
|
|
|
# Example:
|
|
|
|
# - Local: '*.txt', './foo:2017*.txt', '/var/*:log.txt'
|
|
|
|
# - Remote: user@localhost:foo/
|
2017-12-18 21:35:19 +00:00
|
|
|
#
|
|
|
|
# NOTE: This function is buggy and is not used anywhere until we can make sure
|
|
|
|
# it's fixed. See https://github.com/sorin-ionescu/prezto/issues/1443 and
|
|
|
|
# https://github.com/sorin-ionescu/prezto/issues/1521 for more information.
|
2017-07-17 05:15:45 +00:00
|
|
|
function noremoteglob {
|
|
|
|
local -a argo
|
|
|
|
local cmd="$1"
|
|
|
|
for arg in ${argv:2}; do case $arg in
|
|
|
|
( ./* ) argo+=( ${~arg} ) ;; # local relative, glob
|
|
|
|
( /* ) argo+=( ${~arg} ) ;; # local absolute, glob
|
|
|
|
( *:* ) argo+=( ${arg} ) ;; # remote, noglob
|
|
|
|
( * ) argo+=( ${~arg} ) ;; # default, glob
|
|
|
|
esac; done
|
|
|
|
command $cmd "${(@)argo}"
|
|
|
|
}
|