my dotz
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

make prompt aware of git roots

+40 -11
+40 -11
bin/prompt.go
··· 3 3 import ( 4 4 "fmt" 5 5 "os" 6 + "os/exec" 7 + "path/filepath" 6 8 "strings" 7 9 "time" 8 10 ) 9 11 10 - func main() { 11 - cwd, _ := os.Getwd() 12 - host, _ := os.Hostname() 12 + // getRepoRoot returns the full path to the root 13 + // of the closest git dir 14 + func getRepoRoot(pwd string) string { 15 + var rootPath string 16 + 17 + path, err := exec.Command("git", "rev-parse", "--show-toplevel").Output() 18 + if err != nil { 19 + rootPath = "~" 20 + } else { 21 + rootPath = strings.TrimSpace(string(path)) 22 + } 23 + return rootPath 24 + } 25 + 26 + func resolveEmoji(hostname string) string { 13 27 emoji := "💀" 14 - if host == "zora" { 28 + if hostname == "zora" { 15 29 emoji = "🍣" 16 - } else if host == "nostromo" { 30 + } else if hostname == "nostromo" { 17 31 emoji = "🛸" 18 32 } 33 + return emoji 34 + } 35 + 36 + func main() { 37 + cwd, _ := os.Getwd() 38 + host, _ := os.Hostname() 19 39 home := os.Getenv("HOME") 20 - var parts []string 21 - if strings.HasPrefix(cwd, home) { 22 - cwd = "~" + cwd[len(home):] 40 + now := time.Now().Format("15:04:05") 41 + emoji := resolveEmoji(host) 42 + fmt.Printf("%s %s ", now, emoji) 43 + 44 + gitRoot := getRepoRoot(cwd) 45 + 46 + var prefix string 47 + if gitRoot == home { 48 + prefix = "~" 49 + } else { 50 + prefix = filepath.Base(gitRoot) 23 51 } 24 - now := time.Now().Format("15:04:05") 25 - fmt.Printf("[%s] %s%s ", now, emoji, host) 52 + suffix := cwd[len(gitRoot):] 53 + fmt.Printf("%s", prefix) 26 54 27 - parts = strings.Split(cwd, "/") 55 + var parts []string 56 + parts = strings.Split(suffix, "/") 28 57 for i, part := range parts { 29 58 if i == len(parts)-1 { 30 59 fmt.Printf("%s", part)
bin/x86_64/prompt

This is a binary file and will not be displayed.