plan9front/rc/bin/history

83 lines
1.5 KiB
Text
Raw Normal View History

#!/bin/rc
rfork e
nl='
'
fn prfile {
echo -n `{date $flagu -f 'MMM DD hh:mm:ss ZZZ YYYY' `{walk -e m $1}}
walk -e psM $1 | awk '{$NF="["$NF"]"; print " "$0}'
}
fn diffflags {
t=()
for(f in a b c e m n w) {
flagname=flag$f
if(~ $$flagname 1)
t=(-$f $t)
}
echo $t
}
fn ysearch {
if(~ $1 /*)
file=$1
if not
file=`{pwd}^/$1
if(test -f $file)
prfile $file
if not
echo history: warning: $file does not exist >[1=2]
old=()
2024-07-18 16:49:31 +00:00
list $file |
sed 's/\(([^ ]*) *([^ ]*) *([^ ]*)\)/\1\2\3/p' |
awk '"/n/'$dump/$since'" <= $2 {next}
$1 != qid {
qid=$1
gsub($1"[ \t]+", "")
print}' |
while(new=`$nl{read}){
prfile $new
if (~ $flagD 1 && ~ $#old 1)
diff `{diffflags} $new $old
old=$new
}
}
2024-07-18 16:49:31 +00:00
flagfmt='D,a,b,f,c,e,m,n,w,u,t:tag tag,d:dump,s since'
args='[ -Dabcemnw ] [ -uf ] [ -d dumpfilesystem ] [ -s yyyymmdd ] files ...'
if(! ifs=() eval `{aux/getflags $*} ||
~ $#* 0 ||
! ~ $#dump 0 && ! ~ $#dump 1 ||
! ~ $#flags 0 && ! ~ $#flags 1) {
aux/usage
exit usage
}
if(~ $#dump 0)
dump=dump
2024-07-18 16:49:31 +00:00
if(~ $#tag 0)
tag=main
if(~ $#flags 0)
flags=`{date -f 'YYYYMMDD'}
if(~ $#flagu 1)
flagu=-u
2024-07-18 16:49:31 +00:00
# probably gefs
if(test -e /n/$dump/adm){
fn list { ls -Qqr /n/$dump/$tag@day.*/$1 >[2] /dev/null }
since=`{date -f '[main@day.]YYYY.MM.DD[_]hh:mm:ss' `{seconds -f 'YYYYMMDD' $flags}}
}
if not {
fn list { ls -Qqr /n/$dump/*/*/$1 >[2] /dev/null }
since=`{date -f 'YYYY\/MMDD' `{seconds -f 'YYYYMMDD' $flags}}
}
9fs $dump
for(arg in $*)
ysearch $arg