Skip to content

Add an option to sort by Levenshtein distance - #140

Merged
quantumsheep merged 3 commits into
quantumsheep:masterfrom
OmenWild:omen/sort-by-levenshtein-distance
Oct 16, 2025
Merged

quantumsheep merged 3 commits into
quantumsheep:masterfrom
OmenWild:omen/sort-by-levenshtein-distance

Conversation

@OmenWild

Copy link
Copy Markdown
Contributor

This adds a feature to sort by the Levenshtein distance (minimum number of single-character edits (insertions, deletions, or substitutions) required to change one word into the other), which causes the best matches to float to the top.

For example, if I have hosts foo-example, bar-example, and example, and my search box is exam, then example will be at the top because it requires the fewest changes to match.

I have tucked the change away behind a --sort-fancy option.

Note, this is my first time ever using Rust, so I "vibe" coded with Cursor. As best I can tell, the changes seem to make sense, and definitely work, but I do not know if this is truly the best way.

@quantumsheep

Copy link
Copy Markdown
Owner

Hey ! Do you think you can split the PR in two ? One with the Levenshtein distance (which I think could be the default sorting method?), and one with the glob matching

@OmenWild
OmenWild force-pushed the omen/sort-by-levenshtein-distance branch from dfb3fb4 to 3af8343 Compare August 12, 2025 18:23
@OmenWild

Copy link
Copy Markdown
Contributor Author

I have reverted the glob matching, so this PR is only sorting by Levenshtein distance.

@quantumsheep
quantumsheep merged commit c503634 into quantumsheep:master Oct 16, 2025
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
sshs 4.8.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## ✨ What's New ✨

### Interface
* **Reload with `Ctrl+R`** - sshs reads the configuration files again and updates the host list. A restart is not necessary.
* **Pick your palette with `--color`** - the value is a Tailwind palette name, for example `blue`, `green`, or `rose`.
* **Keep your order with `--no-sort`** - sshs shows the hosts in configuration file order.
* **Sort by match score with `--sort-fancy`** - the best fuzzy match comes first ([#140](quantumsheep/sshs#140)).
* **Select text in your terminal** - sshs does not capture the mouse any more.
* **See the real destination** - sshs expands the `%h` and `%n` tokens in the destination column.

### Search
* **Each word must match** - sshs divides the query at spaces. A host appears only when all the words match.
* **Wider match scope** - the fuzzy score includes the name, the aliases, and the destination.
* **Stable selection** - when the query changes, the selection returns to the top match.

### SSH configuration parser
* Quoted values keep their `#` characters, and sshs removes the surrounding quotes.
* `Match` block entries do not leak into the previous host.
* Relative `Include` paths in the system file resolve against `/etc/ssh`.
* `Include` recursion stops at a safe depth and does not overflow the stack.
* Alias merging is blocked only when `HostName` depends on `%h` or `%n` ([#153](quantumsheep/sshs#153)).
* Parser errors show the offending line. A missing configuration file gives a clear error.
* A `Host` entry with no patterns does not cause a crash.

### Stability
* No crash on `End` or `PageDown` when the host list is empty.
* Page navigation moves by the visible table height.
* Table columns use their computed widths.
* When an SSH session exits with an error, sshs returns to the host list.

### Packaging and documentation
* New installation instructions for Debian and Ubuntu.
* New installation method for NetBSD ([#142](quantumsheep/sshs#142)).

## 🌟 New Contributors 🌟
* [@OmenWild](https://github.com/OmenWild) made their first contribution in [#140](quantumsheep/sshs#140)
* [@0323pin](https://github.com/0323pin) made their first contribution in [#142](quantumsheep/sshs#142)
* [@mwestza](https://github.com/mwestza) made their first contribution in [#153](quantumsheep/sshs#153)

**See All the Changes:** [The full list of updates from version 4.7.2 to 4.8.0](quantumsheep/sshs@4.7.2...4.8.0)
</pre>
  <p>View the full release notes at <a href="https://github.com/quantumsheep/sshs/releases/tag/4.8.0">https://github.com/quantumsheep/sshs/releases/tag/4.8.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!18010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants