From 3442f8755f0578ce155287ea73e8d98837e33254 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Thu, 12 Sep 2024 03:37:00 +0100 Subject: [PATCH] checkpoint: bash profile now fully managed --- bash/profile.gotmpl | 2 +- hosts/falcon.json | 53 +++++++++++++++++++++++++++++++++++++-- hosts/sparrow.json | 1 + magefiles/bash_profile.go | 19 ++++++++++++++ magefiles/config.go | 1 + 5 files changed, 73 insertions(+), 3 deletions(-) diff --git a/bash/profile.gotmpl b/bash/profile.gotmpl index 2569e84..7d4f403 100644 --- a/bash/profile.gotmpl +++ b/bash/profile.gotmpl @@ -10,7 +10,7 @@ {{ print "" }} ### Add {{ $sessionPath.Description }} to PATH if ! [[ "${PATH}" =~ {{ $fullPath }} ]]; then - export PATH={{ $fullPath}}:${PATH} + export PATH={{ $fullPath}}:${PATH} fi {{- end -}} {{ print "" }} diff --git a/hosts/falcon.json b/hosts/falcon.json index a8d0ba6..4166702 100644 --- a/hosts/falcon.json +++ b/hosts/falcon.json @@ -1,15 +1,64 @@ { "bashProfile": { "manage": true, + "filename": ".bashrc", "sessionPaths": [ { - "path": ".local/goblin", - "description": "the directory of go binaries" + "path": ".local/software/element-desktop/bin", + "description": "Element" + }, + { + "path": ".local/software/firefox/bin", + "description": "Firefox" + }, + { + "path": ".local/software/go/bin", + "description": "Go" + }, + { + "path": ".local/software/lua/bin", + "description": "Lua" + }, + { + "path": ".local/software/lua-language-server/bin", + "description": "the Lua Language Server" + }, + { + "path": ".local/software/luarocks/bin", + "description": "Luarocks" + }, + { + "path": ".local/software/neovim/bin", + "description": "Neovim" + }, + { + "path": ".local/software/node/bin", + "description": "Node" + }, + { + "path": ".local/software/pulumi/bin", + "description": "Pulumi" + }, + { + "path": ".local/software/radicle/bin", + "description": "Radicle" + }, + { + "path": ".local/software/ruby/bin", + "description": "Ruby" + }, + { + "path": ".local/bin", + "description": "the local bin directory" }, { "path": "Applications", "description": "the AppImage directory" }, + { + "path": ".local/goblin", + "description": "the local gobin directory" + }, { "path": ".local/scripts", "description": "the directory of custom scripts" diff --git a/hosts/sparrow.json b/hosts/sparrow.json index 026db54..e7d7e99 100644 --- a/hosts/sparrow.json +++ b/hosts/sparrow.json @@ -1,6 +1,7 @@ { "bashProfile": { "manage": true, + "filename": ".bash_profile", "aliases": {}, "commands": [ { diff --git a/magefiles/bash_profile.go b/magefiles/bash_profile.go index e26bd5e..35c0fd9 100644 --- a/magefiles/bash_profile.go +++ b/magefiles/bash_profile.go @@ -4,6 +4,8 @@ package main import ( "fmt" + "os" + "path/filepath" "text/template" ) @@ -12,8 +14,14 @@ func BashProfile() error { const ( bashProfileTemplateFile string = "bash/profile.gotmpl" managedBashProfile string = "managed/bash_profile" + defaultFilename string = ".bash_profile" ) + homeDirectory, err := os.UserHomeDir() + if err != nil { + return fmt.Errorf("unable to get the user's home configuration directory: %w", err) + } + config, err := newConfig() if err != nil { return fmt.Errorf("unable to load the configuration: %w", err) @@ -31,5 +39,16 @@ func BashProfile() error { return fmt.Errorf("unable to generate the Bash Profile: %w", err) } + filename := config.BashProfile.Filename + if filename == "" { + filename = defaultFilename + } + + symlinkPath := filepath.Join(homeDirectory, filename) + + if err := ensureSymlink(managedBashProfile, symlinkPath); err != nil { + return err + } + return nil } diff --git a/magefiles/config.go b/magefiles/config.go index 2742ef4..f974bf2 100644 --- a/magefiles/config.go +++ b/magefiles/config.go @@ -36,6 +36,7 @@ type configGitUser struct { type configBashProfile struct { Manage bool `json:"manage"` + Filename string `json:"filename"` SessionPaths []configBashProfileSessionPath `json:"sessionPaths"` XdgDirectories map[string]string `json:"xdgDirectories"` EnvironmentVariables map[string]string `json:"environmentVariables"`