-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.fish
More file actions
executable file
·138 lines (117 loc) · 3.73 KB
/
bootstrap.fish
File metadata and controls
executable file
·138 lines (117 loc) · 3.73 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
134
135
136
137
138
#!/usr/bin/env fish
#
# bootstrap installs everything.
set DOTFILES_ROOT (pwd -P)
function info
echo [(set_color --bold) ' .. ' (set_color normal)] $argv
end
function user
echo [(set_color --bold) ' ?? ' (set_color normal)] $argv
end
function success
echo [(set_color --bold green) ' OK ' (set_color normal)] $argv
end
function abort
echo [(set_color --bold yellow) ABRT (set_color normal)] $argv
exit 1
end
function on_exit -p %self
if not contains $argv[3] 0
echo [(set_color --bold red) FAIL (set_color normal)] "Couldn't setup dotfiles, please open an issue at https://github.com/caarlos0/dotfiles"
end
end
function setup_gitconfig
set managed (git config --global --get dotfiles.managed)
# if there is no user.email, we'll assume it's a new machine/setup and ask it
if test -z (git config --global --get user.email)
user 'What is your github author name?'
read user_name
user 'What is your github author email?'
read user_email
test -n $user_name
or echo "please inform the git author name"
test -n $user_email
or abort "please inform the git author email"
git config --global user.name $user_name
and git config --global user.email $user_email
or abort 'failed to setup git user name and email'
else if test '$managed' = "true"
# if user.email exists, let's check for dotfiles.managed config. If it is
# not true, we'll backup the gitconfig file and set previous user.email and
# user.name in the new one
set user_name (git config --global --get user.name)
and set user_email (git config --global --get user.email)
and mv ~/.gitconfig ~/.gitconfig.backup
and git config --global user.name $user_name
and git config --global user.email $user_email
and success "moved ~/.gitconfig to ~/.gitconfig.backup"
or abort 'failed to setup git user name and email'
else
# otherwise this gitconfig was already made by the dotfiles
info "already managed by dotfiles"
end
# include the gitconfig.local file
# finally make git knows this is a managed config already, preventing later
# overrides by this script
git config --global include.path ~/.gitconfig.local
and git config --global dotfiles.managed true
or abort 'failed to setup git'
end
function link_file -d "links a file keeping a backup"
echo $argv | read -l old new backup
if test -e $new
set newf (readlink $new)
if test "$newf" = "$old"
success "skipped $old"
return
else
mv $new $new.$backup
and success moved $new to $new.$backup
or abort "failed to backup $new to $new.$backup"
end
end
mkdir -p (dirname $new)
and ln -sf $old $new
and success "linked $old to $new"
or abort "could not link $old to $new"
end
function install_dotfiles
for src in $DOTFILES_ROOT/*/*.symlink
link_file $src $HOME/.(basename $src .symlink) backup
or abort 'failed to link config file'
end
for package in $DOTFILES_ROOT/*/
stow -R -t ~/.config (basename $package) --ignore install\.fish --ignore '.*\.symlink' --ignore '\.DS_Store'
and success (basename $package)
end
end
setup_gitconfig
and success 'gitconfig'
or abort 'gitconfig'
install_dotfiles
and success 'dotfiles'
or abort 'dotfiles'
fisher update
and success 'plugins'
or abort 'plugins'
mkdir -p ~/.config/fish/completions/
and success 'completions'
or abort 'completions'
for installer in */install.fish
$installer
and success $installer
or abort $installer
end
if ! grep (command -v fish) /etc/shells
command -v fish | sudo tee -a /etc/shells
and success 'added fish to /etc/shells'
or abort 'setup /etc/shells'
echo
end
test (which fish) = $SHELL
and success 'dotfiles installed/updated!'
and exit 0
chsh -s (which fish)
and success set (fish --version) as the default shell
or abort 'set fish as default shell'
success 'dotfiles installed/updated!'