-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_aliases
59 lines (49 loc) · 1.4 KB
/
.bash_aliases
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
# Personal BASH adaptions
if [ `basename $SHELL` != "bash" ]; then exit; fi
PATH=$HOME/bin:/local/bin:$PATH
HISTTIMEFORMAT='%F %T '
_history ()
{
case $1 in
"")
history
;;
m)
TTY=`tty|sed -e "s/\/dev\///"`; sort ~/.persistent_history | grep $TTY
;;
p)
sort ~/.persistent_history
;;
*)
cat <<_EOF
Usage: h <option>, where option is:
h standard Bash history
m my personal persistant history
p full persistant history
_EOF
;;
esac
}
### PERSISTENT HISTORY
PROMPT_COMMAND="persistent_history"
persistent_history ()
{
local PHexit=$?
local PHuser PHtty PHhost
read PHuser PHtty PHhost <<< $(who am i | tr -d "[()]" | awk '{ print $1,$2,$NF }')
if [ -z $PHuser ]; then PHuser=`id -nu`; fi
if [ -z $PHtty ]; then PHtty=`tty|sed -e 's/\/dev\///'`; fi
if [ -z $PHhost ]; then PHhost=`hostname -i`; fi
[[ $(history 1) =~ ^\ *[0-9]+\ +([^\ ]+\ [^\ ]+)\ +(.*)$ ]]
local PHdate="${BASH_REMATCH[1]}"
local PHcmd="${BASH_REMATCH[2]}"
# Suppress recurring comands in persistent history
if [ "$PHcmd" != "$PERSISTENT_HISTORY_LAST" ]
then
echo $PHdate $PHhost $PHtty $PHexit "|" "$PHcmd" >> ~/.persistent_history
export PERSISTENT_HISTORY_LAST="$PHcmd"
fi
}
alias h="_history $@"
alias l='ls -alF --group-directories-first'
alias ..='cd ..'