-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzsh-dot-up.plugin.zsh
38 lines (32 loc) · 975 Bytes
/
zsh-dot-up.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
dot_up__regex='^\s*(\.){2,}\s*$'
dot_up__showing=false
function _dot_up_convert_to_slash_dots() {
local dots="${BUFFER//[[:space:]]}"
local count="${#dots}"
local target=".."
for ((i = 2; i < count; i++))
do
target="$target/.."
done
echo $target
}
function _dot_up_show_destination() {
if [[ "$BUFFER" =~ $dot_up__regex ]]
then
local absolute_path=$(readlink -f $(_dot_up_convert_to_slash_dots))
zle -M "Destination: $absolute_path"
dot_up__showing=true
elif [ "$dot_up__showing" = true ]
then
zle -M ""
dot_up__showing=false
fi
}
function _dot_up_move() {
if [[ "$BUFFER" =~ $dot_up__regex ]]
then
BUFFER="cd $(_dot_up_convert_to_slash_dots)"
fi
}
zle -N zle-line-pre-redraw _dot_up_show_destination
zle -N zle-line-finish _dot_up_move