dotfiles/sync

125 lines
2.7 KiB
Fish
Executable File

#!/usr/bin/env fish
function main
argparse 'd/desktop' 'g/git' -- $argv
set -l start_dir (pwd)
set -l tmp_dir (mktemp --directory 2>/dev/null; or mktemp -d -t 'dotfiles')
set -l cwd (string match -r '\w+$' $start_dir)
set -l uname (uname)
log 'Syncing shell environment configurations'
set_color grey
setup_tmp_space $cwd $tmp_dir
sync_terminal_env
set_fish_universal_vars
install_fisher_packages
install_nvim_plugins
if test -n "$_flag_d"
set_color normal
log 'Syncing desktop environment configurations'
set_color grey
sync_desktop_env $uname
set_kitty_font_size $uname
end
if test -n "$_flag_g"
set_color normal
log 'Sync git config'
sync_git_config
set_color grey
end
clean_up_tmp_space $cwd $start_dir $tmp_dir
set_color normal
echo -s \n 'Done syncing.'
end
function setup_tmp_space -a cwd tmp_dir
if test ! "$cwd" = 'dotfiles'
git clone --recurse-submodules https://github.com/mitchell/dotfiles.git $tmp_dir
cd $tmp_dir
end
end
function sync_terminal_env
if ! test -e ~/.config
mkdir ~/.config
end
rsync -aP ./.config/fish ~/.config/
rsync -aP ./.config/nvim ~/.config/
rsync -aP ./.tmux-line.conf ~/
rsync -aP ./.tmux.conf ~/
rsync -aP ./.vim ~/
rsync -aP ./.vimrc ~/
rsync -aP ./.taskrc ~/
end
function sync_desktop_env -a uname
rsync -aP ./.config/kitty ~/.config/
rsync -aP ./.config/qutebrowser ~/.config/
rsync -aP ./.ideavimrc ~/
switch $uname
case Darwin
rsync -aP ./.yabairc ~/
rsync -aP ./.skhdrc ~/
case Linux
rsync -aP ./.config/bspwm ~/.config/
rsync -aP ./.config/sxhkd ~/.config/
rsync -aP ./.config/picom ~/.config/
rsync -aP ./.config/polybar ~/.config/
end
end
function set_kitty_font_size -a uname
if test "$uname" = 'Darwin'
sed -i '' -e 's/font_size 11\.0/font_size 13\.0/' ~/.config/kitty/kitty.conf
end
end
function install_fisher_packages
eval fisher
end
function install_nvim_plugins
command -q nvim; and nvim +PlugUpgrade +PlugUpdate +qa
end
function sync_git_config
rsync -aP ./.gitconfig ~/
echo 'Please set your git user:'
read -P 'name: ' name
read -P 'email: ' email
git config --global user.name $name
git config --global user.email $email
end
function set_fish_universal_vars
source ./fish_universal_vars.fish
end
function clean_up_tmp_space -a cwd start_dir tmp_dir
if test ! "$cwd" = 'dotfiles'
cd $start_dir
rm -r $tmp_dir
end
end
function log -a message
echo \n"---------------- $message ----------------"\n
end
main $argv