Enhance fish SSH function with user and keyfile options
This commit is contained in:
parent
a69ba2cb00
commit
058e446102
1 changed files with 45 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue