small pixel drawing of a pufferfish dotfiles

Merge remote-tracking branch 'origin/master'
Jes Olson jolson@digitalocean.com
Tue, 14 Dec 2021 11:31:41 -0600
commit

60a75f1c12bcf558cde809de6a2e3a7fc0b4d84f

parent

55ed050c265e072d95632e1bc9ffaeeda3b3b99c

M .config/git/config.config/git/config

@@ -42,3 +42,5 @@ [includeIf "gitdir:~/howdocs/"]

path = ~/.config/git/config-work [pager] status = true +[url "git@github.internal.digitalocean.com:"] + insteadOf = https://github.internal.digitalocean.com/
M bin/prompt.gobin/prompt.go

@@ -3,28 +3,57 @@

import ( "fmt" "os" + "os/exec" + "path/filepath" "strings" "time" ) -func main() { - cwd, _ := os.Getwd() - host, _ := os.Hostname() +// getRepoRoot returns the full path to the root +// of the closest git dir +func getRepoRoot() string { + var rootPath string + + path, err := exec.Command("git", "rev-parse", "--show-toplevel").Output() + if err != nil { + rootPath = "~" + } else { + rootPath = strings.TrimSpace(string(path)) + } + return rootPath +} + +func resolveEmoji(hostname string) string { emoji := "💀" - if host == "zora" { + if hostname == "zora" { emoji = "🍣" - } else if host == "nostromo" { + } else if hostname == "nostromo" { emoji = "🛸" } + return emoji +} + +func main() { + cwd, _ := os.Getwd() + host, _ := os.Hostname() home := os.Getenv("HOME") - var parts []string - if strings.HasPrefix(cwd, home) { - cwd = "~" + cwd[len(home):] + now := time.Now().Format("15:04:05") + emoji := resolveEmoji(host) + fmt.Printf("%s %s ", now, emoji) + + gitRoot := getRepoRoot() + + var prefix string + if gitRoot == home { + prefix = "~" + } else { + prefix = filepath.Base(gitRoot) } - now := time.Now().Format("15:04:05") - fmt.Printf("[%s] %s%s ", now, emoji, host) + suffix := cwd[len(gitRoot):] + fmt.Printf("%s", prefix) - parts = strings.Split(cwd, "/") + var parts []string + parts = strings.Split(suffix, "/") for i, part := range parts { if i == len(parts)-1 { fmt.Printf("%s", part)
A bin/zora/docc-refresh

@@ -0,0 +1,14 @@

+#!/bin/sh + +app="$1" +contexts="bolt dash dust flux kiwi luca navy nova puff taro vega wolf" + +if [ -z "$app" ]; then + printf "%s\n" "app name required" + exit 1 +fi + +for i in $contexts; do + # vault login + docc --context "$i" update secret-sync -n chef "$app" --secret-auth token,$(cat ~/.vault-token) +done
A bin/zora/docc-restart

@@ -0,0 +1,14 @@

+#!/bin/sh + +app="$1" +contexts="bolt dash dust flux kiwi luca navy nova puff taro vega wolf" + +if [ -z "$app" ]; then + printf "%s\n" "app name required" + exit 1 +fi + +for i in $contexts; do + # vault login + docc --context "$i" -n chef restart "$app" +done
A bin/zora/regions

@@ -0,0 +1,7 @@

+#!/bin/sh + +filter="$1" + +for region in ams2 ams3 blr1 fra1 lon1 nbg1/nyc1 nyc2 nyc3 sfo1 sfo2 sfo3 sgp1 tor1; do + printf "%s\n" "$region" +done