From 3907f3c2b64729b81f1e4802b87fdb92a146c178 Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Wed, 18 Feb 2015 22:53:04 -0800 Subject: [PATCH] pkg/homedir: implement GetShortcutString() Signed-off-by: Ahmet Alp Balkan --- homedir/homedir.go | 9 +++++++++ homedir/homedir_test.go | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/homedir/homedir.go b/homedir/homedir.go index f0246e9..79d4431 100644 --- a/homedir/homedir.go +++ b/homedir/homedir.go @@ -14,3 +14,12 @@ func Get() string { } return os.Getenv("HOME") } + +// GetShortcutString returns the string that is shortcut to user's home directory +// in the native shell of the platform running on. +func GetShortcutString() string { + if runtime.GOOS == "windows" { + return "%USERPROFILE%" // be careful while using in format functions + } + return "~" +} diff --git a/homedir/homedir_test.go b/homedir/homedir_test.go index b89cbf7..7a95cb2 100644 --- a/homedir/homedir_test.go +++ b/homedir/homedir_test.go @@ -15,3 +15,10 @@ func TestGet(t *testing.T) { t.Fatalf("returned path is not absolute: %s", home) } } + +func TestGetShortcutString(t *testing.T) { + shortcut := GetShortcutString() + if shortcut == "" { + t.Fatal("returned shortcut string is empty") + } +}