about summary refs log tree commit diff
path: root/.zshrc
blob: cf9fbf0e89f3c6b72a1fcc6ce37a542191287b44 (plain)
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
# Venomade's zshrc

# source global variables and aliases
[ -f "$HOME/.config/shell/alias" ] && source "$HOME/.config/shell/alias"
[ -f "$HOME/.config/shell/vars" ] && source "$HOME/.config/shell/vars"

# load modules
zmodload zsh/complist
autoload -U compinit && compinit
autoload -U colors && colors

# completion
zstyle ':completion:*' menu select
zstyle ':completion:*' special-dirs true
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} ma=0\;33

# options
setopt append_history inc_append_history share_history
setopt auto_menu menu_complete
setopt auto_param_slash
setopt no_case_glob no_case_match
setopt globdots
setopt extended_glob

# history
HISTCONTROL=ignoreboth


# prompt
USER_COLOR="%F{magenta}"
VENV_COLOR="%F{yellow}"
DIR_COLOR="%F{green}"
GIT_COLOR="%F{blue}"
GIT_DIRTY_COLOR="%F{red}"
PROMPT_SYMBOL_COLOR="%F{yellow}"
RESET_COLOR="%f"

shorten_path() {
  local path="${PWD/#$HOME/~}"
  local parts=("${(@s:/:)path}")

  if (( ${#parts} > 3 )); then
    echo "${parts[1]}/.../${parts[-2]}/${parts[-1]}"
  else
    echo "$path"
  fi
}

git_branch() {
  local branch
  branch=$(git symbolic-ref --short HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)
  [[ -n "$branch" ]] && echo "$branch"
}

git_dirty() {
  [[ -n "$(git status --porcelain 2>/dev/null)" ]] && echo "✗" || echo "✓"
}

set_prompt() {
  local user="${USER_COLOR}%n${RESET_COLOR}"
  local venv=""
  [[ -n "$VIRTUAL_ENV" ]] && venv="${VENV_COLOR}($(basename $VIRTUAL_ENV))${RESET_COLOR} "

  local path="${DIR_COLOR}$(shorten_path)${RESET_COLOR}"
  local git_info=""
  local branch="$(git_branch)"

  if [[ -n "$branch" ]]; then
    git_info=" %F{white}on%f ${GIT_COLOR}${branch}${RESET_COLOR}${GIT_DIRTY_COLOR}$(git_dirty)${RESET_COLOR}"
  fi

  PROMPT="${user} %F{white}in%f ${venv}${path}${git_info}
${PROMPT_SYMBOL_COLOR}λ${RESET_COLOR} "
}

autoload -Uz add-zsh-hook
add-zsh-hook precmd set_prompt

# plugins
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

[ -f "/home/venomade/.ghcup/env" ] && . "/home/venomade/.ghcup/env" # ghcup-env