Parcourir la source

refactor: harden dotfiles for cross-machine compatibility

Don't invoke tools that may not be installed on a given machine:
- .gitconfig: delta pager and interactive.diffFilter fall back to less/cat
  when delta is absent; gh credential helper uses PATH instead of a hardcoded
  /opt/homebrew path (works on Intel/other prefixes); excludesfile relative.
- .zshrc/.bashrc: guard opencode + LM Studio PATH appends and ~/.cargo/env
  behind existence checks.
- lazy-nvm.sh: guard `brew --prefix nvm` behind `command -v brew`; fix the
  pnpm wrapper that mistakenly invoked yarn.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Tom McKenzie il y a 1 mois
Parent
commit
1a2ea1e715
4 fichiers modifiés avec 17 ajouts et 16 suppressions
  1. 3 4
      .bashrc
  2. 6 5
      .gitconfig
  3. 4 2
      .rc.d/lazy-nvm.sh
  4. 4 5
      .zshrc

+ 3 - 4
.bashrc

@@ -26,9 +26,8 @@ PS1="\[\e[1;32m\]\h:\W \u$\[\e[0m\] "
 bind '"\e[A": history-search-backward'
 bind '"\e[B": history-search-forward'
 
-. "$HOME/.cargo/env"
+[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
 
-# Added by LM Studio CLI (lms)
-export PATH="$PATH:/Users/tom/.lmstudio/bin"
-# End of LM Studio CLI section
+# LM Studio CLI (lms)
+[ -d "$HOME/.lmstudio/bin" ] && export PATH="$PATH:$HOME/.lmstudio/bin"
 

+ 6 - 5
.gitconfig

@@ -40,10 +40,11 @@
 	fixup = "!f() { TARGET=$(git rev-parse "$1"); git commit --fixup=$TARGET ${@:2} && EDITOR=true git rebase -i --autostash --autosquash $TARGET^; }; f"
 	last = rev-list -1 HEAD
 [core]
-	excludesfile = /Users/tom/dotfiles/.gitignore_global
+	excludesfile = ~/.gitignore_global
 	whitespace = tab-in-indent,trailing-space,space-before-tab
 	ignorecase = false
-	pager = delta
+	# use delta if installed, else fall back to less (don't break git without delta)
+	pager = command -v delta >/dev/null 2>&1 && delta || less -R
 [push]
 	default = upstream
 [status]
@@ -64,7 +65,7 @@
 	path = ~/dotfiles/.gitconfig_difftastic
 	condition = command -v difft >/dev/null 2>&1
 [interactive]
-	diffFilter = delta --color-only
+	diffFilter = command -v delta >/dev/null 2>&1 && delta --color-only || cat
 [delta]
     features = decorations
 	navigate = true
@@ -79,7 +80,7 @@
 	conflictStyle = zdiff3
 [credential "https://github.com"]
 	helper = 
-	helper = !/opt/homebrew/bin/gh auth git-credential
+	helper = !gh auth git-credential
 [credential "https://gist.github.com"]
 	helper = 
-	helper = !/opt/homebrew/bin/gh auth git-credential
+	helper = !gh auth git-credential

+ 4 - 2
.rc.d/lazy-nvm.sh

@@ -11,7 +11,9 @@ function lazy_nvm {
   if [ -d "${HOME}/.nvm" ]; then
     export NVM_DIR="$HOME/.nvm"
     [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # linux
-    [ -s "$(brew --prefix nvm)/nvm.sh" ] && source $(brew --prefix nvm)/nvm.sh # osx
+    if command -v brew >/dev/null 2>&1; then
+      [ -s "$(brew --prefix nvm)/nvm.sh" ] && source "$(brew --prefix nvm)/nvm.sh" # osx
+    fi
     [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # nvm bash_completion
   fi
 }
@@ -22,4 +24,4 @@ function npm { lazy_nvm; npm "$@"; }
 function node { lazy_nvm; node "$@"; }
 function npx { lazy_nvm; npx "$@"; }
 function yarn { lazy_nvm; yarn "$@"; }
-function pnpm { lazy_nvm; yarn "$@"; }
+function pnpm { lazy_nvm; pnpm "$@"; }

+ 4 - 5
.zshrc

@@ -42,12 +42,11 @@ export PATH="$BUN_INSTALL/bin:$PATH"
 # zoxide
 if command -v zoxide >/dev/null 2>&1; then eval "$(zoxide init zsh)"; fi
 
-. "$HOME/.cargo/env"
+[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
 
 # opencode
-export PATH=/Users/tom/.opencode/bin:$PATH
+[ -d "$HOME/.opencode/bin" ] && export PATH="$HOME/.opencode/bin:$PATH"
 
-# Added by LM Studio CLI (lms)
-export PATH="$PATH:/Users/tom/.lmstudio/bin"
-# End of LM Studio CLI section
+# LM Studio CLI (lms)
+[ -d "$HOME/.lmstudio/bin" ] && export PATH="$PATH:$HOME/.lmstudio/bin"