Home

dotnix @main - refs - log -
-
https://git.jolheiser.com/dotnix.git
My nix dotfiles
tree log patch
feat: add ssh completions Signed-off-by: jolheiser <git@jolheiser.com>
Signature
-----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgBTEvCQk6VqUAdN2RuH6bj1dNkY oOpbPWj+jw4ua1B1cAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5 AAAAQNV2ypUr5cG6JgaqJZ2osbCm1X3au7UigEXUSnTbB2Yl0ZclczYlG5s4R0zcE++aIh v3789bqjk6imVzo7mpmQY= -----END SSH SIGNATURE-----
jolheiser <git@jolheiser.com>
3 weeks ago
3 changed files, 94 additions(+), 1 deletions(-)
M apps/nogui/nushell.nix -> apps/nogui/nushell.nix
diff --git a/apps/nogui/nushell.nix b/apps/nogui/nushell.nix
index 1d919a7446bf9365f407f801a78e6a2c53ca7739..5bad86c83f5524478ce38092a0f4483f42999377 100644
--- a/apps/nogui/nushell.nix
+++ b/apps/nogui/nushell.nix
@@ -31,6 +31,8 @@   };
   xdg.configFile = {
     "nushell/jolheiser.nu".source = ./nushell/jolheiser.nu;
   programs.nushell = {
+    enable = true;
+  programs.nushell = {
 {
   };
 }
M apps/nogui/nushell/jolheiser.nu -> apps/nogui/nushell/jolheiser.nu
diff --git a/apps/nogui/nushell/jolheiser.nu b/apps/nogui/nushell/jolheiser.nu
index ad1666a080d1c138bf9f437318cff4427863f090..09b3de6dd43ddba3bd2dbff138ccb1651ad8639a 100644
--- a/apps/nogui/nushell/jolheiser.nu
+++ b/apps/nogui/nushell/jolheiser.nu
@@ -100,5 +100,7 @@
 ## Other ##
 $env.EDITOR = hx
 
+## Aliases ## 
+
 
-## Aliases ## 
+alias cat = bat
I apps/nogui/nushell/ssh.nu
diff --git a/apps/nogui/nushell/ssh.nu b/apps/nogui/nushell/ssh.nu
new file mode 100644
index 0000000000000000000000000000000000000000..2c02adb50079878495a244dec118bfcf1a4dc829
--- /dev/null
+++ b/apps/nogui/nushell/ssh.nu
@@ -0,0 +1,89 @@
+export extern "ssh" [
+    destination?: string@"nu-complete ssh-host"
+    -4            # Forces ssh to use IPv4 addresses only.
+    -6            # Forces ssh to use IPv6 addresses only.
+    -A            # Enables forwarding of connections from an authentication agent such as ssh-agent(1).
+    -a            # Disables forwarding of the authentication agent connection.
+    -B: string    # bind_interface
+    -b: string    # bind_address
+    -C            # Requests compression of all data
+    -c: string    # cipher_spec
+    -D            # [bind_address:]port
+    -E: string    # log_file
+    -e            # escape_char
+    -F: string    # configfile
+    -f            # Requests ssh to go to background just before command execution.
+    -G            # Causes ssh to print its configuration after evaluating Host and Match blocks and exit.
+    -g            # Allows remote hosts to connect to local forwarded ports
+    -I: string    # pkcs11
+    -i: string@"nu-complete ssh-identity"    # identity_file
+    -J: string    # destination
+    -K            # Enables GSSAPI-based authentication and forwarding(delegation) of GSSAPI credentials to the server.
+    -k            # Disables forwarding (delegation) of GSSAPI credentials to the server.
+    -L: string    # [bind_address:]port:host:hostport / [bind_address:]port:remote_socket / local_socket:host:hostport / local_socket:remote_socket
+    -l: string    # login_name
+    -M            # Places the ssh client into “master” mode for connection sharing.
+    -m: string    # mac_spec
+    -N            # Do not execute a remote command.
+    -n            # Redirects stdin from /dev/null (5) for details.
+    -O: string    # ctl_cmd
+    -o: string    # option
+]
+
+def parse-host [file: string] {
+    let lines = $file | open | lines | str trim
+
+    mut result = []
+    for $line in $lines {
+        let data = $line | parse --regex '^Include\s+(?<file>.+)'
+        if ($data | is-not-empty) {
+            let include = parse-host ($data.file | first)
+            $result = ($result | append $include)
+            continue
+        }
+        let data = $line | parse  --regex '^Host\s+(?<host>.+)'
+        if ($data | is-not-empty) {
+            let host = $data.host | first
+            if ($host == '*') {
+                continue
+            }
+            $result = ($result | append { 'value': $host, 'description': "" })
+            continue;
+        }
+        let data = $line | parse --regex '^HostName\s+(?<hostname>.+)'
+        if ($data | is-not-empty) {
+            let last = $result | last | update 'description' ($data.hostname | first)
+            $result = ($result | drop | append $last)
+        }
+    }
+    $result
+}
+
+def "nu-complete ssh-host" [] {
+    mut files = [
+        '/etc/ssh/ssh_config',
+        '~/.ssh/config'
+    ] | filter { |file| $file | path exists }
+
+
+    $files | each { |file|
+        parse-host $file
+    } | flatten
+}
+
+def "nu-complete ssh-identity" [] {
+  ls ~/.ssh/
+  | where {|f|
+      ($f.name | path parse | get extension) == "pub"
+    }
+  | get name
+  | path parse
+  | each {|p| {'value': $'~/.ssh/($p.stem)', 'description': $p.stem} }
+}
+
+export def ssh-add-all [] {
+    nu-complete ssh-identity
+    | each {|s| print $s.value; ^ssh-add ($s.value | path expand); print '' }
+    null
+}
+