zshrc.d/30-functions.zrc
changeset 5 5dbc9ebf690c
parent 0 7215ca490221
child 6 7671e95ab8b0
equal deleted inserted replaced
4:ca432c482cc9 5:5dbc9ebf690c
    38         fi
    38         fi
    39     done
    39     done
    40 }
    40 }
    41 
    41 
    42 
    42 
    43 # Customized version from Frank Terbeck' scripts
       
    44 # http://bewatermyfriend.org/p/2011/013/
       
    45 # "."   will display the current working directory
       
    46 # ".."  will get you 1 directory up,
       
    47 # "..." will get you 2 directories up, etc.
       
    48 function ft_accept_line_cd_up() {
       
    49     setopt local_options extended_glob
       
    50     local -a cmdline
       
    51     cmdline=( ${(z)BUFFER} )
       
    52     if (( ${#cmdline} == 1 )) && [[ ${cmdline[1]} == "." ]] ; then
       
    53         BUFFER="pwd"
       
    54         zle ".$WIDGET"
       
    55         return
       
    56     fi
       
    57     if (( ${#cmdline} == 1 )) && [[ ${cmdline[1]} == ..## ]] ; then
       
    58         BUFFER='cd '
       
    59         for (( i = 2; i <= ${#${cmdline[1]}}; i++ )); do
       
    60             BUFFER="${BUFFER}../"
       
    61         done
       
    62         BUFFER=${BUFFER%/}
       
    63     fi
       
    64     zle ".$WIDGET"
       
    65 }
       
    66 zle -N accept-line ft_accept_line_cd_up
       
    67 
       
    68 # 2nd part, completion support...
       
    69 function ft_complete_with_dots() {
       
    70     setopt local_options extended_glob
       
    71     local -a cmdline
       
    72     cmdline=( ${(z)BUFFER} )
       
    73     if (( ${#cmdline} == 1 )) && [[ ${cmdline[1]} == ..## ]] ; then
       
    74         BUFFER='cd '
       
    75         for (( i = 2; i <= ${#${cmdline[1]}}; i++ )); do
       
    76             BUFFER="${BUFFER}../"
       
    77         done
       
    78         CURSOR=${#BUFFER}
       
    79     fi
       
    80     zle ".$WIDGET"
       
    81 }
       
    82 # Disabling for now as I don't know how to fallback to automatic correction...
       
    83 #zle -N expand-or-complete ft_complete_with_dots
       
    84 
       
    85 
       
    86 # genpass()
    43 # genpass()
    87 # Generates a tough password of a given length
    44 # Generates a tough password of a given length
    88 # Borrowed (and slightly modifed) from Seth House github repository.
    45 # Borrowed (and slightly modifed) from Seth House github repository.
    89 
    46 
    90 function genpass() {
    47 function genpass() {