feat(revamp): add zsh and neovim configs, add an install script and a dependencies list
This commit is contained in:
@@ -0,0 +1,224 @@
|
||||
# Utility
|
||||
|
||||
Defines general aliases and functions.
|
||||
|
||||
This module must be loaded _before_ the [_`completion`_][1] module so that the
|
||||
provided completion definitions are loaded automatically by _`completion`_
|
||||
module.
|
||||
|
||||
**Note:** Some of the utilities configured in this module might be provided via
|
||||
GNU utilities with incompatible arguments on non-GNU systems. In such cases,
|
||||
using [_`gnu-utility`_][2] module is recommended and it must be loaded
|
||||
_before_ this module.
|
||||
|
||||
To elaborate, the relative order of loading the modules would be
|
||||
_`gnu-utility`_, _`utility`_ and _`completion`_.
|
||||
|
||||
## Settings
|
||||
|
||||
### Highlighting
|
||||
|
||||
If you have enabled color globally in _`${ZDOTDIR:-$HOME}/.zpreztorc`_, you may
|
||||
disable it selectively for certain commands.
|
||||
|
||||
To disable `ls` color, add the following to _`${ZDOTDIR:-$HOME}/.zpreztorc`_.
|
||||
When coloring is disabled, type indicators (`\*`, `/`, `=>`, `@`, `=`, `|`, `%`)
|
||||
will be appended to entries.
|
||||
|
||||
```sh
|
||||
zstyle ':prezto:module:utility:ls' color 'no'
|
||||
```
|
||||
|
||||
To disable GNU coreutils `ls` to list directories grouped first, add the
|
||||
following line to _`${ZDOTDIR:-$HOME}/.zpreztorc`_:
|
||||
|
||||
```sh
|
||||
zstyle ':prezto:module:utility:ls' dirs-first 'no'
|
||||
```
|
||||
|
||||
To disable `grep` highlighting, add the following line to
|
||||
_`${ZDOTDIR:-$HOME}/.zpreztorc`_:
|
||||
|
||||
```sh
|
||||
zstyle ':prezto:module:utility:grep' color 'no'
|
||||
```
|
||||
|
||||
To disable `diff` highlighting, add the following line to
|
||||
_`${ZDOTDIR:-$HOME}/.zpreztorc`_:
|
||||
|
||||
```sh
|
||||
zstyle ':prezto:module:utility:diff' color 'no'
|
||||
```
|
||||
|
||||
To disable `wdiff` highlighting, add the following line to
|
||||
_`${ZDOTDIR:-$HOME}/.zpreztorc`_:
|
||||
|
||||
```sh
|
||||
zstyle ':prezto:module:utility:wdiff' color 'no'
|
||||
```
|
||||
|
||||
To disable `make` highlighting, add the following line to
|
||||
_`${ZDOTDIR:-$HOME}/.zpreztorc`_:
|
||||
|
||||
```sh
|
||||
zstyle ':prezto:module:utility:make' color 'no'
|
||||
```
|
||||
|
||||
### Download Helper
|
||||
|
||||
To configure the download helper to be used with alias `get`, add the following
|
||||
to _`${ZDOTDIR:-$HOME}/.zpreztorc`_, and replace `'<helper>'` with `'curl'`,
|
||||
`'wget'` or `'aria2c'`.
|
||||
|
||||
```sh
|
||||
zstyle -s ':prezto:module:utility:download' helper '<helper>'
|
||||
```
|
||||
|
||||
## Aliases
|
||||
|
||||
### Disabled Spelling Correction
|
||||
|
||||
- `ack`
|
||||
- `cd`
|
||||
- `cp`
|
||||
- `ebuild`
|
||||
- `gcc`
|
||||
- `gist`
|
||||
- `grep`
|
||||
- `heroku`
|
||||
- `ln`
|
||||
- `man`
|
||||
- `mkdir`
|
||||
- `mv`
|
||||
- `mysql`
|
||||
- `rm`
|
||||
|
||||
To disable all spelling corrections, add the following line to
|
||||
_`${ZDOTDIR:-$HOME}/.zpreztorc`_:
|
||||
|
||||
```sh
|
||||
zstyle ':prezto:module:utility' correct 'no'
|
||||
```
|
||||
|
||||
### Disabled File Globbing
|
||||
|
||||
- `bower`
|
||||
- `fc`
|
||||
- `find`
|
||||
- `ftp`
|
||||
- `history`
|
||||
- `locate`
|
||||
- `rake`
|
||||
- `rsync` (selectively enabled for local files)
|
||||
- `scp` (selectively enabled for local files)
|
||||
- `sftp`
|
||||
|
||||
### General
|
||||
|
||||
- `_` executes a command as another user (`sudo`).
|
||||
- `b` opens the default web browser.
|
||||
- `diffu` shorthand for `diff --unified`.
|
||||
- `e` opens the default editor.
|
||||
- `mkdir` creates directories, including intermediary directories.
|
||||
- `p` opens the default pager.
|
||||
- `po` removes a directory from the stack and changes to it (`popd`).
|
||||
- `pu` changes the directory and pushes the old directory onto the stack
|
||||
(`pushd`).
|
||||
- `sa` search aliases for a word.
|
||||
- `type` displays all the attribute values of a shell parameter.
|
||||
|
||||
### Files and Directories
|
||||
|
||||
- `ls` lists with directories grouped first (GNU only).
|
||||
- `l` lists in one column, hidden files.
|
||||
- `ll` lists human readable sizes.
|
||||
- `lr` lists human readable sizes, recursively.
|
||||
- `la` lists human readable sizes, hidden files.
|
||||
- `lm` lists human readable sizes, hidden files through pager.
|
||||
- `lx` lists sorted by extension (GNU only).
|
||||
- `lk` lists sorted by size, largest last.
|
||||
- `lt` lists sorted by date, most recent last.
|
||||
- `lc` lists sorted by date, most recent last, shows change time.
|
||||
- `lu` lists sorted by date, most recent last, shows access time.
|
||||
|
||||
### macOS Everywhere
|
||||
|
||||
- `o` opens files and directories (`open` or `xdg-open`).
|
||||
- `get` downloads files (`curl`, `wget` or `aria2c`).
|
||||
- `pbcopy` copies to the pasteboard (`pbcopy`, `xclip` or `xsel`).
|
||||
- `pbpaste` pastes from the pasteboard (`pbcopy`, `xclip` or `xsel`).
|
||||
- `pbc` copies to the pasteboard (`pbcopy`).
|
||||
- `pbp` pastes from the pasteboard (`pbpaste`).
|
||||
|
||||
### Resource Usage
|
||||
|
||||
- `df` displays free disk space using human readable units (aliases to `pydf`,
|
||||
if installed).
|
||||
- `du` displays disk usage using human readable units.
|
||||
- `top` displays information about processes.
|
||||
- `topc` displays information about processes sorted by CPU usage.
|
||||
- `topm` displays information about processes sorted by RAM usage.
|
||||
|
||||
### Safe ops
|
||||
|
||||
By default, `cp`,`ln`, `mv` and `rm` are aliased to their interactive variants.
|
||||
If this is not desired, it can be disabled by adding the following line to
|
||||
_`${ZDOTDIR:-$HOME}/.zpreztorc`_:
|
||||
|
||||
```sh
|
||||
zstyle ':prezto:module:utility' safe-ops 'no'.
|
||||
```
|
||||
|
||||
In addition, the following aliases have been added:
|
||||
|
||||
- `cpi` copies files and directories interactively.
|
||||
- `lni` links files and directories interactively.
|
||||
- `mvi` moves files and directories interactively.
|
||||
- `rmi` removes files and directories interactively.
|
||||
|
||||
### Miscellaneous
|
||||
|
||||
- `http-serve` serves a directory via HTTP.
|
||||
|
||||
## Functions
|
||||
|
||||
### General
|
||||
|
||||
- `slit` prints columns _1, 2, 3 ... n_.
|
||||
|
||||
### Files and Directories
|
||||
|
||||
- `cdls` changes to a directory and lists its contents.
|
||||
- `dut` displays the grand total disk usage using human readable units.
|
||||
- `find-exec` finds files and executes a command on them.
|
||||
- `mkdcd` makes a directory and changes to it.
|
||||
- `popdls` pops an entry off the directory stack and lists its contents.
|
||||
- `pushdls` pushes an entry onto the directory stack and lists its contents.
|
||||
- `noremoteglob` enable local path globbing but disable remote path globbing.
|
||||
|
||||
### Developer
|
||||
|
||||
- `diff` highlights diff output (requires `colordiff`).
|
||||
- `make` highlights make output (requires `colormake`).
|
||||
- `wdiff` highlights wdiff output (requires `wdiff` or `git`).
|
||||
|
||||
### Resource usage
|
||||
|
||||
- `psu` displays user owned processes status.
|
||||
|
||||
### Search and Replace
|
||||
|
||||
- `prep` provides a grep-like pattern search.
|
||||
- `psub` provides a sed-like pattern substitution.
|
||||
|
||||
## Authors
|
||||
|
||||
_The authors of this module should be contacted via the [issue tracker][3]._
|
||||
|
||||
- [Robby Russell](https://github.com/robbyrussell)
|
||||
- [Suraj N. Kurapati](https://github.com/sunaku)
|
||||
- [Sorin Ionescu](https://github.com/sorin-ionescu)
|
||||
|
||||
[1]: ../completion#readme
|
||||
[2]: ../gnu-utility#readme
|
||||
[3]: https://github.com/sorin-ionescu/prezto/issues
|
||||
@@ -0,0 +1,11 @@
|
||||
#compdef cdls popdls pushdls
|
||||
#autoload
|
||||
|
||||
#
|
||||
# Completes cdls, popdls, and pushdls.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
_cd
|
||||
@@ -0,0 +1,11 @@
|
||||
#compdef dut
|
||||
#autoload
|
||||
|
||||
#
|
||||
# Completes dut.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
_du
|
||||
@@ -0,0 +1,13 @@
|
||||
#compdef mkdcd
|
||||
#autoload
|
||||
|
||||
#
|
||||
# Completes mkdcd.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
local expl
|
||||
|
||||
_wanted directories expl 'directory' _path_files -/ || _message 'directory'
|
||||
@@ -0,0 +1,11 @@
|
||||
#compdef noremoteglob
|
||||
#autoload
|
||||
|
||||
#
|
||||
# Completes noremoteglob.
|
||||
#
|
||||
# Authors:
|
||||
# Indrajit Raychaudhuri <irc+code@indrajit.com>
|
||||
#
|
||||
|
||||
_precommand
|
||||
@@ -0,0 +1,18 @@
|
||||
#compdef prep
|
||||
#autoload
|
||||
|
||||
#
|
||||
# Completes prep.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
_arguments \
|
||||
'-i[ignore case]' \
|
||||
'-m[^ and $ match the start and the end of a line]' \
|
||||
'-s[. matches newline]' \
|
||||
'-v[invert match]' \
|
||||
'-x[ignore whitespace and comments]' \
|
||||
'1::pattern:' \
|
||||
'2::files:_files' && return 0
|
||||
@@ -0,0 +1,19 @@
|
||||
#compdef psub
|
||||
#autoload
|
||||
|
||||
#
|
||||
# Completes psub.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
_arguments \
|
||||
'-g[match globally]' \
|
||||
'-i[ignore case]' \
|
||||
'-m[^ and $ match the start and the end of a line]' \
|
||||
'-s[. matches newline]' \
|
||||
'-x[ignore whitespace and comments]' \
|
||||
'1::pattern:' \
|
||||
'2::replacement:' \
|
||||
'3::files:_files' && return 0
|
||||
@@ -0,0 +1,19 @@
|
||||
#
|
||||
# Highlights diff output.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
# function diff {
|
||||
|
||||
if zstyle -t ':prezto:module:utility:diff' color \
|
||||
&& [[ -t 1 ]] \
|
||||
&& (( $+commands[colordiff] )); then
|
||||
command diff "$@" | colordiff
|
||||
return "${pipestatus[1]}"
|
||||
else
|
||||
command diff "$@"
|
||||
fi
|
||||
|
||||
# }
|
||||
@@ -0,0 +1,27 @@
|
||||
#
|
||||
# Displays the grand total disk usage using human readable units.
|
||||
#
|
||||
# Authors:
|
||||
# Suraj N. Kurapati <sunaku@gmail.com>
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
# function dut {
|
||||
|
||||
(( $# == 0 )) && set -- *
|
||||
|
||||
if [[ ${(@M)${(f)"$(du --version 2>&1)"}:#*GNU *} ]]; then
|
||||
du -khsc "$@" | sort -h -r
|
||||
else
|
||||
local line size name
|
||||
local -a record
|
||||
|
||||
while IFS=$'\n' read line; do
|
||||
record=(${(z)line})
|
||||
size="$(($record[1] / 1024.0))"
|
||||
name="$record[2,-1]"
|
||||
printf "%9.1LfM %s\n" "$size" "$name"
|
||||
done < <(du -kcs "$@") | sort -n -r
|
||||
fi
|
||||
|
||||
# }
|
||||
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# Highlights make output.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
# function make {
|
||||
|
||||
if zstyle -t ':prezto:module:utility:make' color \
|
||||
&& (( $+commands[colormake] )); then
|
||||
command colormake "$@"
|
||||
else
|
||||
command make "$@"
|
||||
fi
|
||||
|
||||
# }
|
||||
@@ -0,0 +1,56 @@
|
||||
#
|
||||
# Provides a grep-like pattern search.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
# function prep {
|
||||
|
||||
local usage pattern modifiers invert
|
||||
|
||||
usage="$(
|
||||
cat <<EOF
|
||||
usage: $0 [-option ...] [--] pattern [file ...]
|
||||
|
||||
options:
|
||||
-i ignore case
|
||||
-m ^ and $ match the start and the end of a line
|
||||
-s . matches newline
|
||||
-v invert match
|
||||
-x ignore whitespace and comments
|
||||
EOF
|
||||
)"
|
||||
|
||||
while getopts ':imsxv' opt; do
|
||||
case "$opt" in
|
||||
(i) modifiers="${modifiers}i" ;;
|
||||
(m) modifiers="${modifiers}m" ;;
|
||||
(s) modifiers="${modifiers}s" ;;
|
||||
(x) modifiers="${modifiers}x" ;;
|
||||
(v) invert="yes" ;;
|
||||
(:)
|
||||
print "$0: option requires an argument: $OPTARG" >&2
|
||||
print "$usage" >&2
|
||||
return 1
|
||||
;;
|
||||
([?])
|
||||
print "$0: unknown option: $OPTARG" >&2
|
||||
print "$usage" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $(( $OPTIND - 1 ))
|
||||
|
||||
if (( $# < 1 )); then
|
||||
print "$usage" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
pattern="$1"
|
||||
shift
|
||||
|
||||
perl -n -l -e "print if ${invert:+not} m/${pattern//\//\\/}/${modifiers}" "$@"
|
||||
|
||||
# }
|
||||
@@ -0,0 +1,57 @@
|
||||
#
|
||||
# Provides a sed-like pattern substitution.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
# function psub {
|
||||
|
||||
local usage pattern replacement modifiers
|
||||
|
||||
usage="$(
|
||||
cat <<EOF
|
||||
usage: $0 [-option ...] [--] pattern replacement [file ...]
|
||||
|
||||
options:
|
||||
-g match globally
|
||||
-i ignore case
|
||||
-m ^ and $ match the start and the end of a line
|
||||
-s . matches newline
|
||||
-x ignore whitespace and comments
|
||||
EOF
|
||||
)"
|
||||
|
||||
while getopts ':gimsx' opt; do
|
||||
case "$opt" in
|
||||
(g) modifiers="${modifiers}g" ;;
|
||||
(i) modifiers="${modifiers}i" ;;
|
||||
(m) modifiers="${modifiers}m" ;;
|
||||
(s) modifiers="${sodifiers}s" ;;
|
||||
(x) modifiers="${modifiers}x" ;;
|
||||
(:)
|
||||
print "$0: option requires an argument: $OPTARG" >&2
|
||||
print "$usage" >&2
|
||||
return 1
|
||||
;;
|
||||
([?])
|
||||
print "$0: unknown option: $OPTARG" >&2
|
||||
print "$usage" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $(( $OPTIND - 1 ))
|
||||
|
||||
if (( $# < 2 )); then
|
||||
print "$usage" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
pattern="$1"
|
||||
replacement="$2"
|
||||
repeat 2 shift
|
||||
|
||||
perl -i'.orig' -n -l -e "s/${pattern//\//\\/}/${replacement//\//\\/}/${modifiers}; print" "$@"
|
||||
|
||||
# }
|
||||
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# Highlights wdiff output.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
# Indrajit Raychaudhuri <irc@indrajit.com>
|
||||
#
|
||||
|
||||
# function wdiff {
|
||||
|
||||
if zstyle -t ':prezto:module:utility:wdiff' color; then
|
||||
if (( $+commands[wdiff] )); then
|
||||
command wdiff \
|
||||
--avoid-wraps \
|
||||
--start-delete="$(print -n $FG[red])" \
|
||||
--end-delete="$(print -n $FG[none])" \
|
||||
--start-insert="$(print -n $FG[green])" \
|
||||
--end-insert="$(print -n $FG[none])" \
|
||||
"$@" \
|
||||
| sed 's/^\(@@\( [+-][[:digit:]]*,[[:digit:]]*\)\{2\} @@\)$/;5;6m\10m/g'
|
||||
elif (( $+commands[git] )); then
|
||||
command git --no-pager diff --no-ext-diff --no-index --color=auto --color-words "$@"
|
||||
else
|
||||
command wdiff "$@"
|
||||
fi
|
||||
elif (( ! $+commands[wdiff] && $+commands[git] )); then
|
||||
command git --no-pager diff --no-ext-diff --no-index --color=never "$@"
|
||||
else
|
||||
command wdiff "$@"
|
||||
fi
|
||||
|
||||
# }
|
||||
@@ -0,0 +1,102 @@
|
||||
#
|
||||
# Provides a much easier way to search and access ZSH's manual. First checks for
|
||||
# terms at the start of the manual, then checks if it's at start of a line allowing
|
||||
# whitespace.
|
||||
#
|
||||
# Authors:
|
||||
# Samantha McVey <samantham@posteo.net>
|
||||
#
|
||||
|
||||
# function zsh-help {
|
||||
|
||||
local usage="$(
|
||||
cat <<EOF
|
||||
usage: $0 [--help] [--zsh-help-debug] [--all] search term(s)
|
||||
Options:
|
||||
--all - search for the term anywhere, not just at the start of a line.
|
||||
--help - show this help message
|
||||
--zsh-help-debug - print out the regex search choosenq instead of searching
|
||||
Looks up things in the zsh documentation. --all must come after --zsh-help-debug
|
||||
if used together.
|
||||
Uses less as the pager. Press 'n' to search forward 'N' to search backwards.
|
||||
Case is ignored unless capital letters appear in the search term.
|
||||
EOF
|
||||
)"
|
||||
#function zsh-help {
|
||||
function _zsh-help-join { # Joins the arguments into a string delimited by $separator
|
||||
local separator=$1;
|
||||
local arr=$*;
|
||||
arr=${arr:${#separator}+1}; # < Line needed so result doesn't start with
|
||||
arr=${arr// /$separator}; # a separator.
|
||||
<<<$arr
|
||||
}
|
||||
local case='-i'; local section='ZSHALL'; local debug=''; local pattern=''
|
||||
function _zsh-help-try-query {
|
||||
local case="$1"; local pattern="$2"; local i=''
|
||||
local array=( ZSHBUILTINS ZSHALL ZSHMODULES )
|
||||
for i in ${array}; do
|
||||
if [[ ${debug} ]]; then printf "Looking in %s for: %s %s\n" "${i}" "${case}" "${pattern}" 1>&2; fi
|
||||
if man --pager='' ${i} | grep -E ${case} "${pattern}" > /dev/null; then
|
||||
printf "%s" "${i}"; return 0;
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
# By default search only things at start of line
|
||||
local first_prefix='^'
|
||||
local prefix='^\s*'
|
||||
if [[ ${1} == '--zsh-help-debug' ]]; then
|
||||
shift; debug=1
|
||||
fi
|
||||
if [[ ${1} == "--all" ]]; then
|
||||
shift; first_prefix='' # We're searching everything, so remove the prefix
|
||||
fi
|
||||
if [[ $# < 1 || $1 == "--help" ]]; then
|
||||
printf "%s\n" "${usage}"
|
||||
unfunction _zsh-help-join; unfunction _zsh-help-try-query; # unfunction so it's not in the global scope
|
||||
return 1
|
||||
fi
|
||||
if [[ ${1} == "test" && $# == 1 ]]; then
|
||||
case=''
|
||||
pattern='^CONDITIONAL EXPRESSIONS$'
|
||||
elif [[ ($1 == "-eq" || $1 == "-ne" || $1 == "-lt" || $1 == "-gt" || $1 == "-le" || $1 == "-ge") && $# == 1 ]]; then
|
||||
case=''
|
||||
pattern="${prefix}exp1\s+${1}\s+exp2"
|
||||
elif [[ $1 == 'zstyle' ]]; then
|
||||
pattern=$(_zsh-help-join '\s+' "$@")
|
||||
section=ZSHMODULES
|
||||
fi
|
||||
# If it wasn't one of the special-cased things, check ZSHBUILTINS first. If
|
||||
# not found there, we will search ZSHALL
|
||||
if [[ ${pattern} == "" ]]; then
|
||||
pattern="$(_zsh-help-join '\s+' "$@")"
|
||||
# search for sections at the start of the man page first
|
||||
section=$(_zsh-help-try-query "${case}" "${first_prefix}${pattern}")
|
||||
# If it exists there, keep ZSHBUILTINS as the section
|
||||
if (( $? == 0 )); then
|
||||
pattern="${first_prefix}${pattern}"
|
||||
elif [[ "${prefix}" ]]; then
|
||||
# if not found, search for the term preceeded by whitetext
|
||||
section=$(_zsh-help-try-query "${case}" "${prefix}${pattern}")
|
||||
if (( $? == 0 )); then
|
||||
pattern="${prefix}${pattern}"
|
||||
else
|
||||
pattern=""
|
||||
fi
|
||||
fi
|
||||
if [[ ! ${pattern} ]]; then # Otherwise we use zshall
|
||||
printf "Can't find term\n" 2>&1
|
||||
unfunction _zsh-help-join; unfunction _zsh-help-try-query; # unfunction so it's not in the global scope
|
||||
return 1;
|
||||
fi
|
||||
fi
|
||||
local command="man --pager=\"less ${case} -p '${pattern}'\" \"${section}\""
|
||||
if [[ ${debug} ]]; then
|
||||
printf "\nFinal search term is:\n"; printf "%s\n" "${command}";
|
||||
else
|
||||
eval $command
|
||||
fi
|
||||
local rtrn=$?
|
||||
unfunction _zsh-help-join; unfunction _zsh-help-try-query; # unfunction so it's not in the global scope
|
||||
return $?
|
||||
#}
|
||||
@@ -0,0 +1,274 @@
|
||||
#
|
||||
# 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.
|
||||
if zstyle -T ':prezto:module:utility' correct; then
|
||||
setopt CORRECT
|
||||
fi
|
||||
|
||||
# Load 'run-help' function.
|
||||
autoload -Uz run-help-{ip,openssl,sudo}
|
||||
|
||||
#
|
||||
# Aliases
|
||||
#
|
||||
|
||||
# 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 bower='noglob bower'
|
||||
alias fc='noglob fc'
|
||||
alias find='noglob find'
|
||||
alias ftp='noglob ftp'
|
||||
alias history='noglob history'
|
||||
alias locate='noglob locate'
|
||||
alias rake='noglob rake'
|
||||
alias rsync='noglob rsync'
|
||||
alias scp='noglob scp'
|
||||
alias sftp='noglob sftp'
|
||||
|
||||
# Define general aliases.
|
||||
alias _='sudo'
|
||||
alias b='${(z)BROWSER}'
|
||||
|
||||
alias diffu="diff --unified"
|
||||
alias e='${(z)VISUAL:-${(z)EDITOR}}'
|
||||
alias mkdir="${aliases[mkdir]:-mkdir} -p"
|
||||
alias p='${(z)PAGER}'
|
||||
alias po='popd'
|
||||
alias pu='pushd'
|
||||
alias sa='alias | grep -i'
|
||||
alias type='type -a'
|
||||
|
||||
# Safe ops. Ask the user before doing anything destructive.
|
||||
alias cpi="${aliases[cp]:-cp} -i"
|
||||
alias lni="${aliases[ln]:-ln} -i"
|
||||
alias mvi="${aliases[mv]:-mv} -i"
|
||||
alias rmi="${aliases[rm]:-rm} -i"
|
||||
if zstyle -T ':prezto:module:utility' safe-ops; then
|
||||
alias cp="${aliases[cp]:-cp} -i"
|
||||
alias ln="${aliases[ln]:-ln} -i"
|
||||
alias mv="${aliases[mv]:-mv} -i"
|
||||
alias rm="${aliases[rm]:-rm} -i"
|
||||
fi
|
||||
|
||||
# ls
|
||||
_ls_version="$(ls --version 2>&1)"
|
||||
|
||||
if [[ ${(@M)${(f)_ls_version}:#*(GNU|lsd|uutils) *} ]]; then
|
||||
# GNU Core Utilities
|
||||
|
||||
if zstyle -T ':prezto:module:utility:ls' dirs-first; then
|
||||
alias ls="${aliases[ls]:-ls} --group-directories-first"
|
||||
fi
|
||||
|
||||
if zstyle -t ':prezto:module:utility:ls' color; then
|
||||
# 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))"
|
||||
else
|
||||
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:'
|
||||
fi
|
||||
fi
|
||||
|
||||
alias ls="${aliases[ls]:-ls} --color=auto"
|
||||
else
|
||||
alias ls="${aliases[ls]:-ls} -F"
|
||||
fi
|
||||
else
|
||||
# BSD Core Utilities
|
||||
|
||||
if zstyle -t ':prezto:module:utility:ls' color; then
|
||||
# Define colors for BSD ls if they're not already defined
|
||||
if (( ! $+LSCOLORS )); then
|
||||
export LSCOLORS='exfxcxdxbxGxDxabagacad'
|
||||
fi
|
||||
|
||||
alias ls="${aliases[ls]:-ls} -G"
|
||||
else
|
||||
alias ls="${aliases[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 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.
|
||||
|
||||
if [[ ${(@M)${(f)_ls_version}:#*GNU *} ]]; then
|
||||
alias lx='ll -XB' # Lists sorted by extension (GNU only).
|
||||
fi
|
||||
|
||||
unset _ls_version
|
||||
|
||||
# Grep
|
||||
if zstyle -t ':prezto:module:utility:grep' color; then
|
||||
export GREP_COLOR=${GREP_COLOR:-'37;45'} # BSD.
|
||||
export GREP_COLORS=${GREP_COLORS:-"mt=$GREP_COLOR"} # GNU.
|
||||
|
||||
alias grep="${aliases[grep]:-grep} --color=auto"
|
||||
fi
|
||||
|
||||
# macOS Everywhere
|
||||
if is-darwin; then
|
||||
alias o='open'
|
||||
elif is-cygwin; then
|
||||
alias o='cygstart'
|
||||
alias pbcopy='tee > /dev/clipboard'
|
||||
alias pbpaste='cat /dev/clipboard'
|
||||
elif is-termux; then
|
||||
alias o='termux-open'
|
||||
alias pbcopy='termux-clipboard-set'
|
||||
alias pbpaste='termux-clipboard-get'
|
||||
else
|
||||
alias o='xdg-open'
|
||||
|
||||
if (( $+commands[xclip] )); then
|
||||
alias pbcopy='xclip -selection clipboard -in'
|
||||
alias pbpaste='xclip -selection clipboard -out'
|
||||
elif (( $+commands[xsel] )); then
|
||||
alias pbcopy='xsel --clipboard --input'
|
||||
alias pbpaste='xsel --clipboard --output'
|
||||
fi
|
||||
fi
|
||||
|
||||
alias pbc='pbcopy'
|
||||
alias pbp='pbpaste'
|
||||
|
||||
# File Download
|
||||
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]"
|
||||
fi
|
||||
|
||||
unset _download_helper{,s}
|
||||
|
||||
# Resource Usage
|
||||
alias df='df -kh'
|
||||
alias du='du -kh'
|
||||
|
||||
if is-darwin || is-bsd; then
|
||||
alias topc='top -o cpu'
|
||||
alias topm='top -o vsize'
|
||||
else
|
||||
alias topc='top -o %CPU'
|
||||
alias topm='top -o %MEM'
|
||||
fi
|
||||
|
||||
# Miscellaneous
|
||||
|
||||
# Serves a directory via HTTP.
|
||||
if (( $#commands[(i)python(|[23])] )); then
|
||||
autoload -Uz is-at-least
|
||||
if (( $+commands[python3] )); then
|
||||
alias http-serve='python3 -m http.server'
|
||||
elif (( $+commands[python2] )); then
|
||||
alias http-serve='python2 -m SimpleHTTPServer'
|
||||
elif is-at-least 3 ${"$(python --version 2>&1)"[(w)2]}; then
|
||||
alias http-serve='python -m http.server'
|
||||
else
|
||||
alias http-serve='python -m SimpleHTTPServer'
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
# 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:-$LOGNAME}" -o 'pid,%cpu,%mem,command' "${(@)argv[2,-1]}"
|
||||
}
|
||||
|
||||
# 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/
|
||||
#
|
||||
# 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.
|
||||
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}"
|
||||
}
|
||||
Reference in New Issue
Block a user