-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory-install.sh
84 lines (66 loc) · 2.03 KB
/
history-install.sh
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
#
# history-recall install script
#
# To install:
#
# $ source history-install.sh [--bashrc | --bash_profile | --profile]
#
# By default, this script will install to ~/.bash_profile, unless it looks like
# ~/.bash_profile sources ~/.bashrc (recommended), in which case we install to ~/.bashrc.
# You may stipulate the exact install location by providing the appropriate flag.
#
HISTORYRC="$HOME/.historyrc"
# Get the path to the directory this script was ran from
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# Presume that we will install to .bash_profile. If it looks like
# .bash_profile is including .bashrc, then we will install to .bashrc.
INSTALL_TO=".bash_profile"
if [ ! -f "$INSTALL_TO" ] || grep -q bashrc "$HOME/$INSTALL_TO" ; then
INSTALL_TO=".bashrc"
fi
# Parse options
while [ $# -gt 0 ] ; do
option=$1
shift
case "$option" in
--bashrc )
INSTALL_TO=".bashrc"
;;
--bash_profile )
INSTALL_TO=".bash_profile"
;;
--profile )
INSTALL_TO=".profile"
;;
esac
done
# Do not overwrite existing installations
if [ -f "$HISTORYRC" ] ; then
echo "history-recall is already installed (~/.historyrc file exists)"
return
fi
# Write our .historyrc file
cat <<- __EOF__ > $HISTORYRC
#!/bin/bash
#
# Configuration file for history-recall script
# See: https://github.com/g1a/history-recall
#
# Source history-recall script.
source "$SCRIPT_DIR/history-recall.sh"
__EOF__
echo 'Created new ~/.historyrc configuration file.'
# If it looks like the fdrc file is already being sourced, then exit.
if grep -q historyrc "$HOME/$INSTALL_TO" ; then
echo "~/.historyrc configuration file is already sourced from ~/$INSTALL_TO)"
return
fi
cat <<- __EOF__ >> "$HOME/$INSTALL_TO"
# Source the history-recall configuration file.
# See: https://github.com/g1a/history-recall
source "$HOME/.historyrc"
__EOF__
echo "Installed 'source ~/.historyrc' in ~/$INSTALL_TO"
# Source history-recall so that it is available in this shell.
source ~/.historyrc