about summary refs log tree commit diff
path: root/configs/shared/.zshrc
blob: a8ea2657d7232d082941378ad5dd6d9004a960ea (plain) (blame)
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
# Necessary to add this line and keep it at the top of my ~/.zshrc to ensure
# that Tramp works as expected. This was taken from here:
# https://www.emacswiki.org/emacs/TrampMode
[[ $TERM == "dumb" ]] && unsetopt zle && PS1='$ ' && return

source ~/antigen.zsh

# Helper functions
# TODO: Find a way to share these functions across zsh files.
defensively_source() {
  # Checks if the file exists before sourcing it
  if [ -f $1 ]; then
    source $1
  else
    "Cannot source: $1. Aborting..."
  fi
}

command_exists() {
  # Predicate to check if the command exists
  command -v $1 >/dev/null
}

# Load the oh-my-zsh library
antigen use oh-my-zsh

# Bundles from robbyrussell's oh-my-zsh repo.
antigen bundle git
antigen bundle extract         # extracts archives polymorphically
antigen bundle zsh-completions # extracts archives polymorphically

# Syntax highlighting
antigen bundle zsh-users/zsh-syntax-highlighting

# Theming
case $(hostname) in
  $DESKTOP)     antigen theme frisk;;
  $LAPTOP)      antigen theme refined;;
  $CLOUDTOP)    antigen theme cloud;;
  acer-manjaro) antigen theme frisk;;
esac

# Leave this last
antigen apply

# Configure fzf
if command_exists fzf-share; then
  source "$(fzf-share)/key-bindings.zsh"

  fzf-locate-widget() {
    # Press M-i to search entire locate database with fzf.
    local selected
    if selected=$(locate / | fzf); then
      LBUFFER+=$selected
    fi
    zle redisplay
  }
  zle -N fzf-locate-widget
  bindkey '\ei' fzf-locate-widget

else
  defensively_source "/usr/share/fzf/key-bindings.zsh"
fi

# Configure fasd
eval "$(fasd --init auto)"

# the above line slows tab-completion down dramatically because it attemtps to
# autocomplete for the 600k+ users found in `compgen -u`. Below is a fix which
# also restores the function of `cd ~<tab>` to display only ZSH Named
# Directories.
zstyle ':completion:*' users root $USER

# Avoiding the defensive source because I want to ensure these files are
# available.
source "$DOTFILES/configs/shared/variables.zsh"
source "$DOTFILES/configs/shared/aliases.zsh"
source "$DOTFILES/configs/shared/functions.zsh"
source "$DOTFILES/configs/shared/zle.zsh"

preexec() {
  # `preexec` runs before every command is run.
  update_x11_forwarding
}

defensively_source ~/.rvm/scripts/rvm         # Ruby
defensively_source ~/.opam/opam-init/init.zsh # OCaml
defensively_source ~/.ghcup/env               # Haskell
defensively_source /etc/bash_completion.d/g4d # Google's g4d