mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-25 01:47:25 +08:00
Compare commits
No commits in common. "72707d92b1f127a2c16f0447e4d8233ed7b3c10e" and "9ce7de9f16ba894423bc5105c7e959894ca2e751" have entirely different histories.
72707d92b1
...
9ce7de9f16
24
lib/grep.zsh
24
lib/grep.zsh
@ -2,9 +2,7 @@ __GREP_CACHE_FILE="$ZSH_CACHE_DIR"/grep-alias
|
|||||||
|
|
||||||
# See if there's a cache file modified in the last day
|
# See if there's a cache file modified in the last day
|
||||||
__GREP_ALIAS_CACHES=("$__GREP_CACHE_FILE"(Nm-1))
|
__GREP_ALIAS_CACHES=("$__GREP_CACHE_FILE"(Nm-1))
|
||||||
if [[ -n "$__GREP_ALIAS_CACHES" ]]; then
|
if [[ -z "$__GREP_ALIAS_CACHES" ]]; then
|
||||||
source "$__GREP_CACHE_FILE"
|
|
||||||
else
|
|
||||||
grep-flags-available() {
|
grep-flags-available() {
|
||||||
command grep "$@" "" &>/dev/null <<< ""
|
command grep "$@" "" &>/dev/null <<< ""
|
||||||
}
|
}
|
||||||
@ -14,28 +12,26 @@ else
|
|||||||
|
|
||||||
# Check for --exclude-dir, otherwise check for --exclude. If --exclude
|
# Check for --exclude-dir, otherwise check for --exclude. If --exclude
|
||||||
# isn't available, --color won't be either (they were released at the same
|
# isn't available, --color won't be either (they were released at the same
|
||||||
# time (v2.5): https://git.savannah.gnu.org/cgit/grep.git/tree/NEWS?id=1236f007
|
# time (v2.5): http://git.savannah.gnu.org/cgit/grep.git/tree/NEWS?id=1236f007
|
||||||
if grep-flags-available --color=auto --exclude-dir=.cvs; then
|
if grep-flags-available --color=auto --exclude-dir=.cvs; then
|
||||||
GREP_OPTIONS="--color=auto --exclude-dir=$EXC_FOLDERS"
|
GREP_OPTIONS="--color=auto --exclude-dir=$EXC_FOLDERS"
|
||||||
elif grep-flags-available --color=auto --exclude=.cvs; then
|
elif grep-flags-available --color=auto --exclude=.cvs; then
|
||||||
GREP_OPTIONS="--color=auto --exclude=$EXC_FOLDERS"
|
GREP_OPTIONS="--color=auto --exclude=$EXC_FOLDERS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "$GREP_OPTIONS" ]]; then
|
{
|
||||||
# export grep, egrep and fgrep settings
|
if [[ -n "$GREP_OPTIONS" ]]; then
|
||||||
alias grep="grep $GREP_OPTIONS"
|
# export grep, egrep and fgrep settings
|
||||||
alias egrep="egrep $GREP_OPTIONS"
|
echo "alias grep='grep $GREP_OPTIONS'"
|
||||||
alias fgrep="fgrep $GREP_OPTIONS"
|
echo "alias egrep='egrep $GREP_OPTIONS'"
|
||||||
|
echo "alias fgrep='fgrep $GREP_OPTIONS'"
|
||||||
# write to cache file if cache directory is writable
|
|
||||||
if [[ -w "$ZSH_CACHE_DIR" ]]; then
|
|
||||||
alias -L grep egrep fgrep >| "$__GREP_CACHE_FILE"
|
|
||||||
fi
|
fi
|
||||||
fi
|
} > "$__GREP_CACHE_FILE"
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
unset GREP_OPTIONS EXC_FOLDERS
|
unset GREP_OPTIONS EXC_FOLDERS
|
||||||
unfunction grep-flags-available
|
unfunction grep-flags-available
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
source "$__GREP_CACHE_FILE"
|
||||||
unset __GREP_CACHE_FILE __GREP_ALIAS_CACHES
|
unset __GREP_CACHE_FILE __GREP_ALIAS_CACHES
|
||||||
|
|||||||
@ -26,8 +26,10 @@ fi
|
|||||||
|
|
||||||
# OSX command-not-found support
|
# OSX command-not-found support
|
||||||
# https://github.com/Homebrew/homebrew-command-not-found
|
# https://github.com/Homebrew/homebrew-command-not-found
|
||||||
if [[ -s '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh' ]]; then
|
if type brew &> /dev/null; then
|
||||||
source '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh'
|
if brew command command-not-found-init > /dev/null 2>&1; then
|
||||||
|
eval "$(brew command-not-found-init)";
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# NixOS command-not-found support
|
# NixOS command-not-found support
|
||||||
|
|||||||
@ -1,13 +1,6 @@
|
|||||||
# Autocompletion for Minikube.
|
# Autocompletion for Minikube.
|
||||||
#
|
#
|
||||||
if (( $+commands[minikube] )); then
|
|
||||||
__MINICUBE_COMPLETION_FILE="${ZSH_CACHE_DIR}/minicube_completion"
|
|
||||||
|
|
||||||
if [[ ! -f $__MINICUBE_COMPLETION_FILE ]]; then
|
if [ $commands[minikube] ]; then
|
||||||
minikube completion zsh >! $__MINICUBE_COMPLETION_FILE
|
source <(minikube completion zsh)
|
||||||
fi
|
|
||||||
|
|
||||||
[[ -f $__MINICUBE_COMPLETION_FILE ]] && source $__MINICUBE_COMPLETION_FILE
|
|
||||||
|
|
||||||
unset __MINICUBE_COMPLETION_FILE
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -89,7 +89,6 @@ case "$words[1]" in
|
|||||||
if [[ "$state" == packages ]]; then
|
if [[ "$state" == packages ]]; then
|
||||||
_pip_all
|
_pip_all
|
||||||
_wanted piplist expl 'packages' compadd -a piplist
|
_wanted piplist expl 'packages' compadd -a piplist
|
||||||
_files -g "*.(tar.gz|whl)"
|
|
||||||
fi ;;
|
fi ;;
|
||||||
uninstall)
|
uninstall)
|
||||||
_pip_installed
|
_pip_installed
|
||||||
|
|||||||
@ -11,8 +11,7 @@ plugins=(... python)
|
|||||||
|
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
|------------------|---------------------------------------------------------------------------------|
|
|------------------|---------------------------------------------------------------------------------|
|
||||||
| `ipython` | Runs the appropriate `ipython` version according to the activated virtualenv |
|
|
||||||
| `pyfind` | Finds .py files recursively in the current directory |
|
| `pyfind` | Finds .py files recursively in the current directory |
|
||||||
| `pyclean [dirs]` | Deletes byte-code and cache files from a list of directories or the current one |
|
| `pyclean [dirs]` | Deletes byte-code and cache files from a list of directories or the current one |
|
||||||
| `pygrep <text>` | Looks for `text` in .py files |
|
| `pygrep <text>` | Looks for `text` in .py files |
|
||||||
| `pyuserpaths` | Add --user site-packages to PYTHONPATH, for all installed python versions. |
|
| `ipython` | Runs the appropriate `ipython` version according to the activated virtualenv |
|
||||||
|
|||||||
@ -11,35 +11,6 @@ function pyclean() {
|
|||||||
find ${ZSH_PYCLEAN_PLACES} -depth -type d -name ".pytest_cache" -exec rm -r "{}" +
|
find ${ZSH_PYCLEAN_PLACES} -depth -type d -name ".pytest_cache" -exec rm -r "{}" +
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add the user installed site-packages paths to PYTHONPATH, only if the
|
|
||||||
# directory exists. Also preserve the current PYTHONPATH value.
|
|
||||||
# Feel free to autorun this when .zshrc loads.
|
|
||||||
function pyuserpaths() {
|
|
||||||
local targets=("python2" "python3") # bins
|
|
||||||
|
|
||||||
# Get existing interpreters.
|
|
||||||
local interps=()
|
|
||||||
for target in $targets; do
|
|
||||||
[ `command -v $target` ] && interps+=($target)
|
|
||||||
done
|
|
||||||
|
|
||||||
# Check for a non-standard install directory.
|
|
||||||
local user_base="${HOME}/.local"
|
|
||||||
[ $PYTHONUSERBASE ] && user_base=$PYTHONUSERBASE
|
|
||||||
|
|
||||||
# Add version specific paths, if:
|
|
||||||
# it exists in the filesystem;
|
|
||||||
# it isn't in PYTHONPATH already.
|
|
||||||
for interp in $interps; do
|
|
||||||
# Get minor release version.
|
|
||||||
local ver=`$interp -V 2>&1`
|
|
||||||
ver=`echo ${ver:7} | cut -d '.' -f 1,2` # The patch version is variable length, truncate it.
|
|
||||||
|
|
||||||
local site_pkgs="${user_base}/lib/python${ver}/site-packages"
|
|
||||||
[[ -d $site_pkgs && ! $PYTHONPATH =~ $site_pkgs ]] && export PYTHONPATH=${site_pkgs}:$PYTHONPATH
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Grep among .py files
|
# Grep among .py files
|
||||||
alias pygrep='grep -r --include="*.py"'
|
alias pygrep='grep -r --include="*.py"'
|
||||||
|
|
||||||
|
|||||||
@ -20,8 +20,6 @@ here are the results of calling `shrink_path <option> /home/me/foo/bar/quux`:
|
|||||||
-s|--short /h/m/f/b/q
|
-s|--short /h/m/f/b/q
|
||||||
-t|--tilde ~/f/ba/q
|
-t|--tilde ~/f/ba/q
|
||||||
-f|--fish ~/f/b/quux
|
-f|--fish ~/f/b/quux
|
||||||
-3 /hom/me/foo/bar/quu
|
|
||||||
-e '$' -3 /ho$/me/foo/bar/qu$
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@ -40,13 +38,10 @@ The following options are available:
|
|||||||
```
|
```
|
||||||
-f, --fish fish simulation, equivalent to -l -s -t.
|
-f, --fish fish simulation, equivalent to -l -s -t.
|
||||||
-l, --last Print the last directory's full name.
|
-l, --last Print the last directory's full name.
|
||||||
-s, --short Truncate directory names to the number of characters given by -. Without
|
-s, --short Truncate directory names to the first character. Without
|
||||||
-s, names are truncated without making them ambiguous.
|
-s, names are truncated without making them ambiguous.
|
||||||
-t, --tilde Substitute ~ for the home directory.
|
-t, --tilde Substitute ~ for the home directory.
|
||||||
-T, --nameddirs Substitute named directories as well.
|
-T, --nameddirs Substitute named directories as well.
|
||||||
-# Truncate each directly to at least this many characters inclusive of the
|
|
||||||
ellipsis character(s) (defaulting to 1).
|
|
||||||
-e SYMBOL Postfix symbol(s) to indicate that a directory name had been truncated.
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The long options can also be set via zstyle, like
|
The long options can also be set via zstyle, like
|
||||||
@ -61,7 +56,6 @@ supported.
|
|||||||
## License
|
## License
|
||||||
|
|
||||||
Copyright (C) 2008 by Daniel Friesel <derf@xxxxxxxxxxxxxxxxxx>
|
Copyright (C) 2008 by Daniel Friesel <derf@xxxxxxxxxxxxxxxxxx>
|
||||||
Copyright (C) 2018-2020 by Pavel N. Krivitsky
|
|
||||||
|
|
||||||
License: WTFPL <http://www.wtfpl.net>
|
License: WTFPL <http://www.wtfpl.net>
|
||||||
|
|
||||||
|
|||||||
@ -10,13 +10,10 @@
|
|||||||
#
|
#
|
||||||
# -f, --fish fish simulation, equivalent to -l -s -t.
|
# -f, --fish fish simulation, equivalent to -l -s -t.
|
||||||
# -l, --last Print the last directory's full name.
|
# -l, --last Print the last directory's full name.
|
||||||
# -s, --short Truncate directory names to the number of characters given by -#. Without
|
# -s, --short Truncate directory names to the first character. Without
|
||||||
# -s, names are truncated without making them ambiguous.
|
# -s, names are truncated without making them ambiguous.
|
||||||
# -t, --tilde Substitute ~ for the home directory.
|
# -t, --tilde Substitute ~ for the home directory.
|
||||||
# -T, --nameddirs Substitute named directories as well.
|
# -T, --nameddirs Substitute named directories as well.
|
||||||
# -# Truncate each directly to at least this many characters inclusive of the
|
|
||||||
# ellipsis character(s) (defaulting to 1).
|
|
||||||
# -e SYMBOL Postfix symbol(s) to indicate that a directory name had been truncated.
|
|
||||||
#
|
#
|
||||||
# The long options can also be set via zstyle, like
|
# The long options can also be set via zstyle, like
|
||||||
# zstyle :prompt:shrink_path fish yes
|
# zstyle :prompt:shrink_path fish yes
|
||||||
@ -40,8 +37,6 @@ shrink_path () {
|
|||||||
typeset -i short=0
|
typeset -i short=0
|
||||||
typeset -i tilde=0
|
typeset -i tilde=0
|
||||||
typeset -i named=0
|
typeset -i named=0
|
||||||
typeset -i length=1
|
|
||||||
typeset ellipsis=""
|
|
||||||
|
|
||||||
if zstyle -t ':prompt:shrink_path' fish; then
|
if zstyle -t ':prompt:shrink_path' fish; then
|
||||||
lastfull=1
|
lastfull=1
|
||||||
@ -58,10 +53,6 @@ shrink_path () {
|
|||||||
|
|
||||||
while [[ $1 == -* ]]; do
|
while [[ $1 == -* ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
--)
|
|
||||||
shift
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
-f|--fish)
|
-f|--fish)
|
||||||
lastfull=1
|
lastfull=1
|
||||||
short=1
|
short=1
|
||||||
@ -71,13 +62,9 @@ shrink_path () {
|
|||||||
print 'Usage: shrink_path [-f -l -s -t] [directory]'
|
print 'Usage: shrink_path [-f -l -s -t] [directory]'
|
||||||
print ' -f, --fish fish-simulation, like -l -s -t'
|
print ' -f, --fish fish-simulation, like -l -s -t'
|
||||||
print ' -l, --last Print the last directory''s full name'
|
print ' -l, --last Print the last directory''s full name'
|
||||||
print ' -s, --short Truncate directory names to the number of characters given by -#. Without'
|
print ' -s, --short Truncate directory names to the first character'
|
||||||
print ' -s, names are truncated without making them ambiguous.'
|
|
||||||
print ' -t, --tilde Substitute ~ for the home directory'
|
print ' -t, --tilde Substitute ~ for the home directory'
|
||||||
print ' -T, --nameddirs Substitute named directories as well'
|
print ' -T, --nameddirs Substitute named directories as well'
|
||||||
print ' -# Truncate each directly to at least this many characters inclusive of the'
|
|
||||||
print ' ellipsis character(s) (defaulting to 1).'
|
|
||||||
print ' -e SYMBOL Postfix symbol(s) to indicate that a directory name had been truncated.'
|
|
||||||
print 'The long options can also be set via zstyle, like'
|
print 'The long options can also be set via zstyle, like'
|
||||||
print ' zstyle :prompt:shrink_path fish yes'
|
print ' zstyle :prompt:shrink_path fish yes'
|
||||||
return 0
|
return 0
|
||||||
@ -89,18 +76,10 @@ shrink_path () {
|
|||||||
tilde=1
|
tilde=1
|
||||||
named=1
|
named=1
|
||||||
;;
|
;;
|
||||||
-[0-9]|-[0-9][0-9])
|
|
||||||
length=${1/-/}
|
|
||||||
;;
|
|
||||||
-e)
|
|
||||||
shift
|
|
||||||
ellipsis="$1"
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
typeset -i elllen=${#ellipsis}
|
|
||||||
typeset -a tree expn
|
typeset -a tree expn
|
||||||
typeset result part dir=${1-$PWD}
|
typeset result part dir=${1-$PWD}
|
||||||
typeset -i i
|
typeset -i i
|
||||||
@ -130,20 +109,12 @@ shrink_path () {
|
|||||||
expn=(a b)
|
expn=(a b)
|
||||||
part=''
|
part=''
|
||||||
i=0
|
i=0
|
||||||
until [[ $i -gt 99 || ( $i -ge $((length - ellen)) || $dir == $part ) && ( (( ${#expn} == 1 )) || $dir = $expn ) ]]; do
|
until [[ (( ${#expn} == 1 )) || $dir = $expn || $i -gt 99 ]] do
|
||||||
(( i++ ))
|
(( i++ ))
|
||||||
part+=$dir[$i]
|
part+=$dir[$i]
|
||||||
expn=($(echo ${part}*(-/)))
|
expn=($(echo ${part}*(-/)))
|
||||||
(( short )) && [[ $i -ge $((length - ellen)) ]] && break
|
(( short )) && break
|
||||||
done
|
done
|
||||||
|
|
||||||
typeset -i dif=$(( ${#dir} - ${#part} - ellen ))
|
|
||||||
if [[ $dif -gt 0 ]]
|
|
||||||
then
|
|
||||||
part+="$ellipsis"
|
|
||||||
else
|
|
||||||
part="$dir"
|
|
||||||
fi
|
|
||||||
result+="/$part"
|
result+="/$part"
|
||||||
cd -q $dir
|
cd -q $dir
|
||||||
shift tree
|
shift tree
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user