~gpanders/dotfiles

ref: 1508bbe8dea4b5bc9bdd87abb914c482cc97e4c6 dotfiles/setup.sh -rwxr-xr-x 3.9 KiB
1508bbe8Greg Anders Add scdoc ftplugin 1 year, 11 months ago
                                                                                
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/sh

uname="$(uname)"

installed() {
    command -v "$1" >/dev/null
}

install() {
    case $uname in
        Darwin)
            brew install "$@"
            ;;
        Linux)
            if installed apt-get; then
                sudo apt-get install -y "$@"
            elif installed yum; then
                sudo yum install "$@"
            elif installed pacman; then
                sudo pacman -S "$@"
            fi
            ;;
        *)
            echo "Unknown OS" >&2
            return 1
            ;;
    esac
}

ask() {
    printf "%s [y/N] " "$1"
    read -r ans
    printf "\n"
    if echo "$ans" | grep -qE '^([Yy]|[Yy][Ee][Ss])+$'; then
        return 0
    else
        return 1
    fi
}

if ! installed stow; then
    install stow
fi

ARGS="$*"

if [ $# -eq 0 ]; then
    ARGS="vim neovim git bash pylint flake8"

    if [ "$uname" = "Linux" ]; then
        ARGS="$ARGS X"
    fi

    if [ "$uname" = "Darwin" ]; then
        ARGS="$ARGS alacritty"
    fi

    if installed ranger; then
        ARGS="$ARGS ranger"
    fi

    for mod in ctags fish khard khal pandoc tmux vdirsyncer weechat zsh; do
        if installed $mod || (ask "Install $mod?" && install $mod); then
            ARGS="$ARGS $mod"
        fi
    done

    if ! installed fzy && ask "Install fzy?"; then
        install fzy
    fi

    if ! installed nnn && ask "Install nnn?"; then
        install nnn
    fi

    if installed i3 || ([ "$uname" = Linux ] && ask "Install i3?" && install i3wm conky); then
        ARGS="$ARGS i3 conky"
    fi

    if ! (installed mutt || installed neomutt) || ! installed mbsync; then
        if ask "Install email tools?"; then
            if ! installed mutt && ! installed neomutt; then
                install neomutt

                # Symlink `mutt` to `neomutt`
                if [ ! -s "$(dirname "$(command -v neomutt)")/mutt" ]; then
                    cd "$(dirname "$(command -v neomutt)")" || exit 1
                    sudo ln -s neomutt mutt
                    sudo chown --reference=neomutt mutt
                    cd "$OLDPWD" || exit 1
                fi
            fi

            if ! installed mbsync; then
                install isync
            fi

            if ! installed urlview; then
                install urlview
            fi

            if ! installed w3m; then
                install w3m
            fi
        fi
    fi

    if installed mutt || installed neomutt; then
        ARGS="$ARGS mutt"
    fi

    if installed offlineimap; then
        ARGS="$ARGS offlineimap"
    fi

    if installed isync || installed mbsync; then
        ARGS="$ARGS isync"
    fi
fi

for mod in $ARGS; do
    if [ -d "$mod" ]; then
        echo "Installing symlinks for $mod"
        stow -t "$HOME" "$mod"
    fi

    # Handle special cases
    case $mod in
        tmux)
            if installed tmux; then
                # Install tmux plugins in a background session
                git submodule update --init
                tmux new-session -s install_plugins -d "tmux run-shell $HOME/.tmux/plugins/tpm/bindings/install_plugins"
            fi

            if ! infocmp tmux-256color >/dev/null 2>&1; then
                tic -x tmux/.local/share/tmux/terminfo/tmux-256color
            fi
            ;;
        git)
            # This repository should always use my personal email
            git config --local user.email greg@gpanders.com

            # Alias for just the dotfiles repo
            git config --local alias.update "!git fetch origin master:master && git rebase --autostash master"
            ;;
        zsh)
            if ! installed antibody; then
                if [ "$uname" = Darwin ]; then
                    brew install getantibody/tap/antibody
                else
                    mkdir -p "$HOME"/.local
                    curl -sfL git.io/antibody | sh -s - -b "$HOME"/.local/bin
                fi
            fi
            ;;
    esac
done

echo " "
echo "Setup complete."