-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzshrc
More file actions
131 lines (109 loc) · 3.23 KB
/
Copy pathzshrc
File metadata and controls
131 lines (109 loc) · 3.23 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
#!/usr/bin/env zsh
# ~/.zshrc
setopt PROMPT_SUBST
# Ensure Homebrew is available in interactive shells too
if ! command -v brew >/dev/null 2>&1 && [ -x /opt/homebrew/bin/brew ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
# Mise
if command -v mise >/dev/null 2>&1; then
eval "$(mise activate zsh)"
fi
# ----- Prompt colors -----
BOLD="%B"
NOBOLD="%b"
RED="${BOLD}%F{red}"
GREEN="${BOLD}%F{green}"
YELLOW="${BOLD}%F{yellow}"
PURPLE="${BOLD}%F{magenta}"
WHITE="%F{white}"
RESET="%f%b"
# Icons
GIT_BRANCH_ICON="⎇ "
GIT_MODIFIED_ICON="✚"
GIT_AHEAD_ICON="↑"
GIT_CLEAN_ICON="✔"
# ----- Git helpers -----
in_git_repo() {
git rev-parse --is-inside-work-tree >/dev/null 2>&1
}
git_branch_name() {
# symbolic-ref is fast; falls back to short SHA in detached HEAD
git symbolic-ref --quiet --short HEAD 2>/dev/null \
|| git rev-parse --short HEAD 2>/dev/null
}
git_ahead_icon() {
# Only compute if upstream exists
local ab behind ahead
ab="$(git rev-list --left-right --count @{upstream}...HEAD 2>/dev/null)" || return 0
behind="${ab%% *}"
ahead="${ab##* }"
(( ahead > 0 )) && printf "%s%s " "$YELLOW" "$GIT_AHEAD_ICON"
}
git_dirty_icon() {
# Cheap dirty check: unstaged or staged changes?
git diff --quiet --ignore-submodules -- 2>/dev/null || { printf "%s%s " "$RED" "$GIT_MODIFIED_ICON"; return 0; }
git diff --cached --quiet --ignore-submodules -- 2>/dev/null || { printf "%s%s " "$RED" "$GIT_MODIFIED_ICON"; return 0; }
printf "%s%s " "$GREEN" "$GIT_CLEAN_ICON"
}
git_prompt_segment() {
in_git_repo || return 0
local branch
branch="$(git_branch_name)" || return 0
printf "%s%s%s%s%s" \
"$(git_dirty_icon)" \
"$WHITE" "$GIT_BRANCH_ICON" "$branch" "$RESET"
printf "%s" "$(git_ahead_icon)"
}
# ----- Prompt hook -----
precmd() {
# MUST be first: captures exit status of the user’s last command
local last_status=$?
# Terminal title to current directory (prompt expansion)
print -Pn "\e]0;%~\a"
local gitseg=""
if in_git_repo; then
gitseg=" $(git_prompt_segment)"
fi
PROMPT="[${PURPLE}%~${RESET}] →${gitseg} ${WHITE}$ ${RESET}"
if (( last_status != 0 )); then
RPROMPT="${RED}Exit:${last_status}${RESET}"
else
RPROMPT="${GREEN}✓${RESET}"
fi
RPROMPT="${RPROMPT} ${YELLOW}%D{%L:%M %p}${RESET}"
}
# ----- Completion (zsh native) -----
autoload -Uz compinit
compinit
# ----- UX / aliases -----
export CLICOLOR=1
export LSCOLORS=GxExBxBxFxegedabagacad
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias cdCode='cd "$HOME/Code"'
alias cdEv='cd "$HOME/Desktop/Everything"'
alias brewup='brew update && brew upgrade && brew cleanup'
# Safer directory toggle
cdl() { cd - >/dev/null && ls; }
# Safer extract (quotes args)
extract() {
local f="$1"
[[ -f "$f" ]] || { echo "'$f' is not a valid file"; return 1; }
case "$f" in
*.tar.bz2) tar xjf "$f" ;;
*.tar.gz) tar xzf "$f" ;;
*.bz2) bunzip2 "$f" ;;
*.rar) unrar x "$f" ;;
*.gz) gunzip "$f" ;;
*.tar) tar xf "$f" ;;
*.tbz2) tar xjf "$f" ;;
*.tgz) tar xzf "$f" ;;
*.zip) unzip "$f" ;;
*.Z) uncompress "$f" ;;
*.7z) 7z x "$f" ;;
*) echo "'$f' cannot be extracted via extract()"; return 2 ;;
esac
}