summaryrefslogtreecommitdiff
path: root/home/baseline/zshrc.nix
blob: 9181159510ea2a03fb4395f724115ea9d781cc51 (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
{
  grml-zsh-config,
  local,
  ...
}: ''
  source ${grml-zsh-config}/etc/zsh/zshrc

  export PATH="$PATH:$HOME/.cargo/bin"

  alias gpicview='loupe'
  alias reset='tput reset'
  alias reload='exec zsh'
  alias this-date='date +%b%d | sed "s/^\w/\U&/g"'

  function spawn() {
    if [ ! -x "$(command -v $1)" ]; then
        echo "spawn: no such command: $1" >&2
        return 1
    fi

    $@ >/dev/null 0>&1 2>&1 &
    disown
  }

  function xseli() {
    T=$(mktemp)
    $EDITOR -n $T
    xsel -b <$T
    rm $T
  }

  autoload -Uz up-line-or-beginning-search
  zle -N up-line-or-beginning-search
  autoload -Uz down-line-or-beginning-search
  zle -N down-line-or-beginning-search
  bindkey '\eOA' up-line-or-beginning-search
  bindkey '\e[A' up-line-or-beginning-search
  bindkey '\eOB' down-line-or-beginning-search
  bindkey '\e[B' down-line-or-beginning-search

  INSTALLABLES=()
  while read -d: PATH_ITEM; do
    if [[ "$PATH_ITEM" =~ "^(/nix/store/[a-z0-9]+-([a-zA-Z][a-zA-Z0-9_]*(-[a-zA-Z][a-zA-Z0-9_]*)*)(-[^/]+)?)/" ]]; then
      INSTALLABLES+=("''${match[2]}")
    fi
  done <<<"$PATH"

  if [ "''${#INSTALLABLES[@]}" -gt 0 ]; then
    _GRML_NIX_SHELL="{''${INSTALLABLES[@]}} "
  fi

  unset INSTALLABLES PATH_ITEM

  function grml_nix_shell() {
    REPLY="$_GRML_NIX_SHELL"
  }

  grml_theme_add_token nix-shell -f grml_nix_shell '%F{red}' '%f'

  if [ -n "$SSH_CONNECTION" ]; then
    USERATHOST=1
  fi

  zstyle ':prompt:grml:left:setup' items time $([ ''${USERATHOST:-0} -eq 0 ] || echo user at host) path nix-shell percent
  zstyle ':prompt:grml:right:setup' items sad-smiley vcs $([ ''${BATTERY:-0} -eq 0 ] || echo battery)
  zstyle ':prompt:grml:right:items:time' pre ' %F{yellow}'

  unsetopt sharehistory
  setopt appendhistory
  setopt extendedhistory

  source ${local.git-aliases}
''