mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-12 15:34:50 +08:00
Compare commits
6 Commits
9ce7de9f16
...
72707d92b1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72707d92b1 | ||
|
|
ed94e06dda | ||
|
|
e65bce8495 | ||
|
|
74420341df | ||
|
|
e42683b8c5 | ||
|
|
d3dfc13716 |
24
lib/grep.zsh
24
lib/grep.zsh
@ -2,7 +2,9 @@ __GREP_CACHE_FILE="$ZSH_CACHE_DIR"/grep-alias
|
||||
|
||||
# See if there's a cache file modified in the last day
|
||||
__GREP_ALIAS_CACHES=("$__GREP_CACHE_FILE"(Nm-1))
|
||||
if [[ -z "$__GREP_ALIAS_CACHES" ]]; then
|
||||
if [[ -n "$__GREP_ALIAS_CACHES" ]]; then
|
||||
source "$__GREP_CACHE_FILE"
|
||||
else
|
||||
grep-flags-available() {
|
||||
command grep "$@" "" &>/dev/null <<< ""
|
||||
}
|
||||
@ -12,26 +14,28 @@ if [[ -z "$__GREP_ALIAS_CACHES" ]]; then
|
||||
|
||||
# Check for --exclude-dir, otherwise check for --exclude. If --exclude
|
||||
# isn't available, --color won't be either (they were released at the same
|
||||
# time (v2.5): http://git.savannah.gnu.org/cgit/grep.git/tree/NEWS?id=1236f007
|
||||
# time (v2.5): https://git.savannah.gnu.org/cgit/grep.git/tree/NEWS?id=1236f007
|
||||
if grep-flags-available --color=auto --exclude-dir=.cvs; then
|
||||
GREP_OPTIONS="--color=auto --exclude-dir=$EXC_FOLDERS"
|
||||
elif grep-flags-available --color=auto --exclude=.cvs; then
|
||||
GREP_OPTIONS="--color=auto --exclude=$EXC_FOLDERS"
|
||||
fi
|
||||
|
||||
{
|
||||
if [[ -n "$GREP_OPTIONS" ]]; then
|
||||
# export grep, egrep and fgrep settings
|
||||
echo "alias grep='grep $GREP_OPTIONS'"
|
||||
echo "alias egrep='egrep $GREP_OPTIONS'"
|
||||
echo "alias fgrep='fgrep $GREP_OPTIONS'"
|
||||
if [[ -n "$GREP_OPTIONS" ]]; then
|
||||
# export grep, egrep and fgrep settings
|
||||
alias grep="grep $GREP_OPTIONS"
|
||||
alias egrep="egrep $GREP_OPTIONS"
|
||||
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
|
||||
} > "$__GREP_CACHE_FILE"
|
||||
fi
|
||||
|
||||
# Clean up
|
||||
unset GREP_OPTIONS EXC_FOLDERS
|
||||
unfunction grep-flags-available
|
||||
fi
|
||||
|
||||
source "$__GREP_CACHE_FILE"
|
||||
unset __GREP_CACHE_FILE __GREP_ALIAS_CACHES
|
||||
|
||||
@ -26,10 +26,8 @@ fi
|
||||
|
||||
# OSX command-not-found support
|
||||
# https://github.com/Homebrew/homebrew-command-not-found
|
||||
if type brew &> /dev/null; then
|
||||
if brew command command-not-found-init > /dev/null 2>&1; then
|
||||
eval "$(brew command-not-found-init)";
|
||||
fi
|
||||
if [[ -s '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh' ]]; then
|
||||
source '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh'
|
||||
fi
|
||||
|
||||
# NixOS command-not-found support
|
||||
|
||||
@ -1,6 +1,13 @@
|
||||
# Autocompletion for Minikube.
|
||||
#
|
||||
if (( $+commands[minikube] )); then
|
||||
__MINICUBE_COMPLETION_FILE="${ZSH_CACHE_DIR}/minicube_completion"
|
||||
|
||||
if [ $commands[minikube] ]; then
|
||||
source <(minikube completion zsh)
|
||||
if [[ ! -f $__MINICUBE_COMPLETION_FILE ]]; then
|
||||
minikube completion zsh >! $__MINICUBE_COMPLETION_FILE
|
||||
fi
|
||||
|
||||
[[ -f $__MINICUBE_COMPLETION_FILE ]] && source $__MINICUBE_COMPLETION_FILE
|
||||
|
||||
unset __MINICUBE_COMPLETION_FILE
|
||||
fi
|
||||
|
||||
@ -89,6 +89,7 @@ case "$words[1]" in
|
||||
if [[ "$state" == packages ]]; then
|
||||
_pip_all
|
||||
_wanted piplist expl 'packages' compadd -a piplist
|
||||
_files -g "*.(tar.gz|whl)"
|
||||
fi ;;
|
||||
uninstall)
|
||||
_pip_installed
|
||||
|
||||
@ -11,7 +11,8 @@ plugins=(... python)
|
||||
|
||||
| Command | Description |
|
||||
|------------------|---------------------------------------------------------------------------------|
|
||||
| `ipython` | Runs the appropriate `ipython` version according to the activated virtualenv |
|
||||
| `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 |
|
||||
| `pygrep <text>` | Looks for `text` in .py files |
|
||||
| `ipython` | Runs the appropriate `ipython` version according to the activated virtualenv |
|
||||
| `pyuserpaths` | Add --user site-packages to PYTHONPATH, for all installed python versions. |
|
||||
|
||||
@ -11,6 +11,35 @@ function pyclean() {
|
||||
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
|
||||
alias pygrep='grep -r --include="*.py"'
|
||||
|
||||
|
||||
@ -20,6 +20,8 @@ here are the results of calling `shrink_path <option> /home/me/foo/bar/quux`:
|
||||
-s|--short /h/m/f/b/q
|
||||
-t|--tilde ~/f/ba/q
|
||||
-f|--fish ~/f/b/quux
|
||||
-3 /hom/me/foo/bar/quu
|
||||
-e '$' -3 /ho$/me/foo/bar/qu$
|
||||
```
|
||||
|
||||
|
||||
@ -38,10 +40,13 @@ The following options are available:
|
||||
```
|
||||
-f, --fish fish simulation, equivalent to -l -s -t.
|
||||
-l, --last Print the last directory's full name.
|
||||
-s, --short Truncate directory names to the first character. Without
|
||||
-s, --short Truncate directory names to the number of characters given by -. Without
|
||||
-s, names are truncated without making them ambiguous.
|
||||
-t, --tilde Substitute ~ for the home directory.
|
||||
-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
|
||||
@ -56,6 +61,7 @@ supported.
|
||||
## License
|
||||
|
||||
Copyright (C) 2008 by Daniel Friesel <derf@xxxxxxxxxxxxxxxxxx>
|
||||
Copyright (C) 2018-2020 by Pavel N. Krivitsky
|
||||
|
||||
License: WTFPL <http://www.wtfpl.net>
|
||||
|
||||
|
||||
@ -10,10 +10,13 @@
|
||||
#
|
||||
# -f, --fish fish simulation, equivalent to -l -s -t.
|
||||
# -l, --last Print the last directory's full name.
|
||||
# -s, --short Truncate directory names to the first character. Without
|
||||
# -s, --short Truncate directory names to the number of characters given by -#. Without
|
||||
# -s, names are truncated without making them ambiguous.
|
||||
# -t, --tilde Substitute ~ for the home directory.
|
||||
# -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
|
||||
# zstyle :prompt:shrink_path fish yes
|
||||
@ -37,6 +40,8 @@ shrink_path () {
|
||||
typeset -i short=0
|
||||
typeset -i tilde=0
|
||||
typeset -i named=0
|
||||
typeset -i length=1
|
||||
typeset ellipsis=""
|
||||
|
||||
if zstyle -t ':prompt:shrink_path' fish; then
|
||||
lastfull=1
|
||||
@ -53,6 +58,10 @@ shrink_path () {
|
||||
|
||||
while [[ $1 == -* ]]; do
|
||||
case $1 in
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-f|--fish)
|
||||
lastfull=1
|
||||
short=1
|
||||
@ -62,9 +71,13 @@ shrink_path () {
|
||||
print 'Usage: shrink_path [-f -l -s -t] [directory]'
|
||||
print ' -f, --fish fish-simulation, like -l -s -t'
|
||||
print ' -l, --last Print the last directory''s full name'
|
||||
print ' -s, --short Truncate directory names to the first character'
|
||||
print ' -s, --short Truncate directory names to the number of characters given by -#. Without'
|
||||
print ' -s, names are truncated without making them ambiguous.'
|
||||
print ' -t, --tilde Substitute ~ for the home directory'
|
||||
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 ' zstyle :prompt:shrink_path fish yes'
|
||||
return 0
|
||||
@ -76,10 +89,18 @@ shrink_path () {
|
||||
tilde=1
|
||||
named=1
|
||||
;;
|
||||
-[0-9]|-[0-9][0-9])
|
||||
length=${1/-/}
|
||||
;;
|
||||
-e)
|
||||
shift
|
||||
ellipsis="$1"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
typeset -i elllen=${#ellipsis}
|
||||
typeset -a tree expn
|
||||
typeset result part dir=${1-$PWD}
|
||||
typeset -i i
|
||||
@ -109,12 +130,20 @@ shrink_path () {
|
||||
expn=(a b)
|
||||
part=''
|
||||
i=0
|
||||
until [[ (( ${#expn} == 1 )) || $dir = $expn || $i -gt 99 ]] do
|
||||
until [[ $i -gt 99 || ( $i -ge $((length - ellen)) || $dir == $part ) && ( (( ${#expn} == 1 )) || $dir = $expn ) ]]; do
|
||||
(( i++ ))
|
||||
part+=$dir[$i]
|
||||
expn=($(echo ${part}*(-/)))
|
||||
(( short )) && break
|
||||
(( short )) && [[ $i -ge $((length - ellen)) ]] && break
|
||||
done
|
||||
|
||||
typeset -i dif=$(( ${#dir} - ${#part} - ellen ))
|
||||
if [[ $dif -gt 0 ]]
|
||||
then
|
||||
part+="$ellipsis"
|
||||
else
|
||||
part="$dir"
|
||||
fi
|
||||
result+="/$part"
|
||||
cd -q $dir
|
||||
shift tree
|
||||
|
||||
Loading…
Reference in New Issue
Block a user