abra zsh config 2.0

This commit is contained in:
Andrey Anurin
2018-08-12 15:26:21 +03:00
parent 201abd09c4
commit 6b114440e2
1195 changed files with 68948 additions and 10539 deletions

View File

@@ -14,19 +14,27 @@ commands.
To disable `ls` color, add the following line to *zpreztorc*; when coloring is
disabled, type indicators (\*, /, =>, @, =, |, %) will be appended to entries.
zstyle ':prezto:module:utility:ls' color 'no'
```sh
zstyle ':prezto:module:utility:ls' color 'no'
```
To disable `diff` highlighting, add the following line to *zpreztorc*:
zstyle ':prezto:module:utility:diff' color 'no'
```sh
zstyle ':prezto:module:utility:diff' color 'no'
```
To disable `wdiff` highlighting, add the following line to *zpreztorc*:
zstyle ':prezto:module:utility:wdiff' color 'no'
```sh
zstyle ':prezto:module:utility:wdiff' color 'no'
```
To disable `make` highlighting, add the following line to *zpreztorc*:
zstyle ':prezto:module:utility:make' color 'no'
```sh
zstyle ':prezto:module:utility:make' color 'no'
```
Aliases
-------
@@ -57,24 +65,22 @@ Aliases
- `history`
- `locate`
- `rake`
- `rsync`
- `scp`
- `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.
- `cp` copies files and directories interactively.
- `diffu` shorthand for `diff --unified`
- `e` opens the default editor.
- `ln` links files and directories interactively.
- `mkdir` creates directories, including intermediary directories.
- `mv` moves files and directories interactively.
- `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`).
- `rm` removes files and directories interactively.
- `sa` search aliases for a word.
- `type` displays all the attribute values of a shell parameter.
### Files and Directories
@@ -92,7 +98,7 @@ Aliases
- `lu` lists sorted by date, most recent last, shows access time.
- `sl` lists directory contents (`ls`).
### Mac OS X Everywhere
### macOS Everywhere
- `o` opens files and directories (`open` or `xdg-open`).
- `get` downloads files (`curl` or `wget`).
@@ -103,13 +109,26 @@ Aliases
### Resource Usage
- `df` displays free disk space using human readable units.
- `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 (aliased to `htop`, if installed).
- `topc` displays information about processes sorted by CPU usage (`htop` not
installed).
- `topm` displays information about processes sorted by RAM usage (`htop` not
installed).
- `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
*zpreztorc*:
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
@@ -130,10 +149,11 @@ Functions
- `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` or `Git`).
- `diff` highlights diff output (requires `colordiff`).
- `make` highlights make output (requires `colormake`).
- `wdiff` highlights wdiff output (requires `wdiff `or `Git`).

View File

@@ -0,0 +1,11 @@
#compdef noremoteglob
#autoload
#
# Completes noremoteglob.
#
# Authors:
# Indrajit Raychaudhuri <irc+code@indrajit.com>
#
_precommand

View File

@@ -6,16 +6,11 @@
#
function diff {
if zstyle -t ':prezto:module:utility:diff' color; then
if (( $+commands[colordiff] )); then
command diff --unified "$@" | colordiff --difftype diffu
elif (( $+commands[git] )); then
git --no-pager diff --color=auto --no-ext-diff --no-index "$@"
else
command diff --unified "$@"
fi
if zstyle -t ':prezto:module:utility:diff' color \
&& (( $+commands[colordiff] )); then
command colordiff "$@"
else
command diff --unified "$@"
command diff "$@"
fi
}

View File

@@ -5,6 +5,8 @@
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
# function prep {
local usage pattern modifiers invert
usage="$(
@@ -50,3 +52,5 @@ pattern="$1"
shift
perl -n -l -e "print if ${invert:+not} m/${pattern//\//\\/}/${modifiers}" "$@"
# }

View File

@@ -5,6 +5,8 @@
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
# function psub {
local usage pattern replacement modifiers
usage="$(
@@ -51,3 +53,5 @@ replacement="$2"
repeat 2 shift
perl -i'.orig' -n -l -e "s/${pattern//\//\\/}/${replacement//\//\\/}/${modifiers}; print" "$@"
# }

View File

@@ -17,7 +17,7 @@ function wdiff {
"$@" \
| sed 's/^\(@@\( [+-][[:digit:]]*,[[:digit:]]*\)\{2\} @@\)$/;5;6m\10m/g'
elif (( $+commands[git] )); then
git --no-pager diff --color=auto --no-ext-diff --no-index --color-words "$@"
command git --no-pager diff --color=auto --no-ext-diff --no-index --color-words "$@"
else
command wdiff "$@"
fi

View File

@@ -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 $?
#}

View File

@@ -41,30 +41,48 @@ alias ftp='noglob ftp'
alias history='noglob history'
alias locate='noglob locate'
alias rake='noglob rake'
# alias rsync='noglob rsync'
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 rmi="${aliases[rm]:-rm} -i"
alias mvi="${aliases[mv]:-mv} -i"
alias cpi="${aliases[cp]:-cp} -i"
alias lni="${aliases[ln]:-ln} -i"
if zstyle -T ':prezto:module:utility' safe-ops; then
alias rm='rmi'
alias mv='mvi'
alias cp='cpi'
alias ln='lni'
fi
# 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 --sh "$HOME/.dir_colors")"
else
eval "$(dircolors --sh)"
# Call dircolors to define colors if they're missing
if [[ -z "$LS_COLORS" ]]; then
if [[ -s "$HOME/.dir_colors" ]]; then
eval "$(dircolors --sh "$HOME/.dir_colors")"
else
eval "$(dircolors --sh)"
fi
fi
alias ls="${aliases[ls]:-ls} --color=auto"
@@ -74,11 +92,15 @@ if is-callable 'dircolors'; then
else
# BSD Core Utilities
if zstyle -t ':prezto:module:utility:ls' color; then
# Define colors for BSD ls.
export LSCOLORS='exfxcxdxbxGxDxabagacad'
# Define colors for BSD ls if they're not already defined
if [[ -z "$LSCOLORS" ]]; then
export LSCOLORS='exfxcxdxbxGxDxabagacad'
fi
# 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:'
# Define colors for the completion system if they're not already defined
if [[ -z "$LS_COLORS" ]]; then
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
alias ls="${aliases[ls]:-ls} -G"
else
@@ -86,10 +108,7 @@ else
fi
fi
# printf "${aliases[ls]:-ls}"
# alias lss="${aliases[ls]:-ls}"
# alias ls="${aliases[ls]:-ls} -A"
alias l='ls -lAh' # Lists in one column, hidden files.
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.
@@ -109,7 +128,7 @@ if zstyle -t ':prezto:module:utility:grep' color; then
alias grep="${aliases[grep]:-grep} --color=auto"
fi
# Mac OS X Everywhere
# macOS Everywhere
if [[ "$OSTYPE" == darwin* ]]; then
alias o='open'
elif [[ "$OSTYPE" == cygwin* ]]; then
@@ -142,22 +161,22 @@ fi
alias df='df -kh'
alias du='du -kh'
if (( $+commands[htop] )); then
alias top=htop
if [[ "$OSTYPE" == (darwin*|*bsd*) ]]; then
alias topc='top -o cpu'
alias topm='top -o vsize'
else
if [[ "$OSTYPE" == (darwin*|*bsd*) ]]; then
alias topc='top -o cpu'
alias topm='top -o vsize'
else
alias topc='top -o %CPU'
alias topm='top -o %MEM'
fi
alias topc='top -o %CPU'
alias topm='top -o %MEM'
fi
# Miscellaneous
# Serves a directory via HTTP.
alias http-serve='python -m SimpleHTTPServer'
if (( $+commands[python3] )); then
alias http-serve='python3 -m http.server'
else
alias http-serve='python -m SimpleHTTPServer'
fi
#
# Functions
@@ -197,3 +216,27 @@ function find-exec {
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}"
}