make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / user-tools / ff
blobaec49e5130c89ce0b52a722993a82f888e9c0db1
1 #!/bin/bash
3 pattern=$1
4 shift
5 depth=0
7 if expr "$pattern" : '.*/' >/dev/null
8 then
9 matchtype=iwholename
10 else
11 matchtype=iname
15 while true
17 #echo -e "\r\e[KDepth $depth" >&2
18 find "${@:-.}" -mindepth "$depth" -maxdepth "$depth" -xdev \
19 \( -$matchtype "*$pattern*" -printf "1 %p\n" \) -o \
20 \( -type d -printf "3 %p\n" \) 2>/dev/null
21 cont=`find "${@:-.}" -mindepth "$depth" -maxdepth "$depth" -xdev -printf 1 -quit 2>/dev/null`
22 [ -z "$cont" ] && break
23 let depth++
24 done |{
25 cols=`tput cols`
26 curpath=''
27 while read -r fd path
29 if [ $fd = 3 ]
30 then
31 curpath=$path
32 elif [ $fd = 1 ]
33 then
34 echo -ne "\r\e[K" >&2
35 echo "$path"
36 t=0
39 if [ $SECONDS -gt ${t:-0} ]
40 then
41 x=$curpath
42 if [ ${#x} -gt $[cols-3] ]
43 then
44 x=${x: -$[cols-4]}/
45 else
46 x=$x/
48 echo -ne "\r\e[K$x" >&2
49 t=$SECONDS
51 done
54 echo -ne "\r\e[K" >&2
58 true <<EOF
60 =pod
62 =head1 NAME
64 ff - Find files horizontally, ie. a whole directory level at a time, across subtrees
66 =head1 SYNOPSIS
68 ff <B<pattern>> [B<path>-1] [B<path>-2] ... [B<path>-n]
70 =head1 DESCRIPTION
72 Search files which name matches to B<pattern> in B<path>s directories recursively, case-insensitively.
73 The file's path is matched if B<pattern> contains '/'.
74 Searching is done horizontaly, ie. scan the upper-most directory level first completely,
75 then dive into the next level and scan those directories before moving to the 3rd level deep, and so on.
76 This way users usually find what they search for more quickly.
78 =cut
80 EOF