various fixes
[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, or else
14 # we risk screwing up history history. And this is duplicated
15 # in ~/.bash_profile just for good measure
16 # history number. History expansion is good.
17 PS4='$LINENO+ '
18 # history file size limit, set to unlimited.
19 # this needs to be different from the default because
20 # default HISTFILESIZE is 500 and could clobber our history
21 HISTFILESIZE=
22 # max commands 1 session can append/read from history
23 HISTSIZE=1000000
24 # the time format display when doing the history command
25 # also, setting this makes the history file record time
26 # of each command as seconds from the epoch
27 HISTTIMEFORMAT="%Y-%m-%d %I:%M %p "
28 # consecutive duplicate lines dont go in history
29 HISTCONTROL=ignoredups
30 # works in addition to HISTCONTROL to do more flexible things
31 # it could also do the same things as HISTCONTROL and thus replace it,
32 # but meh. dunno why, but just " *" does glob expansion, so use [ ] to avoid it.
33 HISTIGNORE='pass *:[ ]*:otp *:oathtool *'
34
35
36 # see comments in brc2 sl() function for background.
37 if [[ $SSH_CONNECTION ]] \
38 && [[ $BRC != t ]]; then
39 brc() {
40 export BRC=t
41 source ~/.bashrc
42 }
43 return 0
44 else
45
46 # the distinction between login and non-login shells is lame,
47 # get rid of it. note ssh shells normally its login if a command is passed
48 if ! shopt -q login_shell; then
49 if [[ -r /etc/profile ]]; then
50 source /etc/profile
51 fi
52 # note, this is not exactly the same as a login shell, because that
53 # reads ~/.bash_profile or alternative, which usually just sources
54 # this file, and we don't want to do that and cause an infinite
55 # loop.
56 fi
57 _tmp=$(readlink -f ${BASH_SOURCE[0]})
58 _tmp=${_tmp%/*}
59 _tmp2=$_tmp/brc
60 if [[ -s $_tmp2 ]]; then
61 # shellcheck source=./brc
62 source $_tmp2
63 fi
64 # brc2 is for things i dont necessarily want on every system
65 _tmp2=$_tmp/brc2
66 if [[ -s $_tmp2 ]]; then
67 # shellcheck source=./brc2
68 source $_tmp2
69 else
70 # This check is for when running the sl() command,
71 # and the remote host got its type misidentified.
72 _tmp2=$_tmp/../brc2
73 if [[ -s $_tmp2 ]]; then
74 # shellcheck source=./brc2
75 source $_tmp2
76 fi
77 fi
78 fi
79
80
81 # ensure no bad programs appending to this file will have an affect
82 return 0