1 # Copy this file into /usr/share/zsh/site-functions/
2 # and add 'autoload n-cd` to .zshrc
4 # This function allows to choose a directory from pushd stack
10 setopt extendedglob pushdignoredups
16 # Unset before configuration is read
17 unset NLIST_COLORING_PATTERN
19 [ -f ~/.config/znt/n-list.conf ] && builtin source ~/.config/znt/n-list.conf
20 [ -f ~/.config/znt/n-cd.conf ] && builtin source ~/.config/znt/n-cd.conf
25 NLIST_REMEMBER_STATE=0
28 list=( "${(@M)list:#(#i)*$1*}" )
30 local NLIST_GREP_STRING="$1"
32 [ "$#list" -eq 0 ] && echo "No matching directories"
34 if [ "$#hotlist" -ge 1 ]; then
35 typeset -a NLIST_NONSELECTABLE_ELEMENTS NLIST_HOP_INDEXES
36 local tmp_list_size="$#list"
37 NLIST_NONSELECTABLE_ELEMENTS=( $(( tmp_list_size+1 )) $(( tmp_list_size+2 )) )
38 list=( "$list[@]" "" $'\x1b[00;31m'"Hotlist"$'\x1b[00;00m': "$hotlist[@]" )
39 (( tmp_list_size+=3 ))
40 local middle_hop=$(( (tmp_list_size+$#list) / 2 ))
41 [[ "$middle_hop" -eq $tmp_list_size || "$middle_hop" -eq $#list ]] && middle_hop=""
42 [ "$tmp_list_size" -eq $#list ] && tmp_list_size=""
43 NLIST_HOP_INDEXES=( 1 $tmp_list_size $middle_hop $#list )
45 [ "$#list" -eq 0 ] && return 1
50 if [ "$REPLY" -gt 0 ]; then
51 selected="$reply[REPLY]"
52 selected="${selected/#\~/$HOME}"
54 (( NCD_DONT_PUSHD )) && setopt NO_AUTO_PUSHD
57 (( NCD_DONT_PUSHD )) && setopt AUTO_PUSHD
59 if [ "$code" -eq "0" ]; then
61 if [ "${(t)CURSOR}" = "integer-local-special" ]; then
62 zle -M "You have selected $selected"
64 echo "You have selected $selected"
68 [ "${(t)CURSOR}" = "integer-local-special" ] && zle redisplay
71 # vim: set filetype=zsh: