summaryrefslogtreecommitdiffstats
path: root/configs/bash/default.nix
blob: 0ec6bf00c4ade9d87de88c8d5549e66789271467 (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
{ config, mylib, pkgs, ... }: {
  environment.etc.inputrc.source = pkgs.writeText "inputrc" /* readline */ ''
    set bell-style visible
    set colored-stats on
    set editing-mode vi
    set show-mode-in-prompt on
    # [cursor] keep in sync with <hrm/configs/vim.nix>
    set vi-ins-mode-string \1\e[6 q\2
    set vi-cmd-mode-string \1\e[2 q\2
  '';
  programs.bash = {
    interactiveShellInit = /* sh */ ''
      HISTCONTROL='erasedups:ignorespace'
      HISTSIZE=900001
      HISTFILESIZE=$HISTSIZE
      HISTTIMEFORMAT=

      shopt -s checkhash
      shopt -s histappend histreedit histverify
      shopt -s no_empty_cmd_completion
      complete -d cd

      case $UID in
        ${mylib.shell.escape (toString config.krebs.users.tv.uid)})
          if test ''${SHLVL-1} = 1 && test -n "''${DISPLAY-}"; then
            _CURRENT_DESKTOP_NAME=''${_CURRENT_DESKTOP_NAME-$(
              ${pkgs.xorg.xprop}/bin/xprop -notype -root \
                  32i _NET_CURRENT_DESKTOP \
                  8s _NET_DESKTOP_NAMES \
                |
              ${pkgs.gnused}/bin/sed -r 's/.* = //;s/"//g;s/, /\a/g' |
              {
                read -r _NET_CURRENT_DESKTOP
                IFS=$'\a' read -ra _NET_DESKTOP_NAMES
                echo "''${_NET_DESKTOP_NAMES[$_NET_CURRENT_DESKTOP]}"
              }
            )}
            case $_CURRENT_DESKTOP_NAME in
              hrm)
                cd ~/hrm
              ;;
              stockholm)
                cd ~/stockholm
              ;;
            esac
          fi

          export NIX_PATH="stockholm=$HOME/stockholm:$NIX_PATH"
        ;;
      esac

      ${pkgs.bash-fzf-history.bind}

      if test -n "''${BASH_EXTRA_INIT-}"; then
        . "$BASH_EXTRA_INIT"
      fi
    '';
    promptInit = /* sh */ ''
      case $UID in
        0)
          PS1='\[\e[1;31m\]\w\[\e[0m\] '
          ;;
        ${toString config.krebs.build.user.uid})
          PS1='\[\e[1;32m\]\w\[\e[0m\] '
          ;;
        *)
          PS1='\[\e[1;35m\]\u \[\e[1;32m\]\w\[\e[0m\] '
          ;;
      esac
      if test -n "$SSH_CLIENT"; then
        PS1='\[\e[35m\]\h'" $PS1"
      fi
      if test -n "$SSH_AGENT_PID"; then
        PS1="ssh-agent[$SSH_AGENT_PID] $PS1"
      fi
    '';
  };
}