2024-01-27 21:15:25 -08:00
|
|
|
#!/usr/bin/env fish
|
|
|
|
# vim:set ft=fish :
|
|
|
|
|
|
|
|
set -q DOT || set -gx DOT "$HOME/dotfiles"
|
|
|
|
|
|
|
|
source "$DOT/script/utils"
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# OS Preferences #
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
function set_os_prefs
|
|
|
|
print_title "OS Preferences"
|
|
|
|
|
|
|
|
set os $(uname | string lower)
|
|
|
|
|
|
|
|
"$DOT/os/$os.fish"
|
|
|
|
end
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Symlink Dotfiles #
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
function link_file
|
|
|
|
set -f src $argv[1]
|
|
|
|
set -f dst $argv[2]
|
|
|
|
|
|
|
|
set -f action
|
|
|
|
|
|
|
|
if [ -f "$dst" ] || [ -d "$dst" ] || [ -L "$dst" ]
|
|
|
|
|
|
|
|
if ! $overwrite_all && ! $backup_all && ! $skip_all
|
|
|
|
set -f current_src (readlink "$dst")
|
|
|
|
|
|
|
|
if [ "$current_src" = "$src" ]
|
2024-01-28 11:55:11 -08:00
|
|
|
set -f skip true
|
2024-01-27 21:15:25 -08:00
|
|
|
else
|
2024-01-28 11:55:11 -08:00
|
|
|
print_question "File already exists: $dst ($(basename $src)), what do you want to do?"
|
|
|
|
print_question "([s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all)"
|
2024-01-27 21:15:25 -08:00
|
|
|
read -n 1 action
|
|
|
|
|
|
|
|
switch $action
|
|
|
|
case o
|
2024-01-28 11:55:11 -08:00
|
|
|
set -f overwrite true
|
2024-01-27 21:15:25 -08:00
|
|
|
case O
|
2024-01-28 11:55:11 -08:00
|
|
|
set -f overwrite_all true
|
2024-01-27 21:15:25 -08:00
|
|
|
case b
|
2024-01-28 11:55:11 -08:00
|
|
|
set -f backup true
|
2024-01-27 21:15:25 -08:00
|
|
|
case B
|
2024-01-28 11:55:11 -08:00
|
|
|
set -f backup_all true
|
2024-01-27 21:15:25 -08:00
|
|
|
case s
|
2024-01-28 11:55:11 -08:00
|
|
|
set -f skip true
|
2024-01-27 21:15:25 -08:00
|
|
|
case S
|
2024-01-28 11:55:11 -08:00
|
|
|
set -f skip_all true
|
2024-01-27 21:15:25 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
set -q overwrite || set overwrite $overwrite_all
|
|
|
|
set -q backup || set backup $backup_all
|
|
|
|
set -q skip || set skip $skip_all
|
|
|
|
|
|
|
|
if $overwrite
|
|
|
|
rm -rf "$dst"
|
|
|
|
print_success "Removed $dst"
|
|
|
|
end
|
|
|
|
|
|
|
|
if $backup
|
|
|
|
mv "$dst" "{$dst}.bak"
|
|
|
|
print_success "Moved $dst to {$dst}.bak"
|
|
|
|
end
|
|
|
|
|
|
|
|
if $skip
|
|
|
|
print_success "Skipped $src"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if ! $skip
|
|
|
|
# See of any directories need to be created.
|
|
|
|
if echo "$dst" | grep -q '/' 2> /dev/null
|
|
|
|
mkdir -p (string replace -r '\/[^\/]+$' '' "$dst")
|
|
|
|
end
|
|
|
|
|
2024-01-28 11:55:11 -08:00
|
|
|
ln -s "$src" "$dst" &> /dev/null
|
2024-01-27 21:15:25 -08:00
|
|
|
print_success "Linked $src to $dst"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function make_dst
|
2024-01-28 11:55:11 -08:00
|
|
|
set -l path (string replace -a '/' '\/' "$DOT")
|
|
|
|
set -l regex (string join '' '^' "$path" '\/[a-zA-Z]+\/(.+)\.symlink$')
|
2024-01-27 21:15:25 -08:00
|
|
|
set -l dst (string replace -r $regex '$1' "$argv[1]")
|
|
|
|
|
2024-01-28 11:55:11 -08:00
|
|
|
printf '%s' "$HOME/$dst"
|
2024-01-27 21:15:25 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
function install_dotfiles
|
|
|
|
print_title "Installing Dotfiles"
|
|
|
|
|
|
|
|
set -g overwrite_all false
|
|
|
|
set -g backup_all false
|
|
|
|
set -g skip_all false
|
|
|
|
|
2024-01-28 11:55:11 -08:00
|
|
|
for src in (find -H "$DOT" -name "*.symlink" -not -path ".git")
|
|
|
|
link_file $src (make_dst $src)
|
|
|
|
end
|
2024-01-27 21:15:25 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Main #
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
print_title "Installers"
|
|
|
|
find . -name install.fish | while read installer; fish -c "$installer"; end
|
|
|
|
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
|
|
|
|
install_dotfiles
|