summaryrefslogtreecommitdiff
path: root/config/bash.nix
blob: ae54f9e14c49f86bc8baa9f2d0147837ab2870bd (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
{
  programs.bash = {
    enable = true;
    initExtra= ''
      function timer_start {
        timer=''${timer:-$SECONDS}
      }

      function timer_stop {
        timer_show=$(($SECONDS - $timer))
        unset timer
      }

      trap 'timer_start' DEBUG

      if [ "$PROMPT_COMMAND" == "" ]; then
        PROMPT_COMMAND="timer_stop"
      else
        PROMPT_COMMAND="$PROMPT_COMMAND; timer_stop"
      fi
      export PS1='\[\e[38;5;243m\](''${timer_show}s) \h \[\e[38;5;254m\]\w \[\033[0m\]> '

      bind "set completion-ignore-case on"

      if [[ -n "$IN_NIX_SHELL" ]]; then
        export PS1="\[\e[38;5;242m\](dev) $PS1"
      fi

      sessionizer() {
        DIR=$(fd . /home/compromyse --type d -L -d 3 | fzf)
        SESSION_NAME="$DIR_$(date +%M%S)"

        if [ -n "$DIR" ]
        then
          cd $DIR
        fi
      }

      if [[ $- != *i* ]]
      then
        sessionizer
      fi

      bind '"\C-f": "sessionizer\n"'

      alias poof="rm $HOME/.ssh/known_hosts*"

      if [ -f $HOME/.custom_bashrc ]; then
        source $HOME/.custom_bashrc
      fi
    '';
  };
}