-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprint-alias.plugin.zsh
40 lines (35 loc) · 1.26 KB
/
print-alias.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
_print-alias () {
# Constants
local -r PREFIX=${PRINT_ALIAS_PREFIX:-}
local -r ALIAS_FORMAT=${PRINT_ALIAS_FORMAT:-$'\e[36m'}
local -r NON_ALIAS_FORMAT=${PRINT_NON_ALIAS_FORMAT:-$'\e[2m'}
local -r RESET_COLORS=$'\e[0m'
local -r IGNORE_ALIASES=(${PRINT_ALIAS_IGNORE_ALIASES:-})
local -r IGNORE_REDEFINED_COMMANDS=${PRINT_ALIAS_IGNORE_REDEFINED_COMMANDS:-'false'}
local -a words
words=( ${(z)BUFFER} )
local -r first_word=${words[1]}
if [[ ${IGNORE_ALIASES[(ie)$first_word]} -le ${#IGNORE_ALIASES} ]]; then
return
fi
if [[ "$(whence -w $first_word 2>/dev/null)" == "${first_word}: alias" ]]; then
shift words
local -r aliased_command=($(whence $first_word))
if [[ $IGNORE_REDEFINED_COMMANDS == 'true' ]]; then
if [[ $first_word == ${aliased_command[1]} ]]; then
return
fi
fi
echo -nE $'\n'"${PREFIX}${ALIAS_FORMAT}${aliased_command}${RESET_COLORS}"
for word in $words; do
echo -nE " ${NON_ALIAS_FORMAT}${word}${RESET_COLORS}"
done
fi
}
zle -N accept-line _print-alias-accept-line
_print-alias-accept-line () {
emulate -L zsh
_print-alias
zle .accept-line
}
zle -N accept-line _print-alias-accept-line