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" }} {{- $chassisType := "desktop" }}
{{- if eq .chezmoi.os "darwin" }} {{- if eq .chezmoi.os "darwin" }}
{{- if contains "MacBook" (output "sysctl" "-n" "hw.model") }} {{- 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 }} {{- $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 }} {{- end }}
# Detect number of CPU cores and threads
{{- $cpuCores := 1 }} {{- $cpuCores := 1 }}
{{- $cpuThreads := 1 }} {{- $cpuThreads := 1 }}
{{- if eq .chezmoi.os "darwin" }} {{- if eq .chezmoi.os "darwin" }}
@@ -24,6 +27,12 @@
{{- $cpuThreads = (output "powershell.exe" "-NoProfile" "-NonInteractive" "-Command" "(Get-CimInstance -ClassName 'Win32_Processor').NumberOfLogicalProcessors") | trim | atoi }} {{- $cpuThreads = (output "powershell.exe" "-NoProfile" "-NonInteractive" "-Command" "(Get-CimInstance -ClassName 'Win32_Processor').NumberOfLogicalProcessors") | trim | atoi }}
{{- end -}} {{- end -}}
# Detect if running in WSL
{{- $wsl := true -}}
{{- if eq .chezmoi.os "linux" -}}
{{- $wsl = (.chezmoi.kernel.osrelease | lower | contains "microsoft") -}}
{{- end -}}
[merge] [merge]
command = "bash" command = "bash"
args = [ args = [
@@ -33,6 +42,7 @@ args = [
[data] [data]
chassis = "{{ $chassisType }}" chassis = "{{ $chassisType }}"
wsl = {{ $wsl }}
[data.cpu] [data.cpu]
cores = {{ $cpuCores }} cores = {{ $cpuCores }}

View File

@@ -12,9 +12,9 @@ export OPENAI_API_KEY="{{ (rbw "OpenAI - chatgpt-cli Key").data.password }}"
# hishtory # hishtory
export HISHTORY_SERVER="https://hsh.{{ template "keys.tmpl" "privateDomain" }}" export HISHTORY_SERVER="https://hsh.{{ template "keys.tmpl" "privateDomain" }}"
export PATH="$PATH:$HOME/.hishtory" export PATH="$PATH:$HOME/.hishtory"
{{ if eq . "zsh" -}} {{ if eq .shell "zsh" -}}
source $HOME/.hishtory/config.zsh source $HOME/.hishtory/config.zsh
{{ else if eq . "bash" -}} {{ else if eq .shell "bash" -}}
source $HOME/.hishtory/config.sh source $HOME/.hishtory/config.sh
{{- else -}} {{- else -}}
{{ fail "Unexpected shell." }} {{ 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 . "$HOME/.cargo/env" # Rustup + Cargo + Cargo-installed tools
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" # Brew eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" # Brew
command -v rbenv &> /dev/null && eval "$(rbenv init -)" # rbenv for Ruby 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 # pyenv, python version manager
export PYENV_ROOT="$HOME/.pyenv" export PYENV_ROOT="$HOME/.pyenv"
@@ -89,3 +93,8 @@ fi
# else # else
# export EDITOR='nvim' # 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
fi fi
{{ template "scripts/commonrc.sh.tmpl" "bash" }} {{ template "scripts/commonrc.sh.tmpl" dict "data" . "shell" "bash" }}
{{ completion "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 source $ZSH/oh-my-zsh.sh
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh # configure with `p10k configure` [[ ! -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" }} {{ completion "zsh" }}