forked from Nthalk/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·68 lines (60 loc) · 1.67 KB
/
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
#!/bin/bash
TS=$(date +%s)
DOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function load {
TO=$1
FROM=$2
echo $TO
if [ -L $TO ]; then
echo "Removing stale link"
rm $TO
fi
if [ -e $TO ]; then
echo "Backing up: $TO"
mv $TO $TO.old.$TS
fi
echo "Updating $TO with $FROM"
ln -s $FROM $TO
}
echo "Creating default directories"
mkdir -p $HOME/local/src
mkdir -p $HOME/local/bin
mkdir -p $HOME/local/inst
mkdir -p $HOME/local/tmp
mkdir -p $HOME/.config
load $HOME/.tmux.conf $DOTDIR/tmux.conf
load $HOME/.vimrc $DOTDIR/vimrc
load $HOME/.emacs $DOTDIR/emacs
load $HOME/.vim $DOTDIR/vim
load $HOME/.config/fish $DOTDIR/fish
# Include ~/.bashrc in ~/.bash_profile
bashrc_include='[[ -s ~/.bashrc ]] && source ~/.bashrc'
if [ -e $HOME/.bash_profile ]; then
if ! grep -q 'source ~/.bashrc' $HOME/.bash_profile; then
echo "~/.bash_profile: adding include to ~/.bashrc"
echo $bashrc_include >> $HOME/.bash_profile
else
echo "~/.bash_profile: already includes ~/.bashrc"
fi
else
echo "~/.bash_profile: adding file to include ~/.bashrc"
echo $bashrc_include >> $HOME/.bash_profile
fi
# Conditionally add DOTDIR/bin to PATH
if [ -e $HOME/.bashrc ]; then
if ! grep -q "$DOTDIR/bin" $HOME/.bashrc; then
echo 'export PATH='$DOTDIR/bin':$PATH' >> $HOME/.bashrc
fi
else
echo 'export PATH='$DOTDIR/bin':$PATH' > $HOME/.bashrc
fi
# Conditionally add gitconfig
gitconfig=$gitconfig"[include]\n path = $DOTDIR/gitconfig"
if [ -e $HOME/.gitconfig ]; then
if ! grep -q "path = $DOTDIR/gitconfig" $HOME/.gitconfig; then
echo -e $gitconfig >> $HOME/.gitconfig
fi
else
echo -e $gitconfig > $HOME/.gitconfig
fi
load $HOME/.gitignore $DOTDIR/gitignore