{"action":"created","issue":{"url":"https://api.github.com/repos/junegunn/fzf/issues/1380","repository_url":"https://api.github.com/repos/junegunn/fzf","labels_url":"https://api.github.com/repos/junegunn/fzf/issues/1380/labels{/name}","comments_url":"https://api.github.com/repos/junegunn/fzf/issues/1380/comments","events_url":"https://api.github.com/repos/junegunn/fzf/issues/1380/events","html_url":"https://github.com/junegunn/fzf/pull/1380","id":360984861,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE2MDcwMDU4","number":1380,"title":"Add --tiebreak proximity=path","user":{"login":"jonhoo","id":176295,"node_id":"MDQ6VXNlcjE3NjI5NQ==","avatar_url":"https://avatars2.githubusercontent.com/u/176295?v=4","gravatar_id":"","url":"https://api.github.com/users/jonhoo","html_url":"https://github.com/jonhoo","followers_url":"https://api.github.com/users/jonhoo/followers","following_url":"https://api.github.com/users/jonhoo/following{/other_user}","gists_url":"https://api.github.com/users/jonhoo/gists{/gist_id}","starred_url":"https://api.github.com/users/jonhoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonhoo/subscriptions","organizations_url":"https://api.github.com/users/jonhoo/orgs","repos_url":"https://api.github.com/users/jonhoo/repos","events_url":"https://api.github.com/users/jonhoo/events{/privacy}","received_events_url":"https://api.github.com/users/jonhoo/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-09-17T18:16:59Z","updated_at":"2018-09-18T04:31:49Z","closed_at":"2018-09-18T04:31:49Z","author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/junegunn/fzf/pulls/1380","html_url":"https://github.com/junegunn/fzf/pull/1380","diff_url":"https://github.com/junegunn/fzf/pull/1380.diff","patch_url":"https://github.com/junegunn/fzf/pull/1380.patch"},"body":"This patch adds a new type of `tiebreak`: `proximity=path`. It works by ranking equally-scored candidates by their proximity to the given path argument, where proximity is defined as the number of shared leading path segments when split by the OS path separator.\r\n\r\nConsider the following simple file hierarchy:\r\n\r\n    test.txt\r\n    bar/test.txt\r\n    bar/main.txt\r\n    misc/test.txt\r\n\r\nWhere a user is currently in the context of `bar/main.txt`. This could be for a number of reasons, such as it being the file that is currently open in their editor (see junegunn/fzf.vim#360 and junegunn/fzf.vim#492). They now want to open `bar/test.txt`. If they invoke `fzf` and type, well, any search, the `by_length` scoring will make the `test.txt` file in the root the \"best\" candidate, as would `by_start`. `by_end` would propose `misc/test.txt`. `by_score` would also likely suggest `test.txt` in the root. None of these take into account the user's current location.\r\n\r\nWith this patch, the user can invoke `fzf --tiebreak path=bar/main.txt`, which will cause it to rank files that share a prefix segment (`bar/` in this case) to rank higher. Thus, when the user types, say, `t`, `bar/test.txt` will immediately be the top recommendation. In editor context, the user's editor should probably automatically add this flag based on the user's current file.\r\n\r\nThe flag also allows for more natural search in deeper hierarchies. For example, if the user is in `foobar/controller/admin.rb` here:\r\n\r\n    baz/controller/admin.rb\r\n    baz/views/admin.rb\r\n    foobar/controller/admin.rb\r\n    foobar/views/admin.rb\r\n\r\nAnd wants to quickly edit the view for that application (i.e., `foobar/views/admin.rb`), then\r\n\r\n    fzf --tiebreak path=foobar/controller/admin.rb\r\n\r\nwill rank `foobar/views/admin.rb` higher than `baz/views/admin.rb` for a search of `admin.rb`, which is what the user most likely expected.\r\n\r\nNote that contrary to other suggestions like only listing files at or below the user's current directory, this patch does *not* limit the user's ability to search beyond the scope of their current context (e.g., they *can* get to `baz/controller/admin.rb` if they so wish)."},"comment":{"url":"https://api.github.com/repos/junegunn/fzf/issues/comments/422252042","html_url":"https://github.com/junegunn/fzf/pull/1380#issuecomment-422252042","issue_url":"https://api.github.com/repos/junegunn/fzf/issues/1380","id":422252042,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMjI1MjA0Mg==","user":{"login":"jonhoo","id":176295,"node_id":"MDQ6VXNlcjE3NjI5NQ==","avatar_url":"https://avatars2.githubusercontent.com/u/176295?v=4","gravatar_id":"","url":"https://api.github.com/users/jonhoo","html_url":"https://github.com/jonhoo","followers_url":"https://api.github.com/users/jonhoo/followers","following_url":"https://api.github.com/users/jonhoo/following{/other_user}","gists_url":"https://api.github.com/users/jonhoo/gists{/gist_id}","starred_url":"https://api.github.com/users/jonhoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonhoo/subscriptions","organizations_url":"https://api.github.com/users/jonhoo/orgs","repos_url":"https://api.github.com/users/jonhoo/repos","events_url":"https://api.github.com/users/jonhoo/events{/privacy}","received_events_url":"https://api.github.com/users/jonhoo/received_events","type":"User","site_admin":false},"created_at":"2018-09-18T04:31:49Z","updated_at":"2018-09-18T04:31:49Z","author_association":"NONE","body":"Mmm, that's a fair argument. And thanks for the explicit example config! Sadly the solution you propose doesn't actually solve this issue (at least for me), since it only gives a binary \"close/not close\" ranking, as opposed to being ranked by proximity. I guess the way to solve this without modifying `fzf` is to implement a separate program that takes a list of files as input and order them by their proximity to an argument. That way you could do:\r\n```console\r\n$ fd -pFt f path/to/file | proximity-sort | fzf --tiebreak=index\r\n```\r\nI guess implementing `proximity-sort` is next on my TODO then :p"}}
{"actor":{"display_login":"jonhoo"}}