dotfiles/.config/fish/functions/update.fish

64 lines
1.7 KiB
Fish

function update --description "Update everything"
# autoconfirm
argparse y/no-confirm -- $argv
# TODO: add configuration options and publish?
set -l termcmd foot fish -c
set -l std 'cargo install-update -a
gup update
uv tool upgrade --all '
set -l noconfirm 'flatpak update -y
yes | paru -Syu'
set -l confirm 'flatpak update
paru -Syu'
set -l cmds (string split \n -- $std | string trim)
if set -q _flag_y
set --append cmds $noconfirm
sudo -v
else
set --append cmds $confirm
end
echo Commands to be run:
for i in $cmds
echo $i
end
return 0
function execute -a cmds
argparse i/interactive -- $argv
if set -ql _flag_i
for cmd in $cmds
# max 2 jobs at a time
while test (count (jobs -p)) -ge 2
sleep 0.5
end
if string match -q "*paru *" -- "$cmd"
eval $cmd
else
$termcmd $cmd &>/dev/null &
end
end
else
for cmd in $cmds
eval $cmd
end
end
end
if isatty stdin; and isatty stdout
while read --nchars 1 -l response --prompt-str="Run on multiple terminals? (y/n)" or return 1
switch $response
case y Y
execute --interactive $cmds
wait
break
case n N
execute $cmds
break
case '*'
echo Invalid input!
continue
end
end
else
execute $cmds
end
end