aboutsummaryrefslogtreecommitdiff
path: root/home/dot_zshrc
blob: 6220015247e48c0385f4fd6f71ace2c71e15499f (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
#!/bin/zsh
export ZSH_COMPDUMP="$XDG_CACHE_HOME/zcompdump"

# do not glob for calculator command
aliases[=]="noglob ="

# color aliases
alias ls='ls --color=auto'
alias grep='grep --color=auto'

# completion
autoload -U compinit
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*' special-dirs true
setopt auto_menu # show completion menu when spamming <tab>
setopt complete_in_word
setopt always_to_end # move cursor to end of word after completion
setopt auto_cd # cd if the command is a valid path
WORDCHARS="${WORDCHARS:gs/\//}" # remove '/' from WORDCHARS
compinit -d "$ZSH_COMPDUMP"

# history
! [ -d "$XDG_DATA_HOME/zsh" ] && mkdir -p "$XDG_DATA_HOME/zsh"
export HISTFILE="$XDG_DATA_HOME/zsh/history"
export HISTSIZE=10000000
export SAVEHIST=10000000
setopt hist_ignore_space
setopt share_history
setopt hist_ignore_dups

# keybinds
bindkey -e # emacs bindings
bindkey '^[[Z' reverse-menu-complete

# prompt
setopt PROMPT_SUBST
export VIRTUAL_ENV_DISABLE_PROMPT=y
PROMPT='$(eo=%{ ec=%} prompt)'

# auto venv
function cd() {
	builtin cd "$@"

	if [ -n "$VIRTUAL_ENV" ] ; then
		if [[ "$PWD"/ != "$(dirname "$VIRTUAL_ENV")"/* ]] && [ ! -z "$(command -v deactivate)" ] ; then
			deactivate
		else
			return
		fi
	fi

	git_dir="$(git rev-parse --show-toplevel 2>/dev/null)"
	for dir in ./ "$git_dir" ../ "$git_dir/.." ; do
		[ ! -d "$dir" ] && continue
		for file in "$dir"/.env "$dir"/venv/bin/activate ; do
			[ ! -e "$file" ] && continue
			source "$file"
			return
		done
	done
}