diff --git a/content/config/helix/config.toml b/content/config/helix/config.toml index 2b7f417..5f64a04 100644 --- a/content/config/helix/config.toml +++ b/content/config/helix/config.toml @@ -49,5 +49,5 @@ C-j = ["half_page_down", "goto_window_center"] C-k = ["half_page_up", "goto_window_center"] [keys.normal."A-/"] -j = ["goto_line_start", ":insert-output use ide.nu; ide doc-comment java-style", "normal_mode", "move_visual_line_up", "insert_at_line_end"] -r = ["goto_line_start", ":insert-output use ide.nu; ide doc-comment rust-style", "normal_mode", "insert_at_line_end"] +j = ["goto_line_start", ":insert-output use ide.nu; ide doc-comment java-style", ":format", "normal_mode", "move_visual_line_up", "insert_at_line_end"] +r = ["goto_line_start", ":insert-output use ide.nu; ide doc-comment rust-style", ":format", "normal_mode", "insert_at_line_end"] diff --git a/content/config/nushell/config.nu.tmpl b/content/config/nushell/config.nu.tmpl index 69797f9..b898df2 100644 --- a/content/config/nushell/config.nu.tmpl +++ b/content/config/nushell/config.nu.tmpl @@ -470,5 +470,4 @@ use ci.nu {{/if-installed}} use ide.nu -source remoting.nu source utils.nu diff --git a/content/config/nushell/scripts/remoting.nu.tmpl b/content/config/nushell/scripts/remoting.nu.tmpl deleted file mode 100644 index 76b73a0..0000000 --- a/content/config/nushell/scripts/remoting.nu.tmpl +++ /dev/null @@ -1,119 +0,0 @@ -# internal function that holds the host data. We could store it in a yaml file as well but that would require nushell to read it from disk every single time -def hosts [] { - [ - {{#each cfg.ssh_hosts}} - { - nu: false - name: (non-empty "{{this.name}}") - ip: (non-empty "{{this.ip}}") - port: (non-empty "{{this.port}}") - username: (non-empty "{{this.username}}") - mac: (non-empty "{{this.mac}}") - } - {{/each}} - ] -} - -def non-empty [entry: string] { - if ($entry | str length) == 0 { - null - } else { - $entry - } -} - -def "nu-complete wol" [] { - hosts - |where mac != '' - |get name -} - -def "nu-complete nu" [] { - hosts - |where nu - |get name -} - -def "nu-complete hosts" [] { - hosts - |get name -} - -def "nu-complete scripts" [] { - $nu.scope.commands - |where is_custom - |get -i command -} - -# Returns ssh connection as url to be consumed by original ssh command -def get-url [ - host: record -] { - if 'ip' in ($host|columns) { - echo $"ssh://($host.username)@($host.ip):($host.port)" - } else { - echo $"ssh://($host.username)@($host.name).($host.domain):($host.port)" - } -} - -# Connect over ssh to one of predefined hosts, execute nushell commands and parse them on the host -export def ssh [ - hostname: string@"nu-complete hosts" # name of the host you want to connect to - ...args # commands you wish to run on the host -] { - let host = (hosts|where name == $hostname|get -i 0) - if $host == null { - ^ssh $hostname ...$args - } - if ($host.nu) { - if ($args|length) > 0 { - ^ssh (get-url $host) (build-string ($args|str join ' ') '|to json -r')|from json - } else { - ^ssh (get-url $host) - } - } else { - ^ssh (get-url $host) ...$args - } -} - -# Connect over ssh to one of predefined hosts, execute nushell script with arguments passed from the host -export def "ssh script" [ - hostname: string@"nu-complete nu" # name of the host you want to connect to - script: string@"nu-complete scripts" # name of the script - ...args # arguments you wish to pass to the script in key=value format -] { - let span = (metadata $script).span - if $script in ($nu.scope.commands|where is_custom|get command) { - - let host = (hosts|where name == $hostname|get 0) - let full_command = (build-string (view-source $script) '; ' $script ' ' ($args|str join ' ') '|to json -r') - ^ssh (get-url $host) ($full_command)|from json - - } else { - error make { - msg: $"($script) is not a custom command, use regular ssh command instead" - label: { - text: "Not a custom command", - start: $span.start, - end: $span.end - } - } - } -} -# Turns on specified hosts using Wake on Lan -export def wake [ - ...names: string@"nu-complete wol" # list of host names to wake -] { - hosts - |where name in $names - |each {|host| - if $host.mac != '' { - echo $"Waking ($host.name)" - wakeonlan $host.mac|ignore - } else { - error make { - msg: $"($host.name) does not support Wake on Lan" - } - } - } -}