Ask the user if he wants to delete the archive

This commit is contained in:
Mylloon 2023-10-08 20:59:51 +02:00
parent d5ba8fac02
commit d8e2d6cd2f
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -16,16 +16,16 @@ function ssh-import
end
set file "$argv[1]"
set archive_file "$argv[1]"
if test (count $argv) -ge 2
# Check if usage is respected
echo "$current_name: too much arguments." 1>&2
return 1
else if not test -e "$file"
else if not test -e "$archive_file"
# Check if file exists
echo "$current_name: file doesn't exists." 1>&2
return 1
else if not test $(string sub --start=-3 "$file") = zip
else if not test $(string sub --start=-3 "$archive_file") = zip
# Check if file have .zip extension
echo "$current_name: file isn't a zip archive." 1>&2
return 1
@ -41,5 +41,20 @@ function ssh-import
# Update and overwrite the .ssh directory with the archive content
# Using modification date, and new files are added
# Files removed aren't tracked
unzip -uo "$file" -d $ssh_directory
unzip -uo "$archive_file" -d $ssh_directory
# Ask user if he want to delete the archive now that it has been imported
while read --nchars 1 -l response --prompt-str="Wanna delete the archive? (y/n)"
or return 1 # if the read was aborted with ctrl-c/ctrl-d
switch $response
case y Y
rm $archive_file
echo "$current_name: archive deleted."
break
case n N
break
case '*'
continue
end
end
end