-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup
executable file
·52 lines (44 loc) · 1.67 KB
/
setup
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
#!/bin/bash
# shellcheck disable=SC1091
#
# Copyright (c) 2024 Ryan Domingue and contributors
# Report bugs at: https://github.com/goodguyry/dotfiles/issues
# This is free software with ABSOLUTELY NO WARRANTY.
# ------------------------------------------------------------------------------
# usage: ./setup.sh
#
# Adds the dotfiles command.
# ------------------------------------------------------------------------------
dotfiles_root=$(dirname "$(realpath "${BASH_SOURCE[0]}")");
cd "${dotfiles_root}" || exit 1;
# Initialize the git repository if necessary.
if [ -n "$(type -P git)" ]; then
if ! git rev-parse --is-inside-work-tree &> /dev/null; then
git init;
git remote add origin https://github.com/goodguyry/dotfiles;
git fetch origin master;
# Reset the index and working tree to the fetched HEAD.
git reset --hard FETCH_HEAD;
# Remove any untracked files.
git clean -fd;
# Pull down the latest changes.
git pull --rebase origin master;
fi;
fi;
# Source setup files.
source "${dotfiles_root}/lib/mmkd";
source "${dotfiles_root}/lib/setfile";
source "${dotfiles_root}/lib/setprefix";
source "${dotfiles_root}/lib/status";
mmkd "${HOME}/.bin" && status "Created '${HOME}/.bin'";
ln -sf "${dotfiles_root}/dotfiles" "${HOME}/.bin/dotfiles";
mmkd "${HOME}/.dotfiles";
if [[ $? ]]; then
for subcommand_file in "${dotfiles_root}"/bin/*; do
[[ -f "${subcommand_file}" ]] && setfile "${subcommand_file}" "${HOME}/.dotfiles/$(basename "${subcommand_file}")";
done;
else
status --error "Could not create ${HOME}/.dotfiles";
fi
setprefix dotfiles "${dotfiles_root}";
[ -n "$(type -P dotfiles)" ] && status --success "Done. Type 'dotfiles' to continue.";