Compare commits

...

2 Commits

Author SHA1 Message Date
jolheiser d0f4bbc55b
feat: add ssh completions
Signed-off-by: jolheiser <git@jolheiser.com>
2024-08-28 22:23:15 -05:00
jolheiser ee28dac8c1
chore: clean up zoxide and ssh
Signed-off-by: jolheiser <git@jolheiser.com>
2024-08-28 22:05:21 -05:00
6 changed files with 93 additions and 66 deletions

View File

@ -31,7 +31,7 @@ in
}; };
}; };
services.gpg-agent = { services.gpg-agent = {
enable = true; enable = false;
enableExtraSocket = true; enableExtraSocket = true;
enableSshSupport = true; enableSshSupport = true;
pinentryPackage = pkgs.pinentry-gnome3; pinentryPackage = pkgs.pinentry-gnome3;

View File

@ -30,7 +30,7 @@
}; };
xdg.configFile = { xdg.configFile = {
"nushell/jolheiser.nu".source = ./nushell/jolheiser.nu; "nushell/jolheiser.nu".source = ./nushell/jolheiser.nu;
"nushell/zoxide.nu".source = ./nushell/zoxide.nu; "nushell/ssh.nu".source = ./nushell/ssh.nu;
"nushell/ohmyposh.nu".source = ./nushell/ohmyposh.nu; "nushell/ohmyposh.nu".source = ./nushell/ohmyposh.nu;
}; };
} }

View File

@ -99,6 +99,6 @@ def , [
## Other ## ## Other ##
$env.EDITOR = hx $env.EDITOR = hx
source ~/.config/nushell/zoxide.nu $env.SSH_AUTH_SOCK = '/run/user/1000/ssh-agent'
source ~/.config/nushell/ohmyposh.nu source ~/.config/nushell/ohmyposh.nu
source ~/.config/nushell/ssh.nu

View File

@ -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
}

View File

@ -1,60 +0,0 @@
# Code generated by zoxide. DO NOT EDIT.
# =============================================================================
#
# Hook configuration for zoxide.
#
# Initialize hook to add new entries to the database.
if (not ($env | default false __zoxide_hooked | get __zoxide_hooked)) {
$env.__zoxide_hooked = true
$env.config = ($env | default {} config).config
$env.config = ($env.config | default {} hooks)
$env.config = ($env.config | update hooks ($env.config.hooks | default {} env_change))
$env.config = ($env.config | update hooks.env_change ($env.config.hooks.env_change | default [] PWD))
$env.config = ($env.config | update hooks.env_change.PWD ($env.config.hooks.env_change.PWD | append {|_, dir|
zoxide add -- $dir
}))
}
# =============================================================================
#
# When using zoxide with --no-cmd, alias these internal functions as desired.
#
# Jump to a directory using only keywords.
def --env __zoxide_z [...rest:string] {
let arg0 = ($rest | append '~').0
let path = if (($rest | length) <= 1) and ($arg0 == '-' or ($arg0 | path expand | path type) == dir) {
$arg0
} else {
(zoxide query --exclude $env.PWD -- $rest | str trim -r -c "\n")
}
cd $path
}
# Jump to a directory using interactive search.
def --env __zoxide_zi [...rest:string] {
cd $'(zoxide query --interactive -- $rest | str trim -r -c "\n")'
}
# =============================================================================
#
# Commands for zoxide. Disable these using --no-cmd.
#
alias z = __zoxide_z
alias zi = __zoxide_zi
# =============================================================================
#
# Add this to your env file (find it by running `$nu.env-path` in Nushell):
#
# zoxide init nushell | save -f ~/.zoxide.nu
#
# Now, add this to the end of your config file (find it by running
# `$nu.config-path` in Nushell):
#
# source ~/.zoxide.nu
#
# Note: zoxide only supports Nushell v0.73.0 and above.

View File

@ -1,7 +1,5 @@
{ {
programs.zoxide = { programs.zoxide = {
enable = true; enable = true;
# TODO remove once zoxide is updated for new nushell def --env syntax
enableNushellIntegration = false;
}; };
} }