1
0
Fork 0
mirror of https://github.com/Luzifer/short_path.git synced 2024-11-08 16:10:00 +00:00
short_path/main.go
Knut Ahlers 824f831458
Initial version
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2017-11-18 14:52:41 +01:00

33 lines
456 B
Go

package main
import (
"fmt"
"os"
"strings"
homedir "github.com/mitchellh/go-homedir"
)
func main() {
cur, err := os.Getwd()
if err != nil {
panic(err)
}
home, err := homedir.Dir()
if err != nil {
panic(err)
}
// Shorten homedir
cur = strings.Replace(cur, home, "~", 1)
out := strings.Split(cur, "/")
for i := 0; i < len(out)-2; i++ {
if len(out[i]) > 0 {
out[i] = string(out[i][0])
}
}
fmt.Print(strings.Join(out, "/"))
}