Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/commands/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var cmdDocker = &cobra.Command{
Aliases: []string{"dock"},
Short: "Docker command aliases",
Run: func(cmd *cobra.Command, _ []string) {
cmd.Help()
_ = cmd.Help()
},
}

Expand Down
44 changes: 10 additions & 34 deletions cli/commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,21 @@ import (
"github.com/spf13/cobra"
)

type component struct {
Name string
Description string
Alias string
}

var components = []component{
{"bin", "Installs ~/bin/* commands", ""},
{"git", "Installs git extensions", ""},
{"home", "Installs ~/.* config files", ""},
{"zsh", "Installs zsh config files", ""},
{"fonts", "Installs fonts", ""},
{"homebrew", "Installs Homebrew dependencies", "brew"},
{"npm", "Installs npm packages", ""},
{"languages", "Installs asdf & languages", ""},
{"vim", "Installs vim config", ""},
{"hammerspoon", "Installs hammerspoon configuration", "hs"},
{"osx", "Installs OSX configuration", ""},
{"agents", "Installs agent skills (Claude Code + Codex)", ""},
}

func componentNames() []string {
names := make([]string, len(components))
for i, c := range components {
names[i] = c.Name
}
return names
}

var cmdInstall = &cobra.Command{
Use: "install",
Short: "Installs configuration",
Run: func(cmd *cobra.Command, args []string) {
if len(args) > 0 {
cmd.Help()
_ = cmd.Help()
os.Exit(1)
}

items := append([]string{"all"}, componentNames()...)
components := install.Components()
names := make([]string, len(components))
for i, c := range components {
names[i] = c.Name
}
items := append([]string{"all"}, names...)

prompt := promptui.Select{
Label: "Select component to install",
Expand Down Expand Up @@ -79,7 +55,7 @@ func init() {
},
)

for _, c := range components {
for _, c := range install.Components() {
var aliases []string
if c.Alias != "" {
aliases = []string{c.Alias}
Expand All @@ -105,7 +81,7 @@ func installAll() {
os.Exit(1)
}

for _, name := range componentNames() {
install.Call(name)
for _, c := range install.Components() {
install.Call(c.Name)
}
}
48 changes: 32 additions & 16 deletions cli/commands/install/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,40 @@ import (
"github.com/drn/dots/pkg/run"
)

// Component describes an installable component
type Component struct {
Name string
Description string
Alias string
Fn func()
}

// Components returns the ordered list of installable components.
// This is the single source of truth for the component registry.
func Components() []Component {
return []Component{
{"bin", "Installs ~/bin/* commands", "", Bin},
{"git", "Installs git extensions", "", Git},
{"home", "Installs ~/.* config files", "", Home},
{"zsh", "Installs zsh config files", "", Zsh},
{"fonts", "Installs fonts", "", Fonts},
{"homebrew", "Installs Homebrew dependencies", "brew", Homebrew},
{"npm", "Installs npm packages", "", Npm},
{"languages", "Installs asdf & languages", "", Languages},
{"vim", "Installs vim config", "", Vim},
{"hammerspoon", "Installs hammerspoon configuration", "hs", Hammerspoon},
{"osx", "Installs OSX configuration", "", Osx},
{"agents", "Installs agent skills (Claude Code + Codex)", "", Agents},
}
}

// Call - Call install command by name
func Call(command string) {
installers := map[string]func(){
"agents": Agents,
"bin": Bin,
"fonts": Fonts,
"git": Git,
"hammerspoon": Hammerspoon,
"home": Home,
"homebrew": Homebrew,
"languages": Languages,
"npm": Npm,
"osx": Osx,
"vim": Vim,
"zsh": Zsh,
}
if fn, ok := installers[command]; ok {
fn()
for _, c := range Components() {
if c.Name == command {
c.Fn()
return
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion cli/commands/install/vim.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func vimUpdatePlug() {
func vimUpdatePlugins() {
log.Info("Updating vim plugins:")
tempPath := "/tmp/vim-update-result"
os.Remove(tempPath)
_ = os.Remove(tempPath)
run.Silent(
"nvim -c \"%s\"",
strings.Join(
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var root = &cobra.Command{
Use: "dots",
Short: "The dots CLI manages your development environment dependencies",
Run: func(cmd *cobra.Command, _ []string) {
cmd.Help()
_ = cmd.Help()
},
}

Expand Down
2 changes: 1 addition & 1 deletion cli/commands/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var cmdSpinner = &cobra.Command{
Use: "spinner",
Short: "Runs simple CLI spinners",
Run: func(cmd *cobra.Command, _ []string) {
cmd.Help()
_ = cmd.Help()
},
}

Expand Down
4 changes: 3 additions & 1 deletion cli/config/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ func save(cfg *ini.File) {
log.Warning("Failed to create config directory: %s", err.Error())
return
}
cfg.SaveTo(configPath())
if err := cfg.SaveTo(configPath()); err != nil {
log.Warning("Failed to save config: %s", err.Error())
}
}

func config() *ini.File {
Expand Down
4 changes: 2 additions & 2 deletions cli/git/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func Create(branch string) bool {
}

// ResetHard - Hard resets to the specified address
func ResetHard(address string) {
run.Verbose("git reset --hard %s", address)
func ResetHard(address string) bool {
return run.Verbose("git reset --hard %s", address) == nil
}

// Delete - Deletes the specified branch
Expand Down
24 changes: 6 additions & 18 deletions cli/link/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,18 @@ import (

// Soft - Creates a soft link between input from and to arguments
func Soft(from string, to string) {
log.Info("Soft link: '%s' -> '%s'", path.Pretty(to), path.Pretty(from))

removeExisting(to)

// create soft link
err := os.Symlink(from, to)

// log errors
if err != nil {
log.Error(err.Error())
}
create("Soft", from, to, os.Symlink)
}

// Hard - Creates a hard link between input from and to arguments
func Hard(from string, to string) {
log.Info("Hard link: '%s' -> '%s'", path.Pretty(to), path.Pretty(from))
create("Hard", from, to, os.Link)
}

func create(label, from, to string, linkFn func(string, string) error) {
log.Info("%s link: '%s' -> '%s'", label, path.Pretty(to), path.Pretty(from))
removeExisting(to)

// create hard link
err := os.Link(from, to)

// log errors
if err != nil {
if err := linkFn(from, to); err != nil {
log.Error(err.Error())
}
}
Expand Down
20 changes: 14 additions & 6 deletions cmd/battery-percent/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ import (
)

func main() {
info := run.Capture("pmset -g ps")
info = strings.Split(info, "\n")[1]
// extract percent from pmset metadata
percent := strings.Fields(info)[2]
// remove trailing ;
percent = percent[:len(percent)-1]
lines := strings.Split(run.Capture("pmset -g ps"), "\n")
if len(lines) < 2 {
fmt.Println("0%")
return
}
fields := strings.Fields(lines[1])
if len(fields) < 3 {
fmt.Println("0%")
return
}
percent := fields[2]
if len(percent) > 0 {
percent = strings.TrimRight(percent, ";")
}
fmt.Println(percent)
}
1 change: 0 additions & 1 deletion cmd/battery-state/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

func main() {
info := run.Capture("pmset -g ps")
info = strings.Split(info, "\n")[0]
if strings.Contains(info, "AC Power") {
fmt.Println("charging")
} else {
Expand Down
15 changes: 13 additions & 2 deletions cmd/cpu/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,22 @@ import (

func main() {
info := run.Capture("sysctl -n vm.loadavg")
if len(info) < 4 {
fmt.Println("0%")
return
}
info = info[2 : len(info)-2]

// load averages [1 min, 5 min, 15 min]
averages := strings.Split(info, " ")
average, _ := strconv.ParseFloat(averages[0], 64)
if len(averages) == 0 {
fmt.Println("0%")
return
}
average, err := strconv.ParseFloat(averages[0], 64)
if err != nil {
fmt.Println("0%")
return
}

fmt.Printf("%v%%\n", math.Round(average))
}
13 changes: 7 additions & 6 deletions cmd/git-ancestor/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (
"github.com/drn/dots/pkg/run"
)

var maxAncestors = 100
var remote = baseRemote()
var dev = fmt.Sprintf("%s/dev", remote)
var master = fmt.Sprintf("%s/master", remote)
const maxAncestors = 100

func main() {
remote := baseRemote()
dev := fmt.Sprintf("%s/dev", remote)
master := fmt.Sprintf("%s/master", remote)

ancestors := ancestors()

if len(ancestors) < 2 {
Expand All @@ -28,7 +29,7 @@ func main() {
continue
}

identified := identify(branches)
identified := identify(branches, remote, dev, master)

// if a branch is identified, use it
if identified != "" {
Expand All @@ -41,7 +42,7 @@ func main() {
os.Exit(1)
}

func identify(branches []string) string {
func identify(branches []string, remote, dev, master string) string {
identified := ""

for _, branch := range branches {
Expand Down
Loading
Loading