mirror of
https://github.com/Luzifer/short_path.git
synced 2024-11-08 16:10:00 +00:00
34 lines
456 B
Go
34 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, "/"))
|
||
|
}
|