checkpoint: rendering the bash_profile file (not symlinked yet)

This commit is contained in:
Dan Anglin 2024-09-11 07:54:13 +01:00
parent cef88ba317
commit 9c88e62a6b
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
4 changed files with 209 additions and 12 deletions

52
bash/profile.gotmpl Normal file
View file

@ -0,0 +1,52 @@
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# Environment section
## Session Paths - These will be added to PATH
{{- range $sessionPath := .BashProfile.SessionPaths -}}
{{- $fullPath := printf "%s/%s" (env "HOME") $sessionPath.Path -}}
{{ print "" }}
{{ print "" }}
### Add {{ $sessionPath.Description }} to PATH
if ! [[ "${PATH}" =~ {{ $fullPath }} ]]; then
export PATH={{ $fullPath}}:${PATH}
fi
{{- end -}}
{{ print "" }}
{{ print "" }}
## XDG Directories
{{ print "" }}
{{- range $key, $value := .BashProfile.XdgDirectories -}}
{{ print "" }}
export {{ $key }}="{{ $value }}"
{{- end -}}
{{ print "" }}
{{ print "" }}
## Extra Environment variables
{{ print "" }}
{{- range $key, $value := .BashProfile.EnvironmentVariables -}}
{{ print "" }}
export {{ $key }}="{{ $value }}"
{{- end -}}
{{ print "" }}
{{ print "" }}
# Aliases
{{ print "" }}
{{- range $key, $value := .BashProfile.Aliases -}}
{{ print "" }}
alias {{ $key }}="{{ $value }}"
{{- end -}}
{{ print "" }}
{{ print "" }}
# Prompt
# External Sources
# Commands
{{ print "" }}
{{- range $command := .BashProfile.Commands -}}
{{ print "" }}
## {{ $command.Description }}
{{ $command.Command }}
{{- end -}}

View file

