From 19f7520c6a9f8a77d91fca312a4cec2ca110c36e Mon Sep 17 00:00:00 2001 From: Wuffers Lightwolf Date: Wed, 21 Dec 2011 18:23:33 -0600 Subject: [PATCH] Update f.sh --- plugins/f/f.sh | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/plugins/f/f.sh b/plugins/f/f.sh index d2d3a51f0..ead1b7b1e 100644 --- a/plugins/f/f.sh +++ b/plugins/f/f.sh @@ -100,7 +100,7 @@ _f() { elif [ "$1" = "--query" ]; then # query the database, this need some local variables to be set while read line; do - [ -${typ} "${line%%|*}" ] && echo "$line" + [ -${typ:-e} "${line%%|*}" ] && echo "$line" done < "$_F_DATA" | \ $_F_AWK -v t="$(date +%s)" -v mode="$mode" -v q="$fnd" -F"|" ' function frecent(rank, time) { @@ -158,7 +158,7 @@ _f() { [ -f "$_F_DATA" ] || return # no db yet local fnd last while [ "$1" ]; do case "$1" in - --complete) [ "$2" = "--" ] && shift; set -- $(echo $2); local list=1;; + --complete) [ "$2" = "--" ] && shift; set -- $(echo $2); local list=1 r=r;; --) while [ "$2" ]; do shift; fnd+="$1 "; last="$1"; done;; -*) [ "$ZSH_VERSION" ] && local x='o=${o[2,#o]}' || local x='o=${o:1}' local o=${1#-}; while [ "$o" ]; do case $o in @@ -190,12 +190,10 @@ _f() { *) fnd+="$1 "; last="$1";; esac; shift; done - [ "$typ" ] || local typ=e # default to match file and directory - # if we hit enter on a completion just execute case "$last" in # completions will always start with / - /*) [ -z "$show$list" -a -${typ} "$last" -a "$exec" ] \ + /*) [ -z "$show$list" -a -${typ:-e} "$last" -a "$exec" ] \ && $exec "$last" && return;; esac @@ -203,15 +201,15 @@ _f() { result="$(_f --query 2>> "$_F_SINK")" # query the database [ $? -gt 0 ] && return if [ "$list" ]; then - echo "$result" | sort -n | sed 's/^[0-9.]*[ ]*//' + echo "$result" | sort -n${r} | sed 's/^[0-9.]*[ ]*//' elif [ "$show" ]; then - echo "$result" | sort -n + echo "$result" | sort -n${r} elif [ "$fnd" -a "$exec" ]; then # exec - $exec "$(echo "$result" | sort -n | sed 's/^[0-9.]*[ ]*//' | tail -n1)" + $exec "$(echo "$result" | sort -n | sed -n '$s/^[0-9.]*[ ]*//p')" elif [ "$fnd" ] && [ "$ZSH_SUBSHELL$BASH_SUBSHELL" != "0" ]; then # echo - echo "$(echo "$result" | sort -n | sed 's/^[0-9.]*[ ]*//' | tail -n1)" + echo "$(echo "$result" | sort -n | sed -n '$s/^[0-9.]*[ ]*//p')" else # no args, show - echo "$result" | sort -n + echo "$result" | sort -n${r} fi fi @@ -279,12 +277,12 @@ if compctl >> "$_F_SINK" 2>&1; then # zsh compstate[insert]=menu # no expand reply=(${(f)"$(_f --complete "$compl")"}) } - compctl -U -K _f_zsh_cmd_complete -x 'C[-1,-*e],s[-]n[1,e]' -c -- _f + compctl -U -K _f_zsh_cmd_complete -V f -x 'C[-1,-*e],s[-]n[1,e]' -c -- _f _f_zsh_word_complete() { local fnd="$(echo "${words[CURRENT]}" | sed 's/'"$_F_QUERY_SEPARATOR"'/ /g')" local typ=${1:-e} - _f --query 2>> "$_F_SINK" | sed 's/^[0-9.]*[ ]*//' | while read line; do - compadd -U "$line" + _f --query 2>> "$_F_SINK" | sort -nr | sed 's/^[0-9.]*[ ]*//' | while read line; do + compadd -U -V f "$line" done compstate[insert]=menu # no expand }