From 9eb7128e01ba9dd1c13fe2347857e9748b2286eb Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sun, 5 Mar 2023 13:42:47 -0800 Subject: [PATCH] xmain: Add RelPath --- xmain/xmain.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xmain/xmain.go b/xmain/xmain.go index f40973f..783bb8b 100644 --- a/xmain/xmain.go +++ b/xmain/xmain.go @@ -9,6 +9,7 @@ import ( "io" "os" "os/signal" + "path/filepath" "syscall" "time" @@ -179,3 +180,11 @@ func (ms *State) WritePath(fp string, p []byte) error { } return os.WriteFile(fp, p, 0644) } + +func (ms *State) RelPath(fp string) string { + rel, err := filepath.Rel(ms.PWD, fp) + if err != nil { + return fp + } + return rel +}