-
Notifications
You must be signed in to change notification settings - Fork 6
/
link.sh
executable file
·97 lines (79 loc) · 3.25 KB
/
link.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
# vim:filetype=sh:
# dmz: Setup my Dotfiles / viM / zshrc / gitconfig
# http://git.io/dmz
# idempotent bash: https://arslan.io/2019/07/03/how-to-write-idempotent-bash-scripts/
# https://github.com/anordal/shellharden/blob/master/how_to_do_things_safely_in_bash.md
set -o errexit # Exit on error. Append "|| true" if you expect an error.
set -o errtrace # Exit on error inside any functions or subshells.
set -o nounset # Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
set -o pipefail # Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
##
## Preconditions
##
require() { hash "$@" || exit 127; }
println() { printf '%s\n' "$*"; }
die() { ret=$?; printf "%s\n" "$@" >&2; exit "$ret"; }
msg() { echo >&2 -e "${1-}"; }
require curl
require git
require tmux
# Change directories to where this script is located
#cd "$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
canonical=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)")
cd "$canonical"
# Create temp folder for all the files being backed up
B=$(mktemp -d /tmp/dotfiles.XXXX)
link() {
if [[ -e $1 ]]; then
# println "$1 -> $2"
cp -pL "$2" "$B" 2>/dev/null || true # (p)reserve attributes and deference symbolic links
mkdir -p $(dirname $2) # ensure target file directory exists
ln -sf "$PWD/$1" "$2" # link target
fi
}
cpn() {
cp -n "$1" "$2" || true
}
link zshrc ~/.zshrc
link zlogin ~/.zlogin
link vimrc ~/.vimrc # minimal vimrc for VIM v8
link tmux.conf ~/.tmux.conf
link tmux.reset.conf ~/.tmux.reset.conf
link bashrc ~/.bashrc
link bash_profile ~/.bash_profile
link inputrc ~/.inputrc
link p10k.zsh ~/.p10k.zsh
link gitconfig ~/.gitconfig
link gitignore ~/.gitignore
link config/nvim/init.vim ~/.config/nvim/init.vim
link config/alacritty/alacritty.toml ~/.config/alacritty/alacritty.toml
link config/alacritty/dracula.toml ~/.config/alacritty/dracula.toml
cpn config/alacritty/alacritty.local.toml ~/.alacritty.local.toml
cpn machine ~/.machine
cpn gitconfig.local ~/.gitconfig.local
# This is the stupidest name for an app yet. And it should be in .config/.hammerspoon
if [[ $(uname) == "Darwin" ]]; then
link init.lua ~/.hammerspoon/init.lua
fi
# copy bin files
mkdir -p ~/bin
cp bin/* ~/bin
# fixing potential insecure group writable folders
# compaudit | xargs chmod g-w
# Setup termcap for tmux
# Italics + true color + iTerm + tmux + vim
# https://medium.com/@dubistkomisch/how-to-actually-get-italics-and-true-colour-to-work-in-iterm-tmux-vim-9ebe55ebc2be
# Understanding TERM strings
# https://sanctum.geek.nz/arabesque/term-strings/
# tic -x termcap/tmux-256color.terminfo || true
# tic -x termcap/xterm-256color-italic.terminfo || true
# Install neovim plugins
println "Installing vim plugins..."
nvim +PlugInstall +qall
# create ~/.ssh folder so zsh-agent doesn't complain
mkdir -p ~/.ssh
# # now change shells
println "Backed up existing files to $B"
ls $B
exit 0