{"id":18005892,"url":"https://github.com/brianhicks/similar-sort","last_synced_at":"2025-04-04T10:47:43.725Z","repository":{"id":233821057,"uuid":"787864012","full_name":"BrianHicks/similar-sort","owner":"BrianHicks","description":null,"archived":false,"fork":false,"pushed_at":"2024-04-17T10:25:03.000Z","size":30,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T06:07:44.369Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BrianHicks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-17T10:25:01.000Z","updated_at":"2024-04-17T14:08:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"109b18c4-b027-4e9c-bd3f-9a203efbda56","html_url":"https://github.com/BrianHicks/similar-sort","commit_stats":null,"previous_names":["brianhicks/similar-sort"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianHicks%2Fsimilar-sort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianHicks%2Fsimilar-sort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianHicks%2Fsimilar-sort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianHicks%2Fsimilar-sort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrianHicks","download_url":"https://codeload.github.com/BrianHicks/similar-sort/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247166138,"owners_count":20894652,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-30T00:22:26.334Z","updated_at":"2025-04-04T10:47:43.697Z","avatar_url":"https://github.com/BrianHicks.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Similar Sort\n\nThis is a small Go program that will:\n\n1. take a reference string as the first argument\n2. and a list of candidate strings in stdin\n3. and output the candidates sorted according to their edit distance from the reference, lowest first.\n\n\"What use is this?\" you may ask!\nWell!\nIt turns out to be really useful to do fuzzy file finding a large project.\n\nWhen I am in some filesystem hierarchy and I trigger my fuzzy-finder, I want to see sibling files before I see similarly-named files further away.\nI also want to match on test files pretty easily.\nSay I have this project structure:\n\n```\nexample\n└── src\n    ├── Main.elm\n    └── Page\n        └── Learn\n            └── Home\n                ├── Main.elm\n                └── View.elm\n```\n\nIf I am in `src/Page/Learn/Home/View.elm` and I want to get to the sibling file `Main.elm`, the default `fzf` config shows me `src/Main.elm` first.\nThat's not what I wanted!\n\nBut if I sort the files instead by piping them through `similar-sort src/Page/Learn/Home/View.elm`, the sibling file will show up first.\nThis works surprisingly well; I really like it!\n\nIt could probably perform a *little* better by doing some heuristic based on equivalent file structure except for the addition/removal of \"tests\", \"specs\", etc, but I haven't bothered yet.\n\n## Installing\n\nIf you have [`nix`](https://nixos.org) installed, clone this and type:\n\n```sh\nnix-env -if .\n```\n\nAfter this, the `similar-sort` binary should be available on your `PATH`.\n\nIf you don't have `nix`, you'll need to install a Rust compiler toolchain yourself and run `cargo build`.\n\n[Isaec](https://github.com/isaec) has also put together [an AUR package](https://aur.archlinux.org/packages/similar-sort-git) if you're on Arch.\n\n### Adding to Vim\n\nAdd this to your vim config:\n\n```vim\nnnoremap \u003csilent\u003e \u003cC-t\u003e :call fzf#run(fzf#wrap({\n  \\ \"source\": \"git ls-files --others --cached --exclude-standard \\| similar-sort \" . @% . \" \\| grep -v \" . @%,\n  \\ \"sink\": \"edit\",\n  \\ \"options\": \"--tiebreak index\"\n  \\ }))\u003cCR\u003e\n```\n\n(You'll need `fzf` and `fzf.vim` installed.)\nThis will bind ctrl-t to the fuzzy finder.\nWhen you select a match, it will open in the current pane.\n\nIf you want to split or vsplit, change `\"sink\": \"edit\"` to `\"sink\": \"split\"` or `\"sink\": \"vsplit\"`.\nSee the docs for `fzf#run` for more customization options.\n\n### Adding to Kakoune\n\nAssuming you're using tmux as your window manager, integration looks something like this:\n\n```\ndefine-command -docstring 'open files named similarly to the current buffer' open-similar %{\n    tmux-terminal-horizontal sh -c %{\n        set -euo pipefail\n        FILE=\"$(git ls-files --others --cached --exclude-standard | similar-sort $1 | grep -v $1 | fzf --tiebreak index)\"\n        printf \"evaluate-commands -client %s edit %s\\n\" \"$2\" \"$FILE\" | kak -p $3\n    } -- %val{bufname} %val{client} %val{session}\n}\n```\n\nI have this bound to `-` with `map global normal \u003cminus\u003e ': open-similar\u003cret\u003e'`.\n\n### Using as a Spellchecker\n\nIf you use [fish](https://fishshell.com/), [Isaec](https://github.com) has written [a spell-checker using similar-sort](https://gist.github.com/isaec/ebed80db75d826a77fd528e955db8670). Source reproduced below for convenience:\n\n```fish\nfunction near\n    set selection (\n        cat /usr/share/dict/american-english \\\n            | similar-sort -- (xclip -o) \\\n            # tiebreak=index to prefer LD sort order\n            | fzf -i +m --tiebreak=index --preview \"dict {}\" --preview-window=\"right,80%,wrap,\u003c60(wrap,up,45%)\"\n    )\n\n    # only run xclip if something was selected (i.e. not if fzf was exited)\n    if test \"$status\" -eq 0\n        # using -loops 2 to wait until clipboard manager has grabbed\n        # using -quiet puts xclip in foreground so we wait to exit\n        echo \"$selection\" | xclip -r -sel clip -loops 2 -quiet\n    end\n\n    exit\nend\n```\n\n## License\n\nCC BY-SA 4.0.\nSee LICENSE in the root of the project for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianhicks%2Fsimilar-sort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrianhicks%2Fsimilar-sort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianhicks%2Fsimilar-sort/lists"}