From f33342f42be9cb465453ea125293d43bc67d55e0 Mon Sep 17 00:00:00 2001 From: Johnie Hjelm Date: Thu, 29 Jan 2026 16:52:10 +0000 Subject: [PATCH 1/4] feat(zshrc): add OS detection for Homebrew setup Only load Homebrew shellenv on macOS to support Linux systems where Homebrew is not installed. --- setup/zshrc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/setup/zshrc b/setup/zshrc index cc9fd9a..edee09b 100644 --- a/setup/zshrc +++ b/setup/zshrc @@ -3,7 +3,10 @@ for file in ~/.{extra,exports,aliases,functions,colors}; do done unset file +# macOS: Homebrew setup +if [[ "$OSTYPE" == "darwin"* ]]; then + eval "$(/opt/homebrew/bin/brew shellenv)" +fi -eval "$(/opt/homebrew/bin/brew shellenv)" eval "$(starship init zsh)" eval "$(sheldon source)" From 8ba1bb42a3d4f441c9fb8fa9d3587e83f7f0259e Mon Sep 17 00:00:00 2001 From: Johnie Hjelm Date: Thu, 29 Jan 2026 16:52:20 +0000 Subject: [PATCH 2/4] feat(exports): add OS-specific NVM paths and ~/.local/bin to PATH - Add ~/.local/bin to PATH for Linux tools (bat symlink, eza, sheldon) - Add OS detection for NVM: use Homebrew paths on macOS, standard paths on Linux --- setup/exports | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/setup/exports b/setup/exports index e6e9ef6..29deddb 100644 --- a/setup/exports +++ b/setup/exports @@ -1,5 +1,5 @@ -export PATH=$HOME/bin:/usr/local/bin:/snap/bin:/opt/bin:$PATH -export PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin +export PATH=$HOME/.local/bin:$HOME/bin:/usr/local/bin:/snap/bin:/opt/bin:$PATH +export PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin export PATH=/usr/local/sbin:$PATH export LANG=en_US.UTF-8 @@ -7,8 +7,14 @@ export LANG=en_US.UTF-8 export GOPATH="$HOME/dev/go" export PATH="$GOPATH/bin:$PATH" +# NVM - OS-specific paths export NVM_DIR="$HOME/.nvm" -[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm -[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" +if [[ "$OSTYPE" == "darwin"* ]]; then + [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" + [ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" +else + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" +fi export PATH=~/.npm-global/bin:$PATH From 6e90d3856849eed8d44e65a079aa25df5df3fcb5 Mon Sep 17 00:00:00 2001 From: Johnie Hjelm Date: Thu, 29 Jan 2026 16:52:29 +0000 Subject: [PATCH 3/4] feat(aliases): add OS detection for cross-platform compatibility Add OSTYPE checks to support both macOS and Linux: - Clipboard: pbcopy (macOS) vs xclip (Linux) - Open command: open (macOS) vs xdg-open (Linux) - Local IP: ipconfig (macOS) vs hostname -I (Linux) - File size: stat -f (macOS) vs stat -c (Linux) - DNS flush: mDNSResponder (macOS) vs systemd-resolve (Linux) - System log: /var/log/system.log (macOS) vs journalctl (Linux) - Update: softwareupdate+brew (macOS) vs apt (Linux) Wrap macOS-only aliases (Finder, Homebrew, system controls) in darwin conditionals. --- setup/aliases | 172 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 112 insertions(+), 60 deletions(-) diff --git a/setup/aliases b/setup/aliases index e334e20..438aedb 100644 --- a/setup/aliases +++ b/setup/aliases @@ -1,18 +1,20 @@ -# Enable aliases to be sudo’ed +# Enable aliases to be sudo'ed alias sudo='sudo ' alias e="$EDITOR" # Reload the .zshrc alias reload='source $HOME/.zshrc && echo "Reloaded ~/.zshrc"' -# programs -alias preview="open -a '$PREVIEW'" -alias safari="open -a safari" -alias firefox="open -a firefox" -alias chrome="open -a google\ chrome" -alias cognito="open -a google\ chrome --args --incognito" -alias spotify="osascript ~/code/SpotifyControl/SpotifyControl.scpt" -alias imessage="open -a Messages" +# macOS-only application aliases +if [[ "$OSTYPE" == "darwin"* ]]; then + alias preview="open -a '$PREVIEW'" + alias safari="open -a safari" + alias firefox="open -a firefox" + alias chrome="open -a google\ chrome" + alias cognito="open -a google\ chrome --args --incognito" + alias spotify="osascript ~/code/SpotifyControl/SpotifyControl.scpt" + alias imessage="open -a Messages" +fi # Easier navigation: .., ..., ...., ....., ~ and - alias ..="cd .." @@ -31,10 +33,23 @@ alias zx="cd ~/dev/experiments" alias zr="cd ~/dev/rust" alias zgj="cd ~/dev/go/src/github.com/johnie" alias cl="clear" -alias pbc="pbcopy" alias reboot="sudo shutdown -r now" -alias sov="osascript -e 'tell application \"System Events\" to sleep'" -alias pubkey="more ~/.ssh/id_ed25519.pub | pbcopy | echo '=> Public key copied to pasteboard.'" + +# Clipboard - OS-specific +if [[ "$OSTYPE" == "darwin"* ]]; then + alias pbc="pbcopy" + alias pbcn="tr -d '\n' | pbcopy" + alias pubkey="more ~/.ssh/id_ed25519.pub | pbcopy | echo '=> Public key copied to pasteboard.'" +else + alias pbc="xclip -selection clipboard" + alias pbcn="tr -d '\n' | xclip -selection clipboard" + alias pubkey="cat ~/.ssh/id_ed25519.pub | xclip -selection clipboard && echo '=> Public key copied to clipboard.'" +fi + +# macOS-only system controls +if [[ "$OSTYPE" == "darwin"* ]]; then + alias sov="osascript -e 'tell application \"System Events\" to sleep'" +fi # Get week number alias week='date +%V' @@ -42,11 +57,19 @@ alias week='date +%V' # be nice alias doh='sudo $(history -p !-1)' -# handy things -alias wifi="airport" -alias wifion="networksetup -setairportpower en1 on" -alias wifioff="networksetup -setairportpower en1 off" -alias flushdns="sudo killall -HUP mDNSResponder" +# handy things - macOS WiFi +if [[ "$OSTYPE" == "darwin"* ]]; then + alias wifi="airport" + alias wifion="networksetup -setairportpower en1 on" + alias wifioff="networksetup -setairportpower en1 off" +fi + +# Flush DNS - OS-specific +if [[ "$OSTYPE" == "darwin"* ]]; then + alias flushdns="sudo killall -HUP mDNSResponder" +else + alias flushdns="sudo systemd-resolve --flush-caches" +fi if $(eza &>/dev/null) then @@ -60,9 +83,15 @@ alias gr='[ ! -z `git rev-parse --show-cdup` ] && cd `git rev-parse --show-cdup # IP addresses alias ip="dig +short myip.opendns.com @resolver1.opendns.com" -alias localip="ipconfig getifaddr en1" alias ips="ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'" +# Local IP - OS-specific +if [[ "$OSTYPE" == "darwin"* ]]; then + alias localip="ipconfig getifaddr en1" +else + alias localip="hostname -I | awk '{print \$1}'" +fi + # Enhanced WHOIS lookups alias whois="whois -h whois-servers.net" @@ -108,63 +137,86 @@ alias dc='docker compose' alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'" alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\"" -# Trim new lines and copy to clipboard -alias pbcn="tr -d '\n' | pbcopy" - # Recursively delete `.DS_Store` files alias cleanup="find . -name '*.DS_Store' -type f -ls -delete" # Shortcuts alias v="nvim" -# File size -alias fs="stat -f \"%z bytes\"" +# File size - OS-specific +if [[ "$OSTYPE" == "darwin"* ]]; then + alias fs="stat -f \"%z bytes\"" +else + alias fs="stat -c \"%s bytes\"" +fi -# Hide/show all desktop icons (useful when presenting) -alias hidedesktop="defaults write com.apple.finder CreateDesktop -bool false && killall Finder" -alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && killall Finder" +# macOS-only Finder and desktop aliases +if [[ "$OSTYPE" == "darwin"* ]]; then + # Hide/show all desktop icons (useful when presenting) + alias hidedesktop="defaults write com.apple.finder CreateDesktop -bool false && killall Finder" + alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && killall Finder" -# Show/Hide hidden files in Finder -alias showfiles="defaults write com.apple.finder AppleShowAllFiles YES && killall Finder" -alias hidefiles="defaults write com.apple.finder AppleShowAllFiles NO && killall Finder" + # Show/Hide hidden files in Finder + alias showfiles="defaults write com.apple.finder AppleShowAllFiles YES && killall Finder" + alias hidefiles="defaults write com.apple.finder AppleShowAllFiles NO && killall Finder" -# PlistBuddy alias, because sometimes `defaults` just doesn’t cut it -alias plistbuddy="/usr/libexec/PlistBuddy" + # PlistBuddy alias, because sometimes `defaults` just doesn't cut it + alias plistbuddy="/usr/libexec/PlistBuddy" +fi -# One of @janmoesen’s ProTip™s +# One of @janmoesen's ProTip™s for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do alias "$method"="lwp-request -m '$method'" done -# Stuff I never really use but cannot delete either because of http://xkcd.com/530/ -alias stfu="osascript -e 'set volume output muted true'" -alias pumpitup="osascript -e 'set volume 10'" +# macOS-only volume and system controls +if [[ "$OSTYPE" == "darwin"* ]]; then + # Stuff I never really use but cannot delete either because of http://xkcd.com/530/ + alias stfu="osascript -e 'set volume output muted true'" + alias pumpitup="osascript -e 'set volume 10'" +fi + +# System log - OS-specific +if [[ "$OSTYPE" == "darwin"* ]]; then + alias msg='tail -f /var/log/system.log' +else + alias msg='journalctl -f' +fi + +# macOS-only Homebrew aliases +if [[ "$OSTYPE" == "darwin"* ]]; then + # Shorter commands for `Homebrew`. + alias brewd="brew doctor" + alias brewi="brew install" + alias brewr="brew uninstall" + alias brews="brew search" + alias brewu="brew update --quiet \ + && brew upgrade \ + && brew cleanup" + + # Empty the trash, the main HDD and on all mounted volumes, + # and clear Apple's system logs to improve shell startup speed. + alias empty-trash="sudo rm -frv /Volumes/*/.Trashes; \ + sudo rm -frv ~/.Trash; \ + sudo rm -frv /private/var/log/asl/*.asl; \ + sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'" +fi -# MacOS log -alias msg='tail -f /var/log/system.log' +# Open command - OS-specific +if [[ "$OSTYPE" == "darwin"* ]]; then + alias o="open" + alias oo="open ." +else + alias o="xdg-open" + alias oo="xdg-open ." +fi -# Shorter commands for `Homebrew`. -alias brewd="brew doctor" -alias brewi="brew install" -alias brewr="brew uninstall" -alias brews="brew search" -alias brewu="brew update --quiet \ +# Update command - OS-specific +if [[ "$OSTYPE" == "darwin"* ]]; then + alias update="sudo softwareupdate --install --all \ + && brew update \ && brew upgrade \ && brew cleanup" - -# Empty the trash, the main HDD and on all mounted volumes, -# and clear Apple’s system logs to improve shell startup speed. -alias empty-trash="sudo rm -frv /Volumes/*/.Trashes; \ - sudo rm -frv ~/.Trash; \ - sudo rm -frv /private/var/log/asl/*.asl; \ - sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'" - -# Open from the terminal. -alias o="open" -alias oo="open ." - -# Update applications and CLTs. -alias update="sudo softwareupdate --install --all \ - && brew update \ - && brew upgrade \ - && brew cleanup" +else + alias update="sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y" +fi From 6e7e0de55bbfe491306dc40bdb5cf7e666c34a9a Mon Sep 17 00:00:00 2001 From: Johnie Hjelm Date: Thu, 29 Jan 2026 16:52:40 +0000 Subject: [PATCH 4/4] feat(scripts): add Ubuntu server install script Automated setup script for Ubuntu servers with: - System dependencies (zsh, git, curl, wget, xclip, fontconfig) - Modern CLI tools (bat, eza, delta) - Starship prompt and Sheldon plugin manager - JetBrainsMono Nerd Font - Config symlinks for shell and git - Sheldon plugin initialization - zsh as default shell Supports SSH access with rich terminal colors when the local terminal uses a Nerd Font and true color. --- scripts/install-ubuntu.sh | 89 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 scripts/install-ubuntu.sh diff --git a/scripts/install-ubuntu.sh b/scripts/install-ubuntu.sh new file mode 100755 index 0000000..29ac0a8 --- /dev/null +++ b/scripts/install-ubuntu.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Ubuntu Setup Script for Starship + Sheldon + Rich Terminal Colors +# Run: bash scripts/install-ubuntu.sh + +echo "==> Installing system dependencies..." +sudo apt update +sudo apt install -y zsh git curl wget unzip fontconfig xclip + +echo "==> Installing bat (better cat)..." +sudo apt install -y bat +mkdir -p ~/.local/bin +[ ! -L ~/.local/bin/bat ] && ln -s /usr/bin/batcat ~/.local/bin/bat || true + +echo "==> Installing eza (better ls)..." +if ! command -v eza &>/dev/null; then + wget -qO- https://github.com/eza-community/eza/releases/download/v0.18.9/eza_x86_64-unknown-linux-gnu.tar.gz | tar xz -C ~/.local/bin +fi + +echo "==> Installing delta (better git diff)..." +if ! command -v delta &>/dev/null; then + DELTA_VERSION=$(curl -s https://api.github.com/repos/dandavison/delta/releases/latest | grep tag_name | cut -d '"' -f4) + wget -qO /tmp/delta.deb "https://github.com/dandavison/delta/releases/download/${DELTA_VERSION}/git-delta_${DELTA_VERSION}_amd64.deb" + sudo dpkg -i /tmp/delta.deb + rm /tmp/delta.deb +fi + +echo "==> Installing starship prompt..." +if ! command -v starship &>/dev/null; then + curl -sS https://starship.rs/install.sh | sh -s -- -y +fi + +echo "==> Installing sheldon plugin manager..." +if ! command -v sheldon &>/dev/null; then + curl --proto '=https' -fLsS https://rossmacarthur.github.io/install/crate.sh \ + | bash -s -- --repo rossmacarthur/sheldon --to ~/.local/bin +fi + +echo "==> Installing JetBrainsMono Nerd Font..." +FONT_DIR=~/.local/share/fonts/JetBrainsMono +if [ ! -d "$FONT_DIR" ]; then + mkdir -p ~/.local/share/fonts + wget -qO /tmp/JetBrainsMono.zip https://github.com/ryanoasis/nerd-fonts/releases/download/v3.1.1/JetBrainsMono.zip + unzip -qo /tmp/JetBrainsMono.zip -d "$FONT_DIR" + rm /tmp/JetBrainsMono.zip + fc-cache -fv +fi + +echo "==> Creating config symlinks..." +CONFIG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +mkdir -p ~/.config/sheldon + +# Starship config +ln -sf "$CONFIG_DIR/.config/starship.toml" ~/.config/starship.toml + +# Sheldon config +ln -sf "$CONFIG_DIR/.config/sheldon/plugins.toml" ~/.config/sheldon/plugins.toml + +# Shell config files +ln -sf "$CONFIG_DIR/setup/zshrc" ~/.zshrc +ln -sf "$CONFIG_DIR/setup/exports" ~/.exports +ln -sf "$CONFIG_DIR/setup/aliases" ~/.aliases +ln -sf "$CONFIG_DIR/setup/functions" ~/.functions +ln -sf "$CONFIG_DIR/setup/colors" ~/.colors +ln -sf "$CONFIG_DIR/setup/extra" ~/.extra + +# Git config +ln -sf "$CONFIG_DIR/setup/gitconfig" ~/.gitconfig +ln -sf "$CONFIG_DIR/setup/gitignore" ~/.gitignore + +echo "==> Initializing sheldon (downloading plugins)..." +~/.local/bin/sheldon lock --update + +echo "==> Setting zsh as default shell..." +if [ "$SHELL" != "$(which zsh)" ]; then + chsh -s "$(which zsh)" +fi + +echo "" +echo "✓ Setup complete!" +echo "" +echo "IMPORTANT - SSH Terminal Setup:" +echo " 1. Your local terminal must use a Nerd Font (e.g., JetBrainsMono Nerd Font)" +echo " 2. Enable true color in your terminal settings" +echo " 3. Reconnect SSH session or run: exec zsh" +echo "" +echo "Test colors: printf '\\x1b[38;2;255;100;0mTRUECOLOR\\x1b[0m\\n'"