summaryrefslogtreecommitdiff
path: root/user/zsh/.zshrc
blob: a579784f847ed497d6fb17a1562fe64e1e0e692c (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
# This is my ZSH config file. I'm using ZSH over Bash
# because it has better autocompletion.

## Key bindings
# vi mode
bindkey -v
# default in Bash
bindkey "^R" history-incremental-search-backward

## Options
setopt autocd
setopt nomatch

## Functions
function ls() {
    # Hide the mess in the home directory by default.
    if [[ $PWD == $HOME ]]; then
        command ls "$@"
    else
        command ls --almost-all "$@"
    fi
}

## Aliases
alias ls='ls --color=auto --group-directories-first' # see also ls function
alias tree='tree -aI .git --dirsfirst'

## Shell variables
PS1='%F{magenta}'
  PS1+='%n'    # username
PS1+='%f'
PS1+='@'
PS1+='%m'      # hostname
PS1+=' '
PS1+='%B'
  PS1+='%40<..<' # truncate (40 chars, indicate with ..)
    PS1+='%~'    # current directory
  PS1+='%<<'
PS1+='%b'
PS1+=' '
PS1+='%#'      # `#` if the shell runs with privileges else `%`
PS1+=' '

HISTSIZE=1000000000
SAVEHIST=1000000000

## Environment variables
export XDG_CACHE_HOME=$HOME/.cache
export XDG_CONFIG_HOME=$HOME/.config

export EDITOR=vim
export INPUTRC=$XDG_CONFIG_HOME/readline/inputrc
export PYTHON_BASIC_REPL=1 # use readline (Python >=3.13 defaults to its own REPL which has no vi keybindings)

# If we'd extend the PATH with PATH=$PATH:extra the PATH would become longer with each subshell.
# In ZSH PATH is tied to the $path array. We force that array to have unique values:
typeset -U path PATH
# Now we can append PATH entries with path+=... without the PATH growing in each subshell.

## Completion
autoload -Uz compinit
[ -d "$XDG_CACHE_HOME"/zsh ] || mkdir -p "$XDG_CACHE_HOME"/zsh
compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-$ZSH_VERSION

# Environment-specifics
if [ -n "$MYNIX_DEV" ]; then
    source "$ZDOTDIR/zshrc-dev.sh"
fi
if [ -n "$MYNIX_GRAPHICAL" ]; then
    source "$ZDOTDIR/zshrc-graphical.sh"
fi