Update f.sh

This commit is contained in:
Wuffers Lightwolf 2011-12-21 18:23:33 -06:00
commit 19f7520c6a

View file

@ -100,7 +100,7 @@ _f() {
elif [ "$1" = "--query" ]; then elif [ "$1" = "--query" ]; then
# query the database, this need some local variables to be set # query the database, this need some local variables to be set
while read line; do while read line; do
[ -${typ} "${line%%|*}" ] && echo "$line" [ -${typ:-e} "${line%%|*}" ] && echo "$line"
done < "$_F_DATA" | \ done < "$_F_DATA" | \
$_F_AWK -v t="$(date +%s)" -v mode="$mode" -v q="$fnd" -F"|" ' $_F_AWK -v t="$(date +%s)" -v mode="$mode" -v q="$fnd" -F"|" '
function frecent(rank, time) { function frecent(rank, time) {
@ -158,7 +158,7 @@ _f() {
[ -f "$_F_DATA" ] || return # no db yet [ -f "$_F_DATA" ] || return # no db yet
local fnd last local fnd last
while [ "$1" ]; do case "$1" in 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;; --) while [ "$2" ]; do shift; fnd+="$1 "; last="$1"; done;;
-*) [ "$ZSH_VERSION" ] && local x='o=${o[2,#o]}' || local x='o=${o:1}' -*) [ "$ZSH_VERSION" ] && local x='o=${o[2,#o]}' || local x='o=${o:1}'
local o=${1#-}; while [ "$o" ]; do case $o in local o=${1#-}; while [ "$o" ]; do case $o in
@ -190,12 +190,10 @@ _f() {
*) fnd+="$1 "; last="$1";; *) fnd+="$1 "; last="$1";;
esac; shift; done esac; shift; done
[ "$typ" ] || local typ=e # default to match file and directory
# if we hit enter on a completion just execute # if we hit enter on a completion just execute
case "$last" in case "$last" in
# completions will always start with / # 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;; && $exec "$last" && return;;
esac esac
@ -203,15 +201,15 @@ _f() {
result="$(_f --query 2>> "$_F_SINK")" # query the database result="$(_f --query 2>> "$_F_SINK")" # query the database
[ $? -gt 0 ] && return [ $? -gt 0 ] && return
if [ "$list" ]; then if [ "$list" ]; then
echo "$result" | sort -n | sed 's/^[0-9.]*[ ]*//' echo "$result" | sort -n${r} | sed 's/^[0-9.]*[ ]*//'
elif [ "$show" ]; then elif [ "$show" ]; then
echo "$result" | sort -n echo "$result" | sort -n${r}
elif [ "$fnd" -a "$exec" ]; then # exec 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 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 else # no args, show
echo "$result" | sort -n echo "$result" | sort -n${r}
fi fi
fi fi
@ -279,12 +277,12 @@ if compctl >> "$_F_SINK" 2>&1; then # zsh
compstate[insert]=menu # no expand compstate[insert]=menu # no expand
reply=(${(f)"$(_f --complete "$compl")"}) 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() { _f_zsh_word_complete() {
local fnd="$(echo "${words[CURRENT]}" | sed 's/'"$_F_QUERY_SEPARATOR"'/ /g')" local fnd="$(echo "${words[CURRENT]}" | sed 's/'"$_F_QUERY_SEPARATOR"'/ /g')"
local typ=${1:-e} local typ=${1:-e}
_f --query 2>> "$_F_SINK" | sed 's/^[0-9.]*[ ]*//' | while read line; do _f --query 2>> "$_F_SINK" | sort -nr | sed 's/^[0-9.]*[ ]*//' | while read line; do
compadd -U "$line" compadd -U -V f "$line"
done done
compstate[insert]=menu # no expand compstate[insert]=menu # no expand
} }