From 6371fdd6eaf706a51369b096071ac2e5969f8f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 15 Jun 2021 08:10:01 +0200 Subject: Improve 'path' subroutine --- dwim | 6 ++++-- 1 file 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 -- cgit v1.2.3