Skip to content

Commit

Permalink
y.pm: add base64 funcs and env_path function
Browse files Browse the repository at this point in the history
  • Loading branch information
samyk committed Jan 16, 2024
1 parent 5296f39 commit b9547a9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions y.pm
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ sub html2text
}

# more easily b64 decode/encode
sub b64 { &base64 }
sub b64d { &decode_base64 }
sub b64e { &encode_base64 }
sub base64
{
return $_[0] =~ /^[A-Za-z0-9+\/\r\n]+={0,2}$/ ? decode_base64($_[0]) : encode_base64($_[0]);
Expand Down Expand Up @@ -697,6 +700,12 @@ sub cd
return chdir($_[0]);
}

# get path of something from env variable, otherwise use default
sub env_path
{
return $ENV{"$_[0]_PATH"} || $_[0];
}

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

0 comments on commit b9547a9

Please sign in to comment.