ac78814f350e48ee565201e335e4af9f19216859
[distro-setup] / .bashrc
1 #!/bin/bash
2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
7 # its license to GPL.
8
9 # Copyright 2024 Ian Kelling
10
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
14
15 # http://www.apache.org/licenses/LICENSE-2.0
16
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
22
23 # shellcheck disable=SC2317
24
25 # to debug
26 #set -x
27 # redirect output to log file. this doesn't work. todo figure out why
28 #exec 1>>/a/tmp/bashlog
29 #exec 2>>/a/tmp/bashlog
30
31
32
33 # History related options first and always, or else we risk screwing up
34 # the history file. This is duplicated in ~/.bash_profile just for good
35 # measure
36
37 # History file size limit, set to unlimited.
38 # this needs to be different from the default because
39 # default HISTFILESIZE is 500 and could clobber our history
40 HISTFILESIZE=
41 # max commands 1 session can append/read from history
42 HISTSIZE=1000000
43 # the time format display when doing the history command
44 # also, setting this makes the history file record time
45 # of each command as seconds from the epoch
46 HISTTIMEFORMAT="%Y-%m-%d %I:%M %p "
47 # consecutive duplicate lines dont go in history
48 HISTCONTROL=ignoredups
49 # This works in addition to HISTCONTROL to do more flexible things
50 # it could also do the same things as HISTCONTROL and thus replace it,
51 # but meh. dunno why, but just " *" does glob expansion, so use [ ] to avoid it.
52 HISTIGNORE='pass *:otp *:oathtool *:histrm *'
53
54 # note: duplicated in /a/bin/ds/filesystem/etc/profile.d/environment.sh
55 umask 022
56
57
58 if [[ $EUID == 1000 && $TERM == linux && ! $DISPLAY && $(tty) = /dev/tty1 && -x /usr/bin/startx ]]; then
59 if tmp=$(systemctl status |& head) && \
60 grep -qi '^ *state: running' <<<"$tmp" && grep -qi '^ *failed: 0' <<<"$tmp" && grep -qi '^ *jobs: 0' <<<"$tmp"; then
61 startx
62 else
63 echo "systemctl status |& head:"
64 printf "%s\n" "$tmp"
65 echo: systemctl list-jobs:
66 systemctl list-jobs
67 fi
68 fi
69
70 #### if (in
71 # noninteractive ssh shells or tty). tty because often i use it when
72 # something is going and io is slow and my bashrc is too slow.
73 if [[ $LC_USEBASHRC != t && ( $SSH_CONNECTION || $TERM == linux ) ]]; then
74 # Here we did not opt-in to running our .bashrc file so we just
75 # return, but we still setup a function to source it without returning
76 # so if we want it we don't have to restart our ssh connection.
77 brc() {
78 export LC_USEBASHRC=t
79 # shellcheck disable=SC1090 # obviously, no need to follow a sourcing of this file
80 source ~/.bashrc
81 }
82 return 0
83 else
84
85 ###### Begin sourcing of files #####
86
87 # The distinction between login and non-login shells is super lame
88 # and pretty random. get rid of that distinction.
89 if ! shopt -q login_shell; then
90 if [[ -r /etc/profile ]]; then
91 source /etc/profile
92 fi
93 # note, this is not exactly the same as a login shell, because that
94 # reads ~/.bash_profile or alternative, which usually just sources
95 # this file, and we don't want to do that and cause an infinite
96 # loop.
97 fi
98
99 # source brc and brc2 if they exist. We have to readlink because we
100 # could be using sl() from ./brc.
101 _tmp=$(readlink -f ${BASH_SOURCE[0]})
102 bashrc_dir=${_tmp%/*}
103 _tmp=$bashrc_dir/brc
104 if [[ -s $bashrc_dir ]]; then
105 # shellcheck source=./brc
106 source $_tmp
107 fi
108 # brc2 is for things i dont necessarily want on every system
109 _tmp=$bashrc_dir/brc2
110 if [[ -s $_tmp ]]; then
111 # shellcheck source=./brc2
112 source $_tmp
113 else
114 # This check is for when running the sl() command,
115 # and the remote host got its type misidentified.
116 _tmp=$bashrc_dir/../brc2
117 if [[ -s $_tmp ]]; then
118 # shellcheck source=./brc2
119 source $_tmp
120 fi
121 fi
122 if [[ $IANK_BASHRC_RUN ]]; then
123 $IANK_BASHRC_RUN ||:
124 fi
125 ###### End sourcing of files #####
126 fi
127 #### end section that works with sl() function to return from
128 #### noninteractive ssh shells
129
130
131 # ensure no bad programs appending to this file will have an affect
132 return 0
133
134 # kitty puts this here on startup, i need to build with some option to
135 # avoid it, whatever.
136
137 ## BEGIN_KITTY_SHELL_INTEGRATION
138 # 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
139 ## END_KITTY_SHELL_INTEGRATION
140
141 # Automatically added by the Guix install script.
142 if [ -n "$GUIX_ENVIRONMENT" ]; then
143 if [[ $PS1 =~ (.*)"\\$" ]]; then
144 PS1="${BASH_REMATCH[1]} [env]\\\$ "
145 fi
146 fi