Files
dotfiles/.bashrc.d/00_env.sh
Kenji Morishige 522b004632 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
2026-02-23 13:33:28 -06:00

78 lines
2.7 KiB
Bash

#!/usr/bin/env bash
# 00_env.sh — Core environment: prompt, editor, OS detection, terminal colors
# Shared across all machines. No secrets. No machine-specific paths.
# ============================================================================
export PS1='\h:\w\$ '
export PS2='> '
export FTP_PASSIVE_MODE=YES
export RSYNC_RSH=ssh
# Use short hostname consistently (macOS and Linux)
HOSTNAME=$(hostname -s)
HOSTDOMAIN=$(hostname -d 2>/dev/null || true)
export HOSTNAME HOSTDOMAIN
EDITOR=vim
export EDITOR
set -o vi
# -----------------------------------------------------------------------
# OS-specific
# -----------------------------------------------------------------------
_OSTYPE=$(uname -s)
case $_OSTYPE in
Linux)
alias ls='ls -F'
alias pst='ps axjf'
if type "$EDITOR" >/dev/null 2>&1; then
alias vi="${EDITOR}"
else
EDITOR=vi
fi
export PAGER=$(type less >/dev/null 2>&1 && echo less || echo more)
function yaml2json {
# 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)
alias pst='pstree'
export CLICOLOR=1
export DOCKER_DEFAULT_PLATFORM=linux/amd64
export BASH_SILENCE_DEPRECATION_WARNING=1
;;
FreeBSD)
export CLICOLOR=1
export LSCOLORS=fxgxcxdxbxegedabagacad
;;
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:'
# 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