updated git and svn scripts
[xrzperl.git] / viewdir
blob80fa8b7304a552e8aee9af3bc3e6aa7d133671ce
1 #!/usr/bin/perl -w
2 ###APPNAME: viewdir
3 ###APPAUTHOR: xiaoranzzz
4 ###APPDATE: Thu Feb 14 14:30:06 2008
5 ###APPVER: 0.1
6 ###APPDESC: View Directory
7 ###APPUSAGE: (directory)
8 ###APPEXAMPLE: viewdir /usr/share/doc/fvwm-crystal
9 ###APPOPTION:
10 use strict;
12 foreach(@ARGV){
13 exit (system("plhelp",$0,@ARGV)) if($_ eq "-h" || $_ eq "--help");
16 my $docdir=shift;
17 $docdir = "." unless $docdir;
18 my $gzview = "zless";
19 my $bzview = "bzless";
20 my $view = "less";
22 chdir($docdir) or die("$!\n");
24 my @docs;
25 foreach(glob("*")) {
26 if(-f "$_") {
27 push(@docs,$_);
31 sub listDoc {
32 my $basedir=shift;
33 my @files=@_;
34 print STDERR $basedir,"\n";
35 my $r = system("ui-select-list","Document list ($basedir:)",@files);
36 return $r>>8;
39 sub viewdoc($) {
40 my $file = $_[0];
41 if(! -f "$file" ){
42 print STDERR "File not exist:$file\n";
44 else {
45 $file =~ m/\.([^.]*$)/;
46 my $ext = $1 ? $1 : "";
47 my $cmd = $view;
48 if($ext eq "html") {
49 $cmd = "htmlview";
51 elsif($ext eq "gz") {
52 $cmd = $gzview;
54 elsif($ext eq "bz" || $ext eq "bz2") {
55 $cmd = $bzview
57 system($cmd,$file);
61 my $choice;
62 while($choice = listDoc($docdir,@docs)) {
63 viewdoc($docdir . "/" . $docs[$choice-1]);