Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ automatically setup these arbitrary injections.
- `programs.firefox.profiles.*.userChrome`
* Wezterm (lua language)
- `programs.wezterm.extraConfig`
* SSH (ssh_config language)
- `services.openssh.extraConfig`
- `programs.ssh.extraConfig`
- `boot.initrd.network.ssh.extraConfig`
</details>

> [!Warning]
Expand Down
21 changes: 21 additions & 0 deletions queries/nix/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,24 @@
(#set! injection.language "css")
(#set! injection.combined)
)

; SSH
; https://search.nixos.org/options?query=ssh.extraConfig
(binding
attrpath: (_) @_path (#hmts-path? @_path "services" "openssh" "extraConfig")
expression: (_ (string_fragment) @injection.content)
(#set! injection.language "ssh_config")
(#set! injection.combined)
)
(binding
attrpath: (_) @_path (#hmts-path? @_path "programs" "ssh" "extraConfig")
expression: (_ (string_fragment) @injection.content)
(#set! injection.language "ssh_config")
(#set! injection.combined)
)
(binding
attrpath: (_) @_path (#hmts-path? @_path "boot" "initrd" "network" "ssh" "extraConfig")
expression: (_ (string_fragment) @injection.content)
(#set! injection.language "ssh_config")
(#set! injection.combined)
)
Comment on lines +127 to +144

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These three binding blocks for SSH configurations are very similar and can be combined into a single block. This will reduce code duplication and make the query file more concise and maintainable. You can use the #lua-match? predicate with a regex to match all three attribute paths. This approach keeps all related SSH extraConfig paths in one place.

(binding
  attrpath: (_) @_path (#lua-match? @_path "^(services%.openssh|programs%.ssh|boot%.initrd%.network%.ssh)%.extraConfig$")
  expression: (_ (string_fragment) @injection.content)
  (#set! injection.language "ssh_config")
  (#set! injection.combined)
)

Copy link
Author

@n0099 n0099 Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If lua-match? predicate is enough then why creating the custom

hmts.nvim/plugin/hmts.lua

Lines 120 to 145 in a32cd41

--- Checks if the given capture is located at the end of the given nix path. Every node can be matched by a regex.
---@param match table<string, TSNode>
---@param _ string
---@param bufnr integer
---@param predicate string[]
---@return boolean
local function hmts_path_handler(match, _, bufnr, predicate)
local node = match[predicate[2]]:parent()
local target_path = vim.list_slice(predicate, 3, nil)
while node do
if #target_path == 0 then
return true
end
if node:type() == "binding" then
local path_node = node:field("attrpath")[1]
local is_match = path_diff(target_path, attrpath_to_strings(path_node, bufnr))
if not is_match then
return false
end
end
node = node:parent()
end
return false
end
?