Skip to content

Commit

Permalink
use external similar-sort repo
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Jun 3, 2020
1 parent fd27acc commit 4fcce3b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 154 deletions.
2 changes: 1 addition & 1 deletion dotfiles/kakoune.nix
Expand Up @@ -10,7 +10,7 @@ let
kak-tree = pkgs.callPackage ../pkgs/kak-tree { };
kak-ayu = pkgs.callPackage ../pkgs/kak-ayu { };

similar-sort = pkgs.callPackage ../pkgs/similar-sort { };
similar-sort = import sources.similar-sort { pkgs = nixpkgs.pkgs; };
similar-sort-files-cmd = arg:
"git ls-files --others --cached --exclude-standard | ${similar-sort}/bin/similar-sort ${arg} | grep -v ${arg} | fzf --tiebreak index";

Expand Down
7 changes: 7 additions & 0 deletions nix/sources.json
Expand Up @@ -164,6 +164,13 @@
"url": "https://github.com/whereswaldon/shellcheck.kak/archive/9acad49508ee95c215541e58353335d9d5b8a927.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"similar-sort": {
"sha256": "0sykdp82cby1ikw4pxzcp1hrhj51dwz0zpprcsj03hhsyg0c1j7b",
"type": "tarball",
"url": "https://git.bytes.zone/brian/similar-sort/archive/301de2b5f83aba77a14b4df33347e8157de4f9ca.tar.gz",
"url_template": "https://git.bytes.zone/brian/similar-sort/archive/<version>.tar.gz",
"version": "301de2b5f83aba77a14b4df33347e8157de4f9ca"
},
"smarttab.kak": {
"branch": "master",
"description": "Automatic handling different styles of indentation and alignment. Mirror of https://gitlab.com/andreyorst/smarttab.kak",
Expand Down
69 changes: 4 additions & 65 deletions pkgs/similar-sort/README.md
@@ -1,68 +1,7 @@
# Similar Sort

This is a small Go program that will:
Hello!
This project has moved to <https://git.bytes.zone/brian/similar-sort>.

1. take a reference string as the first argument
2. and a list of candidate strings in stdin
3. and output the candidates sorted according to their edit distance from the reference, lowest first.

"What use is this?" you may ask!
Well!
It turns out to be really useful to do fuzzy file finding a large project.

When 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.
I also want to match on test files pretty easily.
Say I have this project structure:

```
example
└── src
   ├── Main.elm
   └── Page
   └── Learn
   └── Home
   ├── Main.elm
   └── View.elm
```

If 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.
That's not what I wanted!

But if I sort the files instead by passing them through `similar-sort src/Page/Learn/Home/View.elm`, the sibling file will show up first.
This works surprisingly well, and I really like it!

It 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.

## Installing

You can look in `dotfiles/kakoune.nix` in the root of this project to see how to use this in a home-manager context.
If you're not using home-manager, or you just want to install it globally, `cd` here and type:

```sh
nix-env -if .
```

OR if you have `go` installed but not `nix`, just `go build similar-sort.go`; it has no external dependencies and will result in a static binary you can put wherever.

### Adding to Vim

Add this to your vim config:

```vim
nnoremap <silent> <C-t> :call fzf#run(fzf#wrap({
\ "source": "git ls-files --others --cached --exclude-standard \| similar-sort " . @% . " \| grep -v " . @%,
\ "sink": "edit",
\ "options": "--tiebreak index"
\ }))<CR>
```

(You'll need `fzf` and `fzf.vim` installed.)
This will bind ctrl-t to the fuzzy finder.
When you select a match, it will open in the current pane.

If you want to split or vsplit, change `"sink": "edit"` to `"sink": "split"` or `"sink": "vsplit"`.
See the docs for `fzf#run` for more customization options.

### Adding to Kakoune

I use [connect.kak](https://github.com/alexherbo2/connect.kak) to spawn a terminal window with about the same command line as in the vim config above.
This file just exists to make sure people don't get lost when coming from my blog or other external links.
Have a nice day!
21 changes: 0 additions & 21 deletions pkgs/similar-sort/default.nix

This file was deleted.

67 changes: 0 additions & 67 deletions pkgs/similar-sort/similar-sort.go

This file was deleted.

0 comments on commit 4fcce3b

Please sign in to comment.