/[cvs]/nfo/bash/ff
ViewVC logotype

Annotation of /nfo/bash/ff

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Sun Nov 7 02:02:01 2004 UTC (19 years, 5 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +3 -1 lines
+ added help text for option -i

1 rabit 1.1 #!/bin/sh
2     #---------------------------------------------------------------------
3     N='ff'
4     C='rabit@netfrag.org, 08.10.2004'
5     F="$N - Follow file"
6 joko 1.3 I='$Id: ff,v 1.2 2004/11/07 01:58:30 joko Exp $'
7 rabit 1.1 #---------------------------------------------------------------------
8    
9     # If unset, set the per-user file list to a good default:
10     [ -z "$FFFILES" ] && FFFILES=$HOME'/.ff_files'
11    
12     E='echo -e'
13     YW="\033[1;33m"
14     GY="\033[0;37m"
15     B1="\033[1m"
16     B0="\033[0m"
17    
18     function CheckFileList {
19     if [ -e "$FFFILES" ]; then
20     FileListExists=1
21     else
22     $E " Error: '"$B1$FFFILES$B0"' does not exist yet. First add a file."
23     $E " Try '$B1$N --help$B0' for information on usage."
24     $E 'Aborting.'
25     fi
26     return
27     }
28     function CountFiles {
29     FileCount=`cat $FFFILES | wc -w`
30     return
31     }
32    
33     $E "$YW$F$GY ($C)\n($I)"
34     p1=$1
35     case "$p1" in
36     (-a)
37     if [ -e $2 ]; then
38     $E "- Adding file '"$B1$2$B0"'..."
39     echo $2 >> $FFFILES
40     CountFiles
41     $E " File index is '"$B1$FileCount$B0"'"
42     $E 'Done.'
43     else
44     $E " Error: '"$B1$2$B0"' does not exist."
45     $E 'Aborting.'
46     fi
47     exit
48     ;;
49     (-h|--help)
50     # Just overrun this casing and show help.
51     ;;
52     (-l)
53     CheckFileList; [ -z $FileListExists ] && exit
54     $E "- Listing files in '"$B1$FFFILES$B0"'..."
55     while read FileName; do
56     ((Index++))
57     $E ' '$B1$Index$B0": '"$B1$FileName$B0"'"
58     done < $FFFILES
59     $E 'Done.'
60 joko 1.2 exit
61     ;;
62     (-i)
63     iselect=`which iselect`
64     if [ -z $iselect ]; then
65     echo "ERROR: iselect is not installed"
66     exit
67     fi
68     sel=`cat $FFFILES | $iselect -a -c -n "Select file to tail"`
69     if [ ! -z $sel ]; then
70     tail -f $sel
71     fi
72 rabit 1.1 exit
73     ;;
74     (?*)
75     CheckFileList; [ -z $FileListExists ] && exit
76     CountFiles
77     if ((p1>0)) && ((p1<=FileCount)); then
78     FileName=`head -n $p1 $FFFILES | tail -n 1`
79     $E "- Following '"$B1$FileName$B0"' (press CTRL-C to stop)..."
80     echo
81     tail -f $FileName
82     else
83     $E ' Error: '$B1'<number>'$B0' must be in the range of 1 - '$FileCount'.'
84     $E 'Aborting.'
85     fi
86     exit
87     ;;
88     esac
89    
90     $E $B1'Usage:'$B0
91     $E " $B1$N -l$B0"
92     $E " List all files from '"$B1$FFFILES$B0"' with indices."
93     $E ' '$B1$N' <number>'$B0
94     $E ' Tail and follow the file with index '$B1'<number>'$B0'.'
95     $E ' '$B1$N' -a <filename>'$B0
96     $E " Add a file to '"$B1$FFFILES$B0"'. "$B1'<filename>'$B0' must exist.'
97 joko 1.3 $E " $B1$N -i$B0"
98     $E " Interactively choose from list of files in '"$B1$FFFILES$B0"'."
99 rabit 1.1 $E ' '$B1$N' [-h|--help]'$B0
100     $E ' Get this brief help.'
101     $E "The variable '${B1}FFFILES$B0' set overrides the file list default file name."
102     $E "(for example: '${B1}export FFFILES=\$HOME/fff.txt$B0'.)"
103     # EOF

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed