SSH startup eval: ssh-agent add key to keychain, use .shell dict for commonrc template

This commit is contained in:
2024-10-18 17:00:04 -05:00
parent c438e27536
commit 2d3694aa7a
4 changed files with 30 additions and 11 deletions

View File

@@ -1,3 +1,5 @@
# Detect chassis type (likely: laptop | desktop | container)
# https://www.freedesktop.org/software/systemd/man/latest/hostnamectl.html#chassis%20%5BTYPE%5D
{{- $chassisType := "desktop" }}
{{- if eq .chezmoi.os "darwin" }}
{{- if contains "MacBook" (output "sysctl" "-n" "hw.model") }}
@@ -11,6 +13,7 @@
{{- $chassisType = (output "powershell.exe" "-NoProfile" "-NonInteractive" "-Command" "if ((Get-CimInstance -Class Win32_Battery | Measure-Object).Count -gt 0) { Write-Output 'laptop' } else { Write-Output 'desktop' }") | trim }}
{{- end }}
# Detect number of CPU cores and threads
{{- $cpuCores := 1 }}
{{- $cpuThreads := 1 }}
{{- if eq .chezmoi.os "darwin" }}
@@ -24,15 +27,22 @@
{{- $cpuThreads = (output "powershell.exe" "-NoProfile" "-NonInteractive" "-Command" "(Get-CimInstance -ClassName 'Win32_Processor').NumberOfLogicalProcessors") | trim | atoi }}
{{- end -}}
# Detect if running in WSL
{{- $wsl := true -}}
{{- if eq .chezmoi.os "linux" -}}
{{- $wsl = (.chezmoi.kernel.osrelease | lower | contains "microsoft") -}}
{{- end -}}
[merge]
command = "bash"
args = [
"-c",
"cp {{ "{{" }} .Target {{ "}}" }} {{ "{{" }} .Target {{ "}}" }}.base && code --new-window --wait --merge {{ "{{" }} .Destination {{ "}}" }} {{ "{{" }} .Target {{ "}}" }} {{ "{{" }} .Target {{ "}}" }}.base {{ "{{" }} .Source {{ "}}" }}",
"-c",
"cp {{ "{{" }} .Target {{ "}}" }} {{ "{{" }} .Target {{ "}}" }}.base && code --new-window --wait --merge {{ "{{" }} .Destination {{ "}}" }} {{ "{{" }} .Target {{ "}}" }} {{ "{{" }} .Target {{ "}}" }}.base {{ "{{" }} .Source {{ "}}" }}",
]
[data]
chassis = "{{ $chassisType }}"
wsl = {{ $wsl }}
[data.cpu]
cores = {{ $cpuCores }}
@@ -40,8 +50,8 @@ args = [
encryption = "age"
[age]
identity = "{{ .chezmoi.homeDir }}/key.txt"
recipient = "age1s3ctpj9lafl6qwyvd89sn448us7gdzd53d8yyhsc7zny78c0k4sqerrkze"
identity = "{{ .chezmoi.homeDir }}/key.txt"
recipient = "age1s3ctpj9lafl6qwyvd89sn448us7gdzd53d8yyhsc7zny78c0k4sqerrkze"
[hooks.read-source-state.pre]
command = "{{ .chezmoi.sourceDir }}/.install-password-manager.sh"
command = "{{ .chezmoi.sourceDir }}/.install-password-manager.sh"

View File

@@ -12,9 +12,9 @@ export OPENAI_API_KEY="{{ (rbw "OpenAI - chatgpt-cli Key").data.password }}"
# hishtory
export HISHTORY_SERVER="https://hsh.{{ template "keys.tmpl" "privateDomain" }}"
export PATH="$PATH:$HOME/.hishtory"
{{ if eq . "zsh" -}}
{{ if eq .shell "zsh" -}}
source $HOME/.hishtory/config.zsh
{{ else if eq . "bash" -}}
{{ else if eq .shell "bash" -}}
source $HOME/.hishtory/config.sh
{{- else -}}
{{ fail "Unexpected shell." }}
@@ -29,7 +29,11 @@ export PATH="$HOME/.local/share/bob/nvim-bin:$PATH" # Bob, the Neovim package m
. "$HOME/.cargo/env" # Rustup + Cargo + Cargo-installed tools
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" # Brew
command -v rbenv &> /dev/null && eval "$(rbenv init -)" # rbenv for Ruby
command -v chatgpt &> /dev/null && . <(chatgpt --set-completions {{ . -}}) # chatgpt completions
command -v chatgpt &> /dev/null && . <(chatgpt --set-completions {{ .shell -}}) # chatgpt completions
{{ if eq .shell "bash" -}}
. "$HOME/.asdf/asdf.sh"
. "$HOME/.asdf/completions/asdf.bash"
{{- end }}
# pyenv, python version manager
export PYENV_ROOT="$HOME/.pyenv"
@@ -88,4 +92,9 @@ fi
# export EDITOR='micro'
# else
# export EDITOR='nvim'
# fi
# fi
# If WSL, add SSH key on startup (once per WSL start)
{{- if .data.wsl }}
eval `keychain --quiet --eval --agents ssh ~/.ssh/id_rsa`
{{ end }}

View File

@@ -98,5 +98,5 @@ if ! shopt -oq posix; then
fi
fi
{{ template "scripts/commonrc.sh.tmpl" "bash" }}
{{ template "scripts/commonrc.sh.tmpl" dict "data" . "shell" "bash" }}
{{ completion "bash" }}

View File

@@ -28,5 +28,5 @@ plugins=(git asdf yarn golang sudo zoxide bun node npm zsh-autosuggestions brew
source $ZSH/oh-my-zsh.sh
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh # configure with `p10k configure`
{{ template "scripts/commonrc.sh.tmpl" "zsh" }}
{{ template "scripts/commonrc.sh.tmpl" dict "data" . "shell" "zsh" }}
{{ completion "zsh" }}