blob: df782a07eeb72611e67d4bafccfa2a5897e88239 (
plain)
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
|
# THIS IS CURRENTLY EXPERIMENTAL. REVIEW AND TEST FIRST. NEVER RUN ON MAIN
# MACHINE WITHOUT A BACKUP OF VIMFILES AND DOTFILES
# Links configuration files to the ones listed here. Backup and remove your's
# and then run this script while inside repo directory.
#
# In Windows it has to be run with git-bash.
#
# Note: This solution is lazy and causes some problems. Like not being able to
# track vim pluggins.
#
# As always, ArchLinux's Wiki has a great article explaining dotfiles and how
# people usually manage them.
# https://wiki.archlinux.org/title/Dotfiles
# Config
# ======
mode=$1 # copy,slink
# Prepare
# =======
# HOME variable must be available
if [[ -z $XDG_CONFIG_HOME ]]; then
XDG_CONFIG_HOME="$HOME/.config"
mkdir -p $XDG_CONFIG_HOME
fi
if [[ $mode = "--help" ]]; then
echo "You might want to first run: $0 echo"
echo "Revise the output"
echo "And only then run: $0 slink"
exit
elif [[ $mode = "copy" ]]; then
cp_or_ln="cp"
echo Why? Custom modifications will be difficult to track.
echo Maybe not a good idea. Good bye.
exit
elif [[ $mode = "slink" ]]; then
cp_or_ln="ln -siv" # if you are fearless add the `-f` option
elif [[ $mode = "echo" ]]; then
cp_or_ln="echo ln -siv"
else
echo "Usage: $0 copy|slink|echo"
exit
fi
prompt() {
read -p "Install $1 configuration files? [Y/n/e(exit)] " yesno
yesno=$(echo $yesno | tr '[:upper:]' '[:lower:]')
case $yesno in
y | yes | "" )
return 0;;
e | exit )
exit;;
* )
return 1;;
esac
}
# Install
# =======
# FIXME: If $PWD has spaces in it, this might fail.
# Filewise
if prompt "bash"; then
eval $cp_or_ln " ${PWD}/bash/bash_profile $HOME/.bash_profile"
eval $cp_or_ln " ${PWD}/bash/bashrc $HOME/.bashrc"
eval $cp_or_ln " ${PWD}/bash/bash_aliases $HOME/.bash_aliases"
eval $cp_or_ln " ${PWD}/bash/inputrc $HOME/.inputrc"
fi
if prompt "vim"; then
# `~/.vimrc` takes priority over `~/.vim/vimrc`. Remove the former if it
# exists.
#
# In windows it's `%userprofile%/vimfiles/`
VIMFILES="$HOME/.vim"
mkdir -p $VIMFILES/{undo,swap,backup,plugins}
chmod 0700 $VIMFILES/swap
eval $cp_or_ln " ${PWD}/vim/vimrc $VIMFILES/vimrc"
eval $cp_or_ln " ${PWD}/vim/fun.vim $VIMFILES/fun.vim"
fi
# Directorywise
if prompt "nvim"; then
eval $cp_or_ln " ${PWD}/nvim $XDG_CONFIG_HOME/nvim"
fi
if prompt "git"; then
[ -d $XDG_CONFIG_HOME/git ] || mkdir -p $XDG_CONFIG_HOME/git
eval $cp_or_ln " ${PWD}/git/ignore $XDG_CONFIG_HOME/git/ignore"
eval $cp_or_ln " ${PWD}/git/config $XDG_CONFIG_HOME/git/config"
eval $cp_or_ln " ${PWD}/git/git-prompt.sh $HOME/.git-prompt.sh"
fi
if prompt "zathura"; then
eval $cp_or_ln " ${PWD}/zathura $XDG_CONFIG_HOME/zathura"
fi
if prompt "tmux"; then
eval $cp_or_ln " ${PWD}/tmux/tmux.conf $HOME/.tmux.conf"
fi
echo "all done :)"
|