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

Contents of /nfo/bash/ff

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Fri Oct 15 10:51:04 2004 UTC (19 years, 6 months ago) by rabit
Branch: MAIN
Initial commit: Follow file

1 #!/bin/sh
2 #---------------------------------------------------------------------
3 N='ff'
4 C='rabit@netfrag.org, 08.10.2004'
5 F="$N - Follow file"
6 I='$Id$'
7 #---------------------------------------------------------------------
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 exit
61 ;;
62 (?*)
63 CheckFileList; [ -z $FileListExists ] && exit
64 CountFiles
65 if ((p1>0)) && ((p1<=FileCount)); then
66 FileName=`head -n $p1 $FFFILES | tail -n 1`
67 $E "- Following '"$B1$FileName$B0"' (press CTRL-C to stop)..."
68 echo
69 tail -f $FileName
70 else
71 $E ' Error: '$B1'<number>'$B0' must be in the range of 1 - '$FileCount'.'
72 $E 'Aborting.'
73 fi
74 exit
75 ;;
76 esac
77
78 $E $B1'Usage:'$B0
79 $E " $B1$N -l$B0"
80 $E " List all files from '"$B1$FFFILES$B0"' with indices."
81 $E ' '$B1$N' <number>'$B0
82 $E ' Tail and follow the file with index '$B1'<number>'$B0'.'
83 $E ' '$B1$N' -a <filename>'$B0
84 $E " Add a file to '"$B1$FFFILES$B0"'. "$B1'<filename>'$B0' must exist.'
85 $E ' '$B1$N' [-h|--help]'$B0
86 $E ' Get this brief help.'
87 $E "The variable '${B1}FFFILES$B0' set overrides the file list default file name."
88 $E "(for example: '${B1}export FFFILES=\$HOME/fff.txt$B0'.)"
89 # EOF

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