my dotz
2
fork

Configure Feed

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

simplify prompt

+37 -33
+37 -33
bin/prompt.go
··· 6 6 "os/exec" 7 7 "path/filepath" 8 8 "strings" 9 - "time" 10 9 ) 11 10 12 - // getRepoRoot returns the full path to the root 13 - // of the closest git dir 14 - func gitTopLevel() string { 15 - path, err := exec.Command("git", "rev-parse", "--show-toplevel").Output() 11 + func main() { 12 + wd, err := os.Getwd() 16 13 if err != nil { 17 - // assume the error means there's no git 18 - // dir above us 19 - return "/" 14 + fmt.Print("$ ") 15 + return 20 16 } 21 - return strings.TrimSpace(string(path)) 22 - } 23 - 24 - func resolveEmoji(hostname string) string { 25 - emoji := "💀" 26 - if hostname == "zora" { 27 - emoji = "🌸" 28 - } else if hostname == "nostromo" { 29 - emoji = "🛸" 17 + cwd, err := filepath.EvalSymlinks(wd) 18 + if err != nil { 19 + fmt.Print("$ ") 20 + return 30 21 } 31 - return emoji 32 - } 33 - 34 - func main() { 35 - wd, _ := os.Getwd() 36 - cwd, _ := filepath.EvalSymlinks(wd) 37 - host, _ := os.Hostname() 38 - home := os.Getenv("HOME") 39 - now := time.Now().Format("15:04:05") 40 - emoji := resolveEmoji(host) 41 - fmt.Printf("%s %s ", now, emoji) 22 + emoji := resolveEmoji() 42 23 43 24 var promptRoot string 44 - gitTop := gitTopLevel() 45 - if gitTop == home { 25 + gitRoot := gitRoot() 26 + if gitRoot == os.Getenv("HOME") { 46 27 promptRoot = "~" 47 28 } else { 48 - promptRoot = filepath.Base(gitTop) 29 + promptRoot = filepath.Base(promptRoot) 49 30 } 50 31 // subtract the git toplevel "/home/j3s" 51 32 // from the cwd "/home/j3s/code/nongitdir" 52 33 // to get the suffix "/code/nongitdir" 53 34 // os.cwd gets the symlink, git does not 54 - suffix := cwd[len(gitTop):] 55 - fmt.Printf("%s", promptRoot) 35 + suffix := cwd[len(gitRoot):] 36 + fmt.Printf("%s %s", emoji, promptRoot) 56 37 57 38 var parts []string 58 39 parts = strings.Split(suffix, "/") ··· 68 49 } 69 50 } 70 51 } 52 + 53 + func resolveEmoji() string { 54 + hostname, _ := os.Hostname() 55 + if hostname == "zora" { 56 + return "🌸" 57 + } 58 + if hostname == "nostromo" { 59 + return "🌹" 60 + } 61 + return "💀" 62 + } 63 + 64 + // getRepoRoot returns the full path to the root 65 + // of the closest git dir 66 + func gitRoot() string { 67 + path, err := exec.Command("git", "rev-parse", "--show-toplevel").Output() 68 + if err != nil { 69 + // assume the error means there's no git 70 + // dir above us, or git isn't installed. 71 + return "/" 72 + } 73 + return strings.TrimSpace(string(path)) 74 + }