Add ssh-import
This commit is contained in:
parent
1f7ccd5176
commit
15446733e4
1 changed files with 30 additions and 0 deletions
30
.config/fish/functions/ssh-import.fish
Normal file
30
.config/fish/functions/ssh-import.fish
Normal file
|
@ -0,0 +1,30 @@
|
|||
function ssh-import
|
||||
# Check if no arguments were provided, or if the first argument is '--help'
|
||||
if test -z $argv[1] || test "$argv[1]" = --help
|
||||
echo -e "Usage: ssh-import <archive.zip>"
|
||||
echo -e " ssh-import --help \t - Show this help message"
|
||||
echo -e " ssh-import <archive.zip> - Erase **all** the current .ssh folder and replace it with the archive content"
|
||||
return 0
|
||||
end
|
||||
|
||||
|
||||
set file "$argv[1]"
|
||||
if test (count $argv) -ge 2
|
||||
# Check if usage is respected
|
||||
echo "Too much arguments." 1>&2
|
||||
return 1
|
||||
else if not test -e "$file"
|
||||
# Check if file exists
|
||||
echo "File doesn't exists." 1>&2
|
||||
return 1
|
||||
else if not test $(string sub --start=-3 "$file") = zip
|
||||
# Check if file have .zip extension
|
||||
echo "File isn't a zip archive." 1>&2
|
||||
return 1
|
||||
end
|
||||
|
||||
# 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 "$HOME/.ssh"
|
||||
end
|
Loading…
Reference in a new issue