aboutsummaryrefslogtreecommitdiff
path: root/install
blob: 5b3c1ded9b90974aa4b799a826492f5c5d4d64ba (plain) (blame)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash

#
# Author: Tom Ryder (@tejr) <tom@sanctum.geek.nz>
#
# This script installs @tejr's dotfiles in $HOME with symlinks into the
# expected $HOME/.dotfiles path.
#
# By default, it checks out all Git submodules, and links in configuration for
# Bash, cURL, Git, Vim, and some terminfo(5) definitions. You can supply
# additional flags to link in other configuration files:
#
#   -d -- mysql/psql
#   -g -- GnuPG
#   -m -- Mutt
#   -n -- Ncmpcpp
#   -r -- Newsbeuter
#   -t -- tmux
#   -x -- X11
#
# You should be prompted about replacing any file or directory that already
# exists. I have tried to make the function that does this relatively safe, but
# there are almost certainly edge cases where it might break things, especially
# on systems other than GNU/Linux or BSD.
#
# Run this at your own risk!
#   

# Replace existing file with link if user confirms
lns() {
    local file=$1 link=$2
    if [[ -e $link ]]; then
        read -p "$link already exists; remove? [y/N] " confirm
        case $confirm in
            y*|Y*) 
                rm -r -- "$link"
                ln -s -- "$file" "$link"
                return
                ;;
            *)
                return 1
                ;;
        esac
    else
        ln -s -- "$file" "$link"
    fi
    return
}

# Bail if we don't have git(1)
if ! hash git 2>/dev/null; then
    printf 'install: Could not find git(1)!\n' >&2
    exit 1
fi

# Define dotfiles directory and check it exists
dotfiles=$HOME/.dotfiles
if ! [[ -d $dotfiles ]]; then
    printf 'install: Could not find %s!\n' "$dotfiles" >&2
    exit 1
fi

# Check out submodules
(cd -- "$dotfiles" && git submodule update --init)

# Link in essential logical binaries
mkdir -p -- "$HOME"/.local/bin
lns "$dotfiles"/ack/ack "$HOME"/.local/bin/ack

# Link in essential configuration files
mkdir -p -- "$HOME"/.config
lns "$dotfiles"/ack/ackrc            "$HOME"/.ackrc
lns "$dotfiles"/bash/bash_completion "$HOME"/.config/bash_completion
lns "$dotfiles"/bash/bash_logout     "$HOME"/.bash_logout
lns "$dotfiles"/bash/bash_profile    "$HOME"/.bash_profile
lns "$dotfiles"/bash/bashrc          "$HOME"/.bashrc
lns "$dotfiles"/bash/bashrc.d        "$HOME"/.bashrc.d
lns "$dotfiles"/curl/curlrc          "$HOME"/.curlrc
lns "$dotfiles"/git/gitconfig        "$HOME"/.gitconfig
lns "$dotfiles"/readline/inputrc     "$HOME"/.inputrc
lns "$dotfiles"/sh/profile           "$HOME"/.profile
lns "$dotfiles"/sh/profile.d         "$HOME"/.profile.d
lns "$dotfiles"/vim/vimrc            "$HOME"/.vimrc
lns "$dotfiles"/vim                  "$HOME"/.vim

# Link in shell stuff
while getopts :dgmnrtx opt; do
    case $opt in
        d)
            lns "$dotfiles"/mysql/my.cnf "$HOME"/.my.cnf
            lns "$dotfiles"/psql/psqlrc  "$HOME"/.psqlrc
            ;;
        g)
            mkdir -p -- "$HOME"/.gnupg
            lns "$dotfiles"/gnupg/gpg.conf       "$HOME"/.gnupg/gpg.conf
            lns "$dotfiles"/gnupg/gpg-agent.conf "$HOME"/.gnupg/gpg-agent.conf
            ;;
        m)
            lns "$dotfiles"/mutt/muttrc "$HOME"/.muttrc
            lns "$dotfiles"/mutt        "$HOME"/.mutt
            ;;
        n)
            lns "$dotfiles"/ncmpcpp "$HOME"/.ncmpcpp
            ;;
        r)
            mkdir -p -- "$HOME"/.config "$HOME"/.local/share/newsbeuter
            lns "$dotfiles"/newsbeuter "$HOME"/.config/newsbeuter
            ;;
        t)
            lns "$dotfiles"/tmux/tmux.conf "$HOME"/.tmux.conf
            ;;
        x)
            lns "$dotfiles"/i3           "$HOME"/.i3
            lns "$dotfiles"/X/Xmodmap    "$HOME"/.Xmodmap
            lns "$dotfiles"/X/Xresources "$HOME"/.Xresources
            lns "$dotfiles"/X/xsession   "$HOME"/.xsession
            lns "$dotfiles"/X/xsessionrc "$HOME"/.xsessionrc
            lns "$dotfiles"/vim/gvimrc   "$HOME"/.gvimrc
            ;;
    esac
done
shift $((OPTIND-1))

# Compile terminfo files
if hash tic 2>/dev/null; then
    for info in "$dotfiles"/terminfo/*.info; do
        tic "$info"
    done
fi