mostly fixes, a few improvements
[distro-setup] / .bashrc
1 #!/bin/bash
2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4
5 # to debug
6 #set -x
7 # redirect output to log file. this doesn't work. todo figure out why
8 #exec 1>>/a/tmp/bashlog
9 #exec 2>>/a/tmp/bashlog
10
11
12
13 # History related options first and always, or else we risk screwing up
14 # the history file. This is duplicated in ~/.bash_profile just for good
15 # measure
16
17 # History file size limit, set to unlimited.
18 # this needs to be different from the default because
19 # default HISTFILESIZE is 500 and could clobber our history
20 HISTFILESIZE=
21 # max commands 1 session can append/read from history
22 HISTSIZE=1000000
23 # the time format display when doing the history command
24 # also, setting this makes the history file record time
25 # of each command as seconds from the epoch
26 HISTTIMEFORMAT="%Y-%m-%d %I:%M %p "
27 # consecutive duplicate lines dont go in history
28 HISTCONTROL=ignoredups
29 # This works in addition to HISTCONTROL to do more flexible things
30 # it could also do the same things as HISTCONTROL and thus replace it,
31 # but meh. dunno why, but just " *" does glob expansion, so use [ ] to avoid it.
32 HISTIGNORE='pass *:otp *:oathtool *:histrm *'
33
34 # note: duplicated in /a/bin/ds/filesystem/etc/profile.d/environment.sh
35 umask 022
36
37
38
39 #### if (in
40 # noninteractive ssh shells or tty). tty because often i use it when
41 # something is going and io is slow and my bashrc is too slow.
42 if [[ $LC_USEBASHRC != t && ( $SSH_CONNECTION || $TERM == linux ) ]]; then
43 # Here we did not opt-in to running our .bashrc file so we just
44 # return, but we still setup a function to source it without returning
45 # so if we want it we don't have to restart our ssh connection.
46 brc() {
47 export LC_USEBASHRC=t
48 # shellcheck disable=SC1090 # obviously, no need to follow a sourcing of this file
49 source ~/.bashrc
50 }
51 return 0
52 else
53
54 ###### Begin sourcing of files #####
55
56 # The distinction between login and non-login shells is super lame
57 # and pretty random. get rid of that distinction.
58 if ! shopt -q login_shell; then
59 if [[ -r /etc/profile ]]; then
60 source /etc/profile
61 fi
62 # note, this is not exactly the same as a login shell, because that
63 # reads ~/.bash_profile or alternative, which usually just sources
64 # this file, and we don't want to do that and cause an infinite
65 # loop.
66 fi
67
68 # source brc and brc2 if they exist. We have to readlink because we
69 # could be using sl() from ./brc.
70 _tmp=$(readlink -f ${BASH_SOURCE[0]})
71 bashrc_dir=${_tmp%/*}
72 _tmp=$bashrc_dir/brc
73 if [[ -s $bashrc_dir ]]; then
74 # shellcheck source=./brc
75 source $_tmp
76 fi
77 # brc2 is for things i dont necessarily want on every system
78 _tmp=$bashrc_dir/brc2
79 if [[ -s $_tmp ]]; then
80 # shellcheck source=./brc2
81 source $_tmp
82 else
83 # This check is for when running the sl() command,
84 # and the remote host got its type misidentified.
85 _tmp=$bashrc_dir/../brc2
86 if [[ -s $_tmp ]]; then
87 # shellcheck source=./brc2
88 source $_tmp
89 fi
90 fi
91 if [[ $IANK_BASHRC_RUN ]]; then
92 $IANK_BASHRC_RUN ||:
93 fi
94 ###### End sourcing of files #####
95 fi
96 #### end section that works with sl() function to return from
97 #### noninteractive ssh shells
98
99
100 # ensure no bad programs appending to this file will have an affect
101 return 0
102
103 # kitty puts this here on startup, i need to build with some option to
104 # avoid it, whatever.
105
106 ## BEGIN_KITTY_SHELL_INTEGRATION
107 # if test -n "$KITTY_INSTALLATION_DIR" -a -e "$KITTY_INSTALLATION_DIR/shell-integration/bash/kitty.bash"; then source "$KITTY_INSTALLATION_DIR/shell-integration/bash/kitty.bash"; fi
108 ## END_KITTY_SHELL_INTEGRATION
109
110 # Automatically added by the Guix install script.
111 if [ -n "$GUIX_ENVIRONMENT" ]; then
112 if [[ $PS1 =~ (.*)"\\$" ]]; then
113 PS1="${BASH_REMATCH[1]} [env]\\\$ "
114 fi
115 fi