-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_shellrc
More file actions
151 lines (135 loc) · 6 KB
/
dot_shellrc
File metadata and controls
151 lines (135 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env sh
# ----------------------------------------------------------------------------
# shellrc is sourced by both .bashrc and .zshrc
# Keep this file POSIX-compatible (no bash or zsh specific syntax)
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Prompt (shell-agnostic)
# ----------------------------------------------------------------------------
# _PROMPT_ID = user@host color: red for root, magenta for remote (SSH), cyan for local
# green = no dotfiles installed (system default) — intentionally unused here
# _PROMPT_INFO = path color: always blue
# _PROMPT_RESET = reset color
if [ "$(id -u)" = "0" ]; then
_PROMPT_ID=$(printf '\033[1;31m') # bold red (root)
elif [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] || [ -n "$SSH_CONNECTION" ]; then
_PROMPT_ID=$(printf '\033[1;35m') # bold magenta (remote)
else
_PROMPT_ID=$(printf '\033[1;36m') # bold cyan (local)
fi
_PROMPT_INFO=$(printf '\033[34m') # blue (path)
_PROMPT_RESET=$(printf '\033[0m') # reset
# ----------------------------------------------------------------------------
# Colors (shell-agnostic)
# ----------------------------------------------------------------------------
# BSD ls (macOS): CLICOLOR enables color, LSCOLORS defines the scheme
# Format: each pair = fg/bg for: dir symlink socket pipe exec block char setuid setgid sticky-dir other-writable-dir
export CLICOLOR=1
export LSCOLORS="ExGxFxDxCxEgEdxbxgxcxd" # bold: blue dir, cyan link, magenta socket, green exec
# LS_COLORS: used by GNU ls, grep, fd, tree, and many other tools
if command -v dircolors >/dev/null 2>&1; then
eval "$(dircolors -b)"
else
# Fallback for macOS (no dircolors): sensible defaults for tools that read LS_COLORS
export LS_COLORS='di=1;34:ln=1;36:so=1;35:pi=33:ex=1;32:bd=1;33:cd=1;33:su=37;41:sg=30;43:tw=30;42:ow=34;42'
fi
# Colorize commands that support "--color=auto"
alias grep='grep --color=auto'
if diff --color=auto /dev/null /dev/null >/dev/null 2>&1; then
alias diff='diff --color=auto'
fi
if ls --color=auto /dev/null >/dev/null 2>&1; then
alias ls='ls --color=auto'
fi
# ----------------------------------------------------------------------------
# Editor (shell-agnostic)
# ----------------------------------------------------------------------------
export EDITOR=vim
# ----------------------------------------------------------------------------
# History (shell-agnostic)
# ----------------------------------------------------------------------------
export HISTSIZE=10000
# ----------------------------------------------------------------------------
# cheatsheet lookup (shell-agnostic)
# See docs/cheatsheets/ — files use .sh extension for GitHub syntax highlighting
# ----------------------------------------------------------------------------
cheatsheet() {
local dir="$HOME/.local/share/chezmoi/docs/cheatsheets"
if [ -z "$1" ]; then
echo "Usage:"
echo " cheatsheet <topic>"
echo ""
echo "Available cheatsheets:"
ls "$dir" | sed 's/\.sh$//' | sed 's/^/ /'
elif [ -f "$dir/$1.sh" ]; then
cat "$dir/$1.sh"
else
echo "No cheatsheet found for '$1'. Run 'cheatsheet' to list available topics."
return 1
fi
}
# ----------------------------------------------------------------------------
# Reload shell config without exiting (shell-agnostic)
# ----------------------------------------------------------------------------
reload() {
echo "Reloading shell..."
case "$(ps -p $$ -o comm=)" in
*zsh*) exec zsh ;;
*bash*) exec bash ;;
*) echo "Unknown shell; restart manually." ;;
esac
}
# ----------------------------------------------------------------------------
# OPTIONAL: PATH (shell-agnostic)
# ----------------------------------------------------------------------------
# Add $HOME/.local/bin to front of PATH (if exists)
test -d "$HOME/.local/bin" && export PATH="$HOME/.local/bin:$PATH"
# ----------------------------------------------------------------------------
# OPTIONAL: pyenv (shell-agnostic)
# ----------------------------------------------------------------------------
if [ -d "$HOME/.pyenv" ]; then
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
fi
# ----------------------------------------------------------------------------
# OPTIONAL: fnm (shell-agnostic)
# ----------------------------------------------------------------------------
if command -v fnm >/dev/null 2>&1; then
eval "$(fnm env)"
fi
# ----------------------------------------------------------------------------
# OPTIONAL: nvm (shell-agnostic)
# ----------------------------------------------------------------------------
if [ -s "/opt/homebrew/opt/nvm/nvm.sh" ]; then
export NVM_DIR="$HOME/.nvm"
\. "/opt/homebrew/opt/nvm/nvm.sh"
elif [ -s "/usr/local/opt/nvm/nvm.sh" ]; then
export NVM_DIR="$HOME/.nvm"
\. "/usr/local/opt/nvm/nvm.sh"
fi
# ----------------------------------------------------------------------------
# OPTIONAL: ssh-agent - requires smallstep (shell-agnostic)
# ----------------------------------------------------------------------------
if command -v step >/dev/null 2>&1; then
if ! pgrep -u "$USER" ssh-agent >/dev/null 2>&1; then
eval "$(ssh-agent -s)" >/dev/null
fi
fi
# ----------------------------------------------------------------------------
# OPTIONAL: zoxide (shell-agnostic)
# ----------------------------------------------------------------------------
if command -v zoxide >/dev/null 2>&1; then
case "$(ps -p $$ -o comm=)" in
*zsh*) eval "$(zoxide init zsh)" ;;
*bash*) eval "$(zoxide init bash)" ;;
*) eval "$(zoxide init posix --hook prompt)" ;;
esac
fi
# ----------------------------------------------------------------------------
# OPTIONAL: Kitty terminal (shell-agnostic)
# Use kitten ssh to propagate terminfo to remote hosts
# ----------------------------------------------------------------------------
if command -v kitten >/dev/null 2>&1; then
alias ssh='kitten ssh'
fi