-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbash_profile.txt
More file actions
63 lines (54 loc) · 2.26 KB
/
bash_profile.txt
File metadata and controls
63 lines (54 loc) · 2.26 KB
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
# ~/.bash_profile: executed by bash(1) for login shells.
## Long/Short hostname: the distiction is not available on windows
if [ -z "$MINGW_CHOST" && -z "$MSYSTEM" ] ; then
HOST=`hostname | sed -e 's/\..*//g'`
export HOST
else
HOSTNAME=`/bin/hostname -f`
HOST=`/bin/hostname -s 2 >/dev/null`
if [ "$?" -eq "1" ] ; then
HOST=`hostname | sed -e 's/\..*//g'`
fi
export HOST HOSTNAME
fi
## If not running interactively, do not do anything more
[[ $- != *i* ]] && return
## Otherwise, do sqlite logging, starting with the session
UNAME=$(uname -a)
export UNAME
SQLITEFILE="$HOME/.bash_history-$HOST.db"
export SQLITEFILE
## In case the files are deployed on a new host
[[ -z $SID ]] && export SID=$(sqlite3 "$SQLITEFILE" "
CREATE TABLE IF NOT EXISTS sessions ( -- table of the session, pk unique for host+time
sid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
login TIMESTAMP NOT NULL DEFAULT current_timestamp,
-- bash login timestamp
logout TIMESTAMP NULL, -- bash logout timestamp
user TEXT, -- username to merge different databases later
uname TEXT -- complete kernel version
);
CREATE TABLE IF NOT EXISTS commands ( -- table of the commands, pk autoincremented
cid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
ssid INTEGER NOT NULL, -- foreign key session(sid)
seq INTEGER NOT NULL, -- deduplicate pipes + detect suspicious holes
start TIMESTAMP NOT NULL DEFAULT current_timestamp,
-- execution begins when enter is pressed
stop TIMESTAMP NULL, -- ends when prompt shown again, empty if SIGINT
err INTEGER NULL, -- eventual returned code
what TEXT, -- command line as it was typed
path TEXT, -- context where the command line was typed
FOREIGN KEY (ssid) REFERENCES sessions(sid) ON DELETE CASCADE,
UNIQUE (ssid, seq)
);
INSERT INTO sessions (user,uname) VALUES (
'${USER//\'/''}', '${UNAME//\'/''}'
);
SELECT max(sid) from sessions;
")
##### Run a multiplexer if doing a remote login?
#[[ -z "$TMUX" ]] && exec tmux
### Run the normal aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi