Skip to content

Instantly share code, notes, and snippets.

@kuniyoshi
Created July 16, 2016 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuniyoshi/15a1f9163442ad7cbdecc879cc7b744d to your computer and use it in GitHub Desktop.
Save kuniyoshi/15a1f9163442ad7cbdecc879cc7b744d to your computer and use it in GitHub Desktop.
その辺にあるこのファイルが見たい
#!/usr/bin/env perl -s
use 5.10.0;
use utf8;
use strict;
use warnings;
our $ext;
our $d;
our $h;
my $name = shift;
die usage( )
if $h;
if ( defined $ext ) {
$name = "$name.$ext";
}
else {
$name = "$name.*";
}
my $directory = defined $d ? $d : q{.};
chomp( my @files = `find $directory -name '$name'` );
if ( @files > 1 ) {
warn "Several files found\n";
warn map { $_, "\n" } @files;
exit;
}
if ( !@files ) {
warn "No file[$name] found.\n";
exit;
}
my @args = ( ( $ENV{PAGER} || "less" ), $files[0] );
warn "Show file:\t$files[0]\n";
exec { $args[0] } @args;
sub usage {
return <<END_USAGE;
usage: $0 [-ext=<extension>] [-d=<directory>] <filename>
extension: specifies extension to show
directory: specifies to search from where
filename: name of file which is wanted to show
END_USAGE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment