-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·133 lines (104 loc) · 3.71 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·133 lines (104 loc) · 3.71 KB
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
#!/bin/bash
function check_prereqs {
if [[ "$DARWIN" == "1" ]] && [[ -n "$(which brew)" ]]; then
brew install git bash-completion vim tmux ripgrep
return
fi
if [[ -n "$(which apt)" ]] && [[ "$(sudo -n echo hello 2>/dev/null)" == "hello" ]]; then
sudo apt update && sudo apt install -y git bash-completion vim tmux ripgrep
return
fi
}
function create_if_not_exist {
FILE="$1"
if [[ ! -f "$FILE" ]]; then
echo -e "Creating $FILE"
touch "$FILE"
fi
}
function add_line_if_not_present {
FILE="$1"
LINE="$2"
if ! grep -q "$LINE" "$FILE"; then
echo "$LINE" >>"$FILE"
fi
}
function install_gitconfig {
git config --global include.path "$DOTFILE_DIR/git/gitconfig.ini"
if [[ -n "$GITHUB_REPOSITORY" ]] && [[ ! $GITHUB_REPOSITORY == github/* ]]; then
echo "Detected that you are not working on a github.com repository."
git config --global user.email "mitchell.rysavy@gmail.com"
fi
}
function install_bashrc {
BASHRC_FILE="$HOME/.bashrc"
BASHPROFILE_FILE="$HOME/.bash_profile"
if [[ "$DARWIN" == "1" ]]; then
# On Mac: add all sourced files to .bash_profile
create_if_not_exist "$BASHPROFILE_FILE"
add_line_if_not_present "$BASHPROFILE_FILE" "export DOTFILE_DIR=$DOTFILE_DIR"
add_line_if_not_present "$BASHPROFILE_FILE" "source \"\$DOTFILE_DIR/bash/bashrc.sh\""
else
create_if_not_exist "$BASHRC_FILE"
add_line_if_not_present "$BASHRC_FILE" "export DOTFILE_DIR=$DOTFILE_DIR"
add_line_if_not_present "$BASHRC_FILE" "source \"\$DOTFILE_DIR/bash/bashrc.sh\""
fi
}
function install_tmuxconf {
if [[ -z "$(which tmux)" ]]; then
echo -e "tmux is not found."
return
fi
TMUXRC_FILE="$HOME/.tmux.conf"
TMUXRC_SRC_LINE="source-file \"\$DOTFILE_DIR/tmux/tmux.conf\""
create_if_not_exist "$TMUXRC_FILE"
add_line_if_not_present "$TMUXRC_FILE" "$TMUXRC_SRC_LINE"
}
function install_vimrc {
if [[ -z "$(which vim)" ]]; then
echo -e "vim is not found."
return
fi
VIMRC_FILE="$HOME/.vimrc"
VIM_SRC_LINE="so $DOTFILE_DIR/vim/vim.vim"
VIMRC_SRC_LINE="so $DOTFILE_DIR/vim/vimrc.vim"
create_if_not_exist "$VIMRC_FILE"
add_line_if_not_present "$VIMRC_FILE" "$VIM_SRC_LINE"
add_line_if_not_present "$VIMRC_FILE" "$VIMRC_SRC_LINE"
curl -fLo "$HOME/.vim/autoload/plug.vim" --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
}
function install_neovimrc {
if [[ -z "$(which nvim)" ]]; then
echo -e "neovim is not found."
return
fi
NVIM_CFG="$HOME/.config/nvim"
mkdir -p "$NVIM_CFG/plugged/"
PLUG_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/site/autoload/plug.vim"
VIMRC_FILE="$NVIM_CFG/init.vim"
NVIM_SRC_LINE="so $DOTFILE_DIR/vim/neovim.vim"
VIMRC_SRC_LINE="so $DOTFILE_DIR/vim/vimrc.vim"
curl -fLo "$PLUG_DIR" --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
create_if_not_exist "$VIMRC_FILE"
add_line_if_not_present "$VIMRC_FILE" "$NVIM_SRC_LINE"
add_line_if_not_present "$VIMRC_FILE" "$VIMRC_SRC_LINE"
}
# As always, props to
# https://stackoverflow.com/questions/59895/how-can-i-get-the-source-directory-of-a-bash-script-from-within-the-script-itsel
export DOTFILE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
echo -e "We appear to be running from $DOTFILE_DIR..."
if [[ "$OSTYPE" == "darwin"* ]]; then
echo -e "Mac detected!"
DARWIN=1
else
DARWIN=0
fi
if [[ "$CODESPACES" == "true" ]]; then
echo -e "Codespaces detected!"
fi
check_prereqs
install_bashrc
install_tmuxconf
install_vimrc
install_neovimrc
install_gitconfig