From 2e597005a25bea21f642281b81386c52ecdeb468 Mon Sep 17 00:00:00 2001 From: Chris Toph Date: Thu, 3 Apr 2025 01:33:29 -0400 Subject: [PATCH] Enhance fish SSH function with user and keyfile options --- home/toph/common/core/fish/init.fish | 46 +++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/home/toph/common/core/fish/init.fish b/home/toph/common/core/fish/init.fish index a22473d..1e11045 100644 --- a/home/toph/common/core/fish/init.fish +++ b/home/toph/common/core/fish/init.fish @@ -2,6 +2,7 @@ function cd zoxide $argv end +# Clears all possible garbage from the Nix store 😀 function garbage sudo nh clean all nh clean all @@ -15,6 +16,7 @@ function ls eza $argv end +# Rebuilds the NixOS configuration, located in ~/git/Nix/dot.nix for all my hosts function rebuild if test -f ~/git/Nix/dot.nix/scripts/rebuild.fish cd ~/git/Nix/dot.nix @@ -24,8 +26,50 @@ function rebuild end end +# SSH function, just for convenience since I use it a lot function s - ssh (whoami)@$argv + set user (whoami) + set keyfile "" + set host "" + + set args $argv + while test (count $args) -gt 0 + switch $args[1] + case -u + if test (count $args) -ge 2 + set user $args[2] + set args $args[3..-1] + else + echo "Error: Option -u requires a username argument." + echo "Usage: s [-u username] [-i keyfile] host" + return 1 + end + case -i + if test (count $args) -ge 2 + set keyfile $args[2] + set args $args[3..-1] + else + echo "Error: Option -i requires a keyfile argument." + echo "Usage: s [-u username] [-i keyfile] host" + return 1 + end + case '*' + set host $args[1] + set args $args[2..-1] + end + end + + if test -z "$host" + echo "Error: Missing host." + echo "Usage: s [-u username] [-i keyfile] host" + return 1 + end + + if test -n "$keyfile" + ssh -i $keyfile $user@$host + else + ssh $user@$host + end end set fish_greeting # Disable greeting