浏览代码

pkg/homedir: implement GetShortcutString()

Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
Ahmet Alp Balkan 10 年之前
父节点
当前提交
8ca37e4760
共有 2 个文件被更改,包括 16 次插入0 次删除
  1. 9 0
      pkg/homedir/homedir.go
  2. 7 0
      pkg/homedir/homedir_test.go

+ 9 - 0
pkg/homedir/homedir.go

@@ -14,3 +14,12 @@ func Get() string {
 	}
 	}
 	return os.Getenv("HOME")
 	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 "~"
+}

+ 7 - 0
pkg/homedir/homedir_test.go

@@ -15,3 +15,10 @@ func TestGet(t *testing.T) {
 		t.Fatalf("returned path is not absolute: %s", home)
 		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")
+	}
+}