aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-06-15 08:10:01 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-06-15 08:10:01 +0200
commit6371fdd6eaf706a51369b096071ac2e5969f8f48 (patch)
tree392d4f0d9ae9c56eda244a3acfbc74b236abbf09
parent0590c64260739c0736967b69654f89bee98ed5df (diff)
downloaddwim-6371fdd6eaf706a51369b096071ac2e5969f8f48.tar.gz
Improve 'path' subroutine
-rwxr-xr-xdwim6
1 files changed, 4 insertions, 2 deletions
diff --git a/dwim b/dwim
index 91ce5b8..b5fc6b0 100755
--- a/dwim
+++ b/dwim
@@ -137,8 +137,10 @@ sub path {
my $n = shift;
$n =~ s,^~([^/]+),/home/$1,;
$n =~ s,^~,/home/$ENV{USER},;
- return $n if $n =~ /^\// or $n =~ /^~/;
- return dir . "/$n";
+ goto done if $n =~ /^\// or $n =~ /^~/;
+ $n = dir . "/$n";
+done: chdir dirname($n);
+ return $n;
}
# take K => V and return environment variable K if defined, otherwise V