-
Notifications
You must be signed in to change notification settings - Fork 50
/
alias-tips.plugin.zsh
57 lines (48 loc) · 1.79 KB
/
alias-tips.plugin.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
_alias_tips__PLUGIN_DIR=${0:a:h}
# If alias-tips is loaded from a symlink, then work out
# where the actual file is located
if [[ -L ${0:a} ]]; then
_alias_tips__PLUGIN_DIR=$(readlink ${0:a})
_alias_tips__PLUGIN_DIR=${_alias_tips__PLUGIN_DIR:h}
fi
#export ZSH_PLUGINS_ALIAS_TIPS_TEXT="💡 Alias tip: "
#export ZSH_PLUGINS_ALIAS_TIPS_EXCLUDES="_ c"
#export ZSH_PLUGINS_ALIAS_TIPS_EXPAND=0
_alias_tips__preexec () {
local CMD=$1
local CMD_EXPANDED=$2
if [[ $CMD != $CMD_EXPANDED ]] then # Alias is used
if [[ ${ZSH_PLUGINS_ALIAS_TIPS_REVEAL-0} == 1 ]] \
&& [[ ${${ZSH_PLUGINS_ALIAS_TIPS_REVEAL_EXCLUDES-()}[(I)$1]} == 0 ]] then # Reveal cmd
local reveal_text=${ZSH_PLUGINS_ALIAS_TIPS_REVEAL_TEXT-Alias for: }
local color_dark_gray='\e[1;30m'
local color_reset='\e[0m'
echo -e "$color_dark_gray$reveal_text$CMD_EXPANDED $color_reset"
fi
if [[ ${ZSH_PLUGINS_ALIAS_TIPS_EXPAND-1} == 0 ]] then
return 0
fi
fi
if hash git 2> /dev/null; then
# alias.foo bar => git foo = git bar
# alias.foo !git bar => git foo = git bar
local git_aliases
git_aliases=$(git config --get-regexp "^alias\." | \
\sed 's/[ ]/ = /' | \
\sed 's/^alias\./git /' | \
\sed 's/ = \([^!]\)/ = git \1/' | \
\sed 's/ = !/ = /')
fi
local shell_aliases
shell_aliases=$(\alias)
local shell_functions
shell_functions=$(\functions | \grep -E -a '^[a-zA-Z].+ \(\) \{$')
# Exit code returned from python script when we want to force use of aliases.
local force_exit_code=10
echo $shell_functions "\n" $git_aliases "\n" $shell_aliases | \
python3 ${_alias_tips__PLUGIN_DIR}/alias-tips.py $*
local ret=$?
if [[ $ret = $force_exit_code ]]; then kill -s INT $$ ; fi
}
autoload -Uz add-zsh-hook
add-zsh-hook preexec _alias_tips__preexec