Skip to content

Commit

Permalink
y.pm: add which cmd to find file path
Browse files Browse the repository at this point in the history
  • Loading branch information
samyk committed Oct 12, 2024
1 parent 12dd1fc commit de13f6c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions y.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,19 @@ sub env_path
return $ENV{"${cmd}_PATH"} || $ENV{lc($cmd) . "_PATH"} || $ENV{uc($cmd) . "_PATH"} || ($nodefault ? undef : $cmd);
}

# find path of file
sub which
{
my $file = shift;
return if !length $file;

my @paths = split /:/, $ENV{PATH};
for my $path (@paths)
{
return "$path/$file" if -e "$path/$file";
}
}

# is stdin piped in?
# useful for scripts that can be used in a pipeline
sub piped
Expand Down

0 comments on commit de13f6c

Please sign in to comment.