Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
| ... | ... |
@@ -14,3 +14,12 @@ func Get() string {
|
| 14 | 14 |
} |
| 15 | 15 |
return os.Getenv("HOME")
|
| 16 | 16 |
} |
| 17 |
+ |
|
| 18 |
+// GetShortcutString returns the string that is shortcut to user's home directory |
|
| 19 |
+// in the native shell of the platform running on. |
|
| 20 |
+func GetShortcutString() string {
|
|
| 21 |
+ if runtime.GOOS == "windows" {
|
|
| 22 |
+ return "%USERPROFILE%" // be careful while using in format functions |
|
| 23 |
+ } |
|
| 24 |
+ return "~" |
|
| 25 |
+} |
| ... | ... |
@@ -15,3 +15,10 @@ func TestGet(t *testing.T) {
|
| 15 | 15 |
t.Fatalf("returned path is not absolute: %s", home)
|
| 16 | 16 |
} |
| 17 | 17 |
} |
| 18 |
+ |
|
| 19 |
+func TestGetShortcutString(t *testing.T) {
|
|
| 20 |
+ shortcut := GetShortcutString() |
|
| 21 |
+ if shortcut == "" {
|
|
| 22 |
+ t.Fatal("returned shortcut string is empty")
|
|
| 23 |
+ } |
|
| 24 |
+} |