fix: Linux/Ubuntu compatibility for shell configs and dotfiles manager

00_env.sh:
  - yaml2json: use python3 (python3 first, python fallback) — Ubuntu 20+ has no 'python'
  - pyenv init: moved out of Darwin-only block; now runs everywhere if pyenv installed
  - xterm ls alias: split by OS — Linux gets 'ls --color=auto', macOS gets 'ls -G'

10_aliases.sh:
  - psg: guard with 'command -v pstree' (not installed by default on Ubuntu)
  - ps-m: Linux-only (--sort flag is GNU ps, not available on macOS)
  - gitresetpw: OS-conditional — osxkeychain on Darwin, store on Linux

dotfiles_manager.sh:
  - Replace both hardcoded 'brew install gnupg' die messages with _require_gpg()
    helper that gives apt-get hint on Linux and brew hint on macOS
This commit is contained in:
Kenji Morishige
2026-02-23 13:33:28 -06:00
parent 32be384c0e
commit 522b004632
3 changed files with 40 additions and 15 deletions

View File

@@ -34,7 +34,9 @@ Linux)
export PAGER=$(type less >/dev/null 2>&1 && echo less || echo more)
function yaml2json {
python -c 'import sys, yaml, json; print(json.dumps(yaml.safe_load(sys.stdin.read())))'
# python3 on Ubuntu 20+; fall back to python2 if needed
local _py; _py=$(command -v python3 2>/dev/null || command -v python 2>/dev/null)
"$_py" -c 'import sys, yaml, json; print(json.dumps(yaml.safe_load(sys.stdin.read())))'
}
;;
Darwin)
@@ -42,14 +44,6 @@ Darwin)
export CLICOLOR=1
export DOCKER_DEFAULT_PLATFORM=linux/amd64
export BASH_SILENCE_DEPRECATION_WARNING=1
# pyenv — only init if installed
if command -v pyenv >/dev/null 2>&1; then
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
fi
;;
FreeBSD)
export CLICOLOR=1
@@ -57,12 +51,27 @@ FreeBSD)
;;
esac
# -----------------------------------------------------------------------
# pyenv — init if installed (works on both Linux and macOS)
# -----------------------------------------------------------------------
if command -v pyenv >/dev/null 2>&1; then
export PYENV_ROOT="${PYENV_ROOT:-$HOME/.pyenv}"
[[ ":$PATH:" != *":$PYENV_ROOT/bin:"* ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
fi
# -----------------------------------------------------------------------
# Terminal-specific
# -----------------------------------------------------------------------
case $TERM in
xterm*)
export LS_COLORS='no=00:fi=00:di=00;35:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;31:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:*.pl=00;32:'
alias ls='ls -F --color'
# GNU ls (Linux) uses --color; BSD ls (macOS/FreeBSD) uses -G / CLICOLOR
if [[ "$(uname -s)" == "Linux" ]]; then
alias ls='ls -F --color=auto'
else
alias ls='ls -F -G'
fi
;;
esac

View File

@@ -17,8 +17,10 @@ alias sl='screen -list'
alias sr='screen -r'
# Process inspection
alias psg='pstree | grep'
alias ps-m='ps aux --sort -rss'
# pstree may not be installed on all systems
command -v pstree >/dev/null 2>&1 && alias psg='pstree | grep'
# --sort is a GNU ps flag (Linux only)
[[ "$(uname -s)" == "Linux" ]] && alias ps-m='ps aux --sort -rss'
# Docker — short forms
alias d='docker'
@@ -29,5 +31,10 @@ alias db='docker build'
# Git helpers
alias giturl='git config --get remote.origin.url'
alias gitresetpw='git config --global credential.helper osxkeychain'
# Git credential helper is OS-specific
if [[ "$(uname -s)" == "Darwin" ]]; then
alias gitresetpw='git config --global credential.helper osxkeychain'
else
alias gitresetpw='git config --global credential.helper store'
fi
alias git-clean='git-prune-branches'