-
Notifications
You must be signed in to change notification settings - Fork 0
/
symlink.sh
executable file
·76 lines (62 loc) · 2.48 KB
/
symlink.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
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
DOTFILES=~/dotfiles
OS_NAME=$(grep '^NAME=' /etc/os-release)
if [[ "$OS_NAME" == "NAME=NixOS" ]]; then
# TODO: link ~/dotfiles/nixos to /etc/nixos instead? can I?
echo you need to do something like
echo ln -s "$DOTFILES"/nixos/configuration.nix /etc/nixos/configuration.nix
echo ln -s "$DOTFILES"/nixos/hardware-configuration.nix /etc/nixos/hardware-configuration.nix
fi
echo "hopefully you read the source code of the script you're about to run"
sleep 3
BACKUP_DIRECTORY="$DOTFILES"/.linked_over_files_backup
# if the last argument is not a symlink, move it to a backup directory
# then link (ln -s) the second-last argument to that path instead
ln_if_not_link() {
mkdir -p "$BACKUP_DIRECTORY"
if [ ! -L "${@: -1}" ]; then
sudo mv "${@: -1}" "$BACKUP_DIRECTORY"/"${@: -1}"
ln -s "$DOTFILES"/"${@: -2}" ~/"${@: -1}"
fi
}
backup_if_not_link() {
if [ ! -L "${@: -1}" ]; then
# TODO: mkdir -p the parent if arg is a directory
sudo mv "${@: -1}" "$BACKUP_DIRECTORY"/"${@: -1}"
fi
}
# if the last argument is a symlink, pass all arguments to an "rm" command
rm_if_not_link() {
if [ ! -L "${@: -1}" ]; then
sudo rm "$@"
fi
}
ln_if_not_link bashrc ~/.bashrc > /dev/null 2>&1;
ln_if_not_link gitconfig ~/.gitconfig > /dev/null 2>&1;
ln_if_not_link gitignore ~/.gitignore > /dev/null 2>&1;
ln_if_not_link wgetrc ~/.wgetrc > /dev/null 2>&1;
ln_if_not_link inputrc ~/.inputrc > /dev/null 2>&1;
ln_if_not_link "$DOTFILES_PREFIX"/tmux.conf ~/.tmux.conf
ln_if_not_link "$DOTFILES_PREFIX"/tmux/ ~/.tmux
# TODO: do this idempotently and safely
# TODO: should I remove untracked files with git checkout -- ./config
# should probably prompt on that...
# Avoid getting into an incosistent state if you can't copy something from the existing ~/.config
# because it already exists in ~/dotfiles/config
if [[ ! -L ~/.config ]]; then
cp ~/.config/* "$DOTFILES"/config
ln -s "$DOTFILES"/config ~/.config
fi
# It's in ~/dotfiles/config/nvim/init.vim
rm_if_not_link ~/.nvimrc > /dev/null 2>&1;
rm_if_not_link ~/.nvim > /dev/null 2>&1;
# macOS specific
if [ "$(uname)" = "Darwin" ]; then
# Terminal.app doesn't read .bashrc, but .profile works
echo >> ~/.profile
echo 'source ~/.bashrc' >> ~/.profile
ln_if_not_link macos/bash_mac.sh ~/.bash_mac
# TODO: check if this still has any effect
mkdir -p ~/Library/KeyBindings
ln_if_not_link macos/system_wide_emacs_movement.dict ~/Library/KeyBindings/DefaultKeyBinding.dict
fi