@ -1,9 +1,110 @@
{
"applicationConfigurations": [
"alacritty",
"amfora",
"git",
"lf",
"logrotate",
"tmux",
"user-dirs.dirs",
"user-dirs.locale",
"zk"
],
"bashProfile": {
"manage": true,
"sessionPaths": [
{
"path": ".local/goblin",
"description": "the directory of go binaries"
},
{
"path": "Applications",
"description": "the AppImage directory"
},
{
"path": ".local/scripts",
"description": "the directory of custom scripts"
}
],
"xdgDirectories": {
"XDG_CACHE_HOME": "${HOME}/.local/cache",
"XDG_CONFIG_HOME": "${HOME}/.local/config",
"XDG_DATA_HOME": "${HOME}/.local/share",
"XDG_STATE_HOME": "${HOME}/.local/state"
},
"environmentVariables": {
"LOG_HOME": "${XDG_STATE_HOME}/logs",
"DOCKER_CONFIG": "${XDG_CONFIG_HOME}/docker",
"GPG_TTY": "$(tty)",
"GNUPGHOME": "${XDG_DATA_HOME}/gnupg",
"GOPATH": "${XDG_DATA_HOME}/go",
"GOROOT": "${HOME}/.local/software/go",
"GOBIN": "${HOME}/.local/goblin",
"GOOS": "linux",
"GOARCH": "amd64",
"CGO_ENABLED": "0",
"MAGEFILE_CACHE": "${XDG_CACHE_HOME}/magefile",
"MAGEFILE_ENABLE_COLOR": "true",
"HISTFILE": "${XDG_STATE_HOME}/bash/history",
"HISTCONTROL": "ignoreboth",
"HISTFILESIZE": "10000",
"HISTSIZE": "1000",
"HISTTIMEFORMAT": "%d/%m/%y %T: ",
"KUBECONFIG": "${XDG_CONFIG_HOME}/kube/config",
"LESSHISTFILE": "${XDG_STATE_HOME}/less/history",
"MINIKUBE_HOME": "${XDG_DATA_HOME}/minikube",
"BROWSER": "firefox",
"EDITOR": "nvim",
"TERMINAL": "st",
"LANG": "en_GB.UTF-8",
"MANPAGER": "nvim +Man!",
"PULUMI_SKIP_UPDATE_CHECK": "true",
"PULUMI_HOME": "${XDG_DATA_HOME}/pulumi",
"RAD_HOME": "${XDG_DATA_HOME}/radicle",
"TERMINFO": "${XDG_DATA_HOME}/terminfo",
"TERMINFO_DIRS": "${TERMINFO}:/usr/share/terminfo",
"VAGRANT_HOME": "${XDG_DATA_HOME}/vagrant"
},
"aliases": {
"ls": "ls --color=auto",
"ll": "ls -laF",
"la": "ls -A",
"l": "ls -CF",
"rm": "rm -i",
"mv": "mv -i",
"cp": "cp -i",
"grep": "grep --color=auto",
"fgrep": "fgrep --color=auto",
"egrep": "egrep --color=auto",
"systemctl": "sudo systemctl",
"journalctl": "sudo journalctl",
"pwgen": "pwgen -s -c -n",
"dc": "docker-compose",
"vim": "nvim",
"view": "nvim -R",
"vimdiff": "nvim -d",
"freeflow": "enbas --config-dir ${XDG_CONFIG_HOME}/enbas/free-flow",
"g": "git",
"k": "kubectl",
"pass": "PASSWORD_STORE_DIR=${XDG_DATA_HOME}/pass pass"
},
"commands": [
{
"command": "shopt -s histappend",
"description": "Append to the history file, don't overwrite it."
},
{
"command": "set -o vi",
"description": "Activate vi mode."
}
]
},
"directories": {
"useDefaultDirectories": true,
"includeXDGDirectories": true,
"additionalDirectories": [
".local/goblin",
".local/share/go",
".local/software",
"Certificates",
"Docker",
@ -16,17 +117,6 @@
"Projects"
]
},
"applicationConfigurations": [
"alacritty",
"amfora",
"git",
"lf",
"logrotate",
"tmux",
"user-dirs.dirs",
"user-dirs.locale",
"zk"
],
"git": {
"gpgSign": true,
"user": {

35
magefiles/bash_profile.go Normal file
View file

@ -0,0 +1,35 @@
//go:build mage
package main
import (
"fmt"
"text/template"
)
// BashProfile manages the user's Bash Profile using their configuration and the Bash Profile template.
func BashProfile() error {
const (
bashProfileTemplateFile string = "bash/profile.gotmpl"
managedBashProfile string = "managed/bash_profile"
)
config, err := newConfig()
if err != nil {
return fmt.Errorf("unable to load the configuration: %w", err)
}
if !config.BashProfile.Manage {
return nil
}
funcMap := template.FuncMap{
"env": env,
}
if err := renderTemplate(config, bashProfileTemplateFile, managedBashProfile, funcMap); err != nil {
return fmt.Errorf("unable to generate the Bash Profile: %w", err)
}
return nil
}

View file

@ -11,8 +11,9 @@ import (
)
type config struct {
Directories configDirectories `json:"directories"`
ApplicationConfigurations []string `json:"applicationConfigurations"`
BashProfile configBashProfile `json:"bashProfile"`
Directories configDirectories `json:"directories"`
Git configGit `json:"git"`
}
@ -33,6 +34,25 @@ type configGitUser struct {
SigningKey string `json:"signingKey"`
}
type configBashProfile struct {
Manage bool `json:"manage"`
SessionPaths []configBashProfileSessionPath `json:"sessionPaths"`
XdgDirectories map[string]string `json:"xdgDirectories"`
EnvironmentVariables map[string]string `json:"environmentVariables"`
Aliases map[string]string `json:"aliases"`
Commands []configBashProfileCommand `json:"commands"`
}
type configBashProfileSessionPath struct {
Path string `json:"path"`
Description string `json:"description"`
}
type configBashProfileCommand struct {
Command string `json:"command"`
Description string `json:"description"`
}
func newConfig() (config, error) {
cfg := defaultConfig()