{"id":13524409,"url":"https://github.com/garybernhardt/selecta","last_synced_at":"2025-05-15T03:05:58.338Z","repository":{"id":11143011,"uuid":"13509658","full_name":"garybernhardt/selecta","owner":"garybernhardt","description":"A fuzzy text selector for files and anything else you need to select. Use it from vim, from the command line, or anywhere you can run a shell command.","archived":false,"fork":false,"pushed_at":"2023-03-03T23:49:25.000Z","size":621,"stargazers_count":1342,"open_issues_count":6,"forks_count":81,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-05-14T23:45:46.174Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/garybernhardt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2013-10-11T21:04:22.000Z","updated_at":"2025-05-10T19:38:27.000Z","dependencies_parsed_at":"2022-08-07T06:01:10.280Z","dependency_job_id":"9fad3480-41e7-4750-8613-b135f2833b61","html_url":"https://github.com/garybernhardt/selecta","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garybernhardt%2Fselecta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garybernhardt%2Fselecta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garybernhardt%2Fselecta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garybernhardt%2Fselecta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/garybernhardt","download_url":"https://codeload.github.com/garybernhardt/selecta/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254264765,"owners_count":22041793,"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-08-01T06:01:09.832Z","updated_at":"2025-05-15T03:05:58.311Z","avatar_url":"https://github.com/garybernhardt.png","language":"Ruby","funding_links":[],"categories":["Command Line","Ruby"],"sub_categories":["Dependency Management"],"readme":"# Selecta\n\nSelecta is a fuzzy selector. You can use it for fuzzy selection in the style of\nCommand-T, ctrlp, etc. You can also use it to fuzzy select anything else:\ncommand names, help topics, identifiers; anything you have a list of.\n\nIt was originally written to select things from vim, but it has no dependency\non vim at all and is used for many other purposes. Its interface is dead\nsimple:\n\n* Pass it a list of choices on stdin.\n* It will present a pretty standard fuzzy selection interface to the user (and\n  block until they make a selection or kill it with ^C).\n* It will print the user's selection on stdout.\n\nFor example, you can say:\n\n```\ncat $(ls *.txt | selecta)\n```\n\nwhich will prompt the user to fuzzy-select one of the text files in the current\ndirectory, then print the contents of whichever one they choose. It looks like\nthis:\n\n![Demo](https://raw.github.com/garybernhardt/selecta/master/demo.gif)\n\nSelecta supports these keys:\n\n- ^W to delete the word before the cursor\n- ^H to delete the character before the cursor\n- ^U to delete the entire line\n- ^N to select the next match\n- ^P to select the previous match\n- ^C to quit without selecting a match\n\n## Theory of Operation\n\nSelecta is unusual in that it's a filter (it reads from/to stdin/stdout), but\nit's also an interactive program (it accepts user keystrokes and draws a UI).\nIt directly opens `/dev/tty` to do the latter.\n\nWith that exception aside, Selecta is a normal, well-behaved Unix tool. If a\nselection is made, the line will be written to stdout with a single trailing\nnewline. If no selection is made (meaning the user killed Selecta with ^C), it\nwill write nothing to stdout and exit with status code 1.\n\nBecause it's just a filter program, Selecta doesn't know about any other tools.\nSpecifically, it does not:\n\n- Read from or write to the disk.\n- Know about any editors (including vim).\n- Know what it's searching.\n- Perform any actions on the item you select.\n\nThe ranking algorithm is:\n\n- Select each input string that contains all of the characters in the query.\n  They must be in order, but don't have to be sequential. Case is ignored.\n- The score is the length of the matching substring. Lower is better.\n- If a character is on a word boundary, it only contributes 1 to the length, rather than the actual number of characters since the previous matching character. Querying \"app/models\" for \"am\" gives a score of 2, not 5.\n- Bonus for exact queries: when several adjacent characters match sequentially, only the first two score. Querying \"search_spec.rb\" for \"spec\" gives a score of 2, not 4.\n- Bonus for acronyms: when several sequential query characters exist on word boundaries, only the first two score. Querying \"app/models/user.rb\" for \"amu\" gives a score of 2, not 3.\n\nSome concrete examples:\n- \"ct\" will match \"cat\" and \"Crate\", but not \"tack\".\n- \"le\" will match \"lend\" and \"ladder\". \"lend\" will appear higher in the results\n  because the matching substring is shorter (\"le\" vs. \"ladde\").\n\n## Installation\n\nSelecta requires Ruby 1.9.3 or better.\n\nTo install on your Mac using [Homebrew](http://brew.sh), say:\n\n```shell\nbrew install selecta\n```\n\nFor other systems, copy the `selecta` script to your path. ~/bin is a great\nplace for it. If you don't currently have a ~/bin, just do `mkdir ~/bin` and\nadd `export PATH=\"$HOME/bin:$PATH\"` to your .zshrc, .bashrc, etc.\n\nSelecta is *not installable as a Ruby gem*! Gems are only good for\napplication-specific tools. You want Selecta available at all times. If it were\na gem, it would sometimes disappear when switching Rubies, gemsets, etc.\n\n## Use with Vim\n\nThere's no vim plugin. It may not end up needing one; we'll see. For now, you\ncan just stick the code below in your .vimrc to invoke Selecta with `\u003cleader\u003ef`\n(this will be `\\f` unless you've changed your leader). Note that Selecta has to\nrun in a terminal by its nature, so this Vim example will not work in graphical\nVims like MacVim.\n\n```vimscript\n\" Run a given vim command on the results of fuzzy selecting from a given shell\n\" command. See usage below.\nfunction! SelectaCommand(choice_command, selecta_args, vim_command)\n  try\n    let selection = system(a:choice_command . \" | selecta \" . a:selecta_args)\n  catch /Vim:Interrupt/\n    \" Swallow the ^C so that the redraw below happens; otherwise there will be\n    \" leftovers from selecta on the screen\n    redraw!\n    return\n  endtry\n  redraw!\n  exec a:vim_command . \" \" . selection\nendfunction\n\n\" Find all files in all non-dot directories starting in the working directory.\n\" Fuzzy select one of those. Open the selected file with :e.\nnnoremap \u003cleader\u003ef :call SelectaCommand(\"find * -type f\", \"\", \":e\")\u003ccr\u003e\n```\n\n## Usage Examples\n\nFor other examples of using Selecta with Vim, git, zsh, etc., see the [examples](https://github.com/garybernhardt/selecta/blob/master/EXAMPLES.md) file.\nIt has pre-built configurations for many use cases.\n\n## FAQ\n\n**Won't this be slow?**\n\nNope: startup and termination together burn about 23 ms of CPU on my machine (a\nmid-2011 MacBook Air).\nFor under 100,000 lines of input or so, searching is quite snappy, and you'll rarely want to search through more than that.\nOn modern machines, finding files is also quite fast: `find` on a 100,000-file directory takes about 200 ms on my machine.\n\n**What about caching, selecting only certain file types, etc.?**\n\nThose are different problems. This is just a simple fuzzy finding user\ninterface. It could be combined with caching, etc. I don't use caching myself,\nprefering to keep repos small. Selecta was partially motivated by frustration\nwith existing fuzzy file finders, which occasionally showed incorrect results\nwith caching turned on but were painfully slow with caching disabled.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarybernhardt%2Fselecta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgarybernhardt%2Fselecta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarybernhardt%2Fselecta/lists"}