refactor(sshtmp): simplify cleanup logic
Amolith
created 2 months ago
The `try...finally` block was removed as the `rm -rf` command
will still execute at the end of the function regardless of
the `ssh` command's exit status. This simplifies the code
without changing the cleanup behavior.
Change summary
dot_config/private_fish/functions/sshtmp.fish | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
Detailed changes
@@ -10,14 +10,11 @@ function sshtmp --description "Connect to an SSH host using a temporary, one-tim
set -l tmp_dir (mktemp -d)
set -l key_path "$tmp_dir/id_ed25519"
- try
- ssh-keygen -t ed25519 -f "$key_path" -N "" -C "sshtmp temporary key for $destination" >/dev/null
- command ssh -i "$key_path" \
- -o IdentitiesOnly=yes \
- -o StrictHostKeyChecking=no \
- -o UserKnownHostsFile=/dev/null \
- $destination
- finally
- rm -rf "$tmp_dir"
- end
+ ssh-keygen -t ed25519 -f "$key_path" -N "" -C "sshtmp temporary key for $destination" >/dev/null
+ command ssh -i "$key_path" \
+ -o IdentitiesOnly=yes \
+ -o StrictHostKeyChecking=no \
+ -o UserKnownHostsFile=/dev/null \
+ $destination
+ rm -rf "$tmp_dir"
end