#!/usr/bin/env fish

set slocal ~/.local/share
set sconfig ~/.config
set sflat ~/.var/app
set dest ~/Torrents/Backups/mega
set dlocal $dest/local
set dconfig $dest/config
set dflat $dest/var
set -x fisher_path ~/.config/fish/fisher
set -x PNPM_HOME ~/.local/share/pnpm
set -x PATH $PNPM_HOME $PATH
set ssubs ~/Torrents/Data/Media
set dsubs ~/Torrents/Data/Subs

paru -Qettq >$dest/paru
flatpak list --all --columns=application >$dest/flatpak
pip list --user >$dest/pip
pipx list >$dest/pipx
fish -lc "fisher list >$dest/fisher"
pnpm list -g >$dest/pnpm

function bkup
    echo "Creating a backup of" $argv[1] into $argv[2]
    rsync --exclude "*.git" --inplace --delete -aurL $argv[1] $argv[2]
end

bkup ~/Development/Scripts/ $dest/scripts
bkup ~/Development/Docker/docker-compose.yml $dest
bkup ~/.ssh/ $dest/ssh
bkup ~/Torrents/Data/Backups/ $dest/servarr
bkup ~/.var/ $dest/var

### Deprecate
### pass
for dir in gnupg fonts gnome-recipes rhythmbox maps-places\.json \
    gvfs-metadata
    bkup $slocal/$dir $dlocal
end

### Deprecate
### backintime muso SmpDirs2 iriKali 'org.gabmus.gfeeds.json' 'chromium-flags.conf'
for dir in bat beets celluloid ComicTagger calibre desmume \
    doom 'environment.d' gallery-dl jawz mpd fish git gopass htop \
    lutris moc mpd mpv MusicBrainz ncmpcpp neofetch paru proselint \
    systemd yuzu 'PureRef.ini' \
    'syncplay.ini' 'topgrade.toml' wgetrc \
    mpdscribble mpdasrc Trolltech.conf
    bkup $sconfig/$dir $dconfig
end

for file in $ssubs/**/**.srt
    set dest (string replace $ssubs $dsubs $file)
    mkdir --parents (dirname $dest)
    cp $file $dest
end

# busctl --user call org.gnome.Shell /io/elhan/ExtensionsSync io.elhan.ExtensionsSync save

# set -x GZIP -9
# doas tar cvfz /home/jawz/Torrents/Backups/docker.tar.gz /home/jawz/Development/Docker/
