Top Related Projects
:cherry_blossom: A command-line fuzzy finder
Fuzzy Finder in rust!
:mag: A simple, fast fuzzy finder for the terminal
PathPicker accepts a wide range of input -- output from git commands, grep results, searches -- pretty much anything. After parsing the input, PathPicker presents you with a nice UI to select which files you're interested in. After that you can open them in your favorite editor or execute arbitrary commands.
Simplistic interactive filtering tool
An interactive cheatsheet tool for the command-line
Quick Overview
Skim is a fuzzy finder written in Rust, designed to be a faster and more feature-rich alternative to fzf. It provides a command-line interface for searching and filtering through large amounts of text data, making it useful for file navigation, command history searching, and more.
Pros
- Fast performance due to Rust implementation
- Cross-platform support (Linux, macOS, Windows)
- Highly customizable with various options and keybindings
- Supports multi-selection and preview functionality
Cons
- Smaller community compared to fzf
- May require additional setup for some integrations
- Documentation could be more comprehensive
- Limited built-in shell integrations compared to fzf
Code Examples
- Basic usage in a shell script:
# Search for files in the current directory
files=$(find . -type f | skim)
- Using skim with custom options:
# Search with a custom prompt and multi-select enabled
selected_items=$(echo "item1\nitem2\nitem3" | sk --prompt="Select items: " --multi)
- Integration with Git:
# Fuzzy search through Git commits
git log --oneline | sk --ansi --preview "echo {} | cut -d' ' -f1 | xargs git show --color=always"
Getting Started
To install skim, you can use Cargo (Rust's package manager):
cargo install skim
For basic usage, pipe input to skim:
find . -type f | sk
To customize skim, you can add options:
sk --height 40% --reverse --multi
For more advanced usage and integration with your shell, refer to the project's documentation on GitHub.
Competitor Comparisons
:cherry_blossom: A command-line fuzzy finder
Pros of fzf
- Written in Go, which offers good performance and cross-platform compatibility
- More mature project with a larger user base and ecosystem
- Extensive documentation and examples available
Cons of fzf
- Larger binary size compared to Skim
- Slower startup time for large datasets
Code Comparison
skim:
use skim::prelude::*;
let options = SkimOptionsBuilder::default()
.height(Some("50%"))
.multi(true)
.build()
.unwrap();
let selected_items = Skim::run_with(&options, None)
.map(|out| out.selected_items)
.unwrap_or_else(|| Vec::new());
fzf:
import "github.com/junegunn/fzf/src/fzf"
opts := fzf.DefaultOptions()
opts.Multi = true
finder := fzf.New(opts)
selected, _ := finder.Find(os.Stdin, false)
Both Skim and fzf provide similar functionality for fuzzy finding, but they differ in implementation language and some features. Skim is written in Rust, offering memory safety and potentially faster execution for certain operations. fzf, on the other hand, has a more established ecosystem and broader adoption. The code examples demonstrate the similar API structure, with both libraries allowing customization of options and returning selected items.
Fuzzy Finder in rust!
Pros of skim
- Faster performance due to Rust implementation
- More extensive feature set including multi-select and preview
- Active development with frequent updates
Cons of skim
- Larger binary size due to Rust compilation
- Steeper learning curve for configuration and customization
- May have compatibility issues with some shell environments
Code Comparison
skim:
use skim::prelude::*;
let options = SkimOptionsBuilder::default()
.height(Some("50%"))
.multi(true)
.build()
.unwrap();
let selected_items = Skim::run_with(&options, None)
.map(|out| out.selected_items)
.unwrap_or_else(|| Vec::new());
skim>:
# No direct code comparison available as skim> is not a separate repository
# It appears to be a typo or misunderstanding in the original question
Note: The comparison between skim-rs/skim and skim-rs/skim> seems to be an error, as there is no separate repository for "skim>". The comparison provided focuses on the features and characteristics of the skim project itself, as there is no alternative repository to compare it against based on the given information.
:mag: A simple, fast fuzzy finder for the terminal
Pros of fzy
- Written in C, potentially offering better performance for large datasets
- Extremely lightweight and minimal dependencies
- Simple and straightforward implementation
Cons of fzy
- Less feature-rich compared to skim
- Limited customization options
- Lacks multi-core support for improved performance on modern systems
Code Comparison
skim (Rust):
pub fn fuzzy_indices(choice: &str, query: &str) -> Option<(f64, Vec<usize>)> {
if query.is_empty() {
return Some((SCORE_MIN, vec![]));
}
let choice = choice.to_lowercase();
let query = query.to_lowercase();
// ... (implementation continues)
}
fzy (C):
score_t match_positions(const char *haystack, const char *needle, size_t *positions) {
if (!*needle)
return SCORE_MAX;
score_t score = 0;
size_t match_required = strlen(needle);
size_t last_match = 0;
// ... (implementation continues)
}
Both implementations focus on fuzzy matching algorithms, but skim uses Rust's type system and functional programming features, while fzy relies on C's lower-level constructs for potentially faster execution.
PathPicker accepts a wide range of input -- output from git commands, grep results, searches -- pretty much anything. After parsing the input, PathPicker presents you with a nice UI to select which files you're interested in. After that you can open them in your favorite editor or execute arbitrary commands.
Pros of PathPicker
- Written in Python, making it more accessible for scripting and customization
- Integrates well with command-line tools and outputs
- Provides a more interactive interface for file selection
Cons of PathPicker
- Slower performance compared to Skim's Rust implementation
- Less actively maintained (last commit over 2 years ago)
- Limited to file selection, while Skim offers more general-purpose fuzzy finding
Code Comparison
PathPicker (Python):
def getFilesFromLines(self, lines):
return set(
line.strip()
for line in lines
if os.path.exists(line.strip())
)
Skim (Rust):
pub fn parse_finder_output(output: &str) -> Vec<String> {
output
.lines()
.filter(|line| !line.is_empty())
.map(|line| line.to_string())
.collect()
}
Both projects aim to improve command-line workflows, but they take different approaches. PathPicker focuses on file selection from command outputs, while Skim provides a more general-purpose fuzzy finder. Skim's Rust implementation offers better performance, while PathPicker's Python codebase may be more familiar to some developers. The choice between them depends on specific use cases and performance requirements.
Simplistic interactive filtering tool
Pros of peco
- Written in Go, which may be more familiar to some developers
- Longer project history and potentially more mature codebase
- Extensive documentation and examples available
Cons of peco
- Generally slower performance compared to skim
- Less frequent updates and maintenance
- Lacks some advanced features present in skim (e.g., preview window)
Code comparison
skim:
use skim::prelude::*;
let options = SkimOptionsBuilder::default()
.height(Some("50%"))
.multi(true)
.build()
.unwrap();
let selected_items = Skim::run_with(&options, None)
.map(|out| out.selected_items)
.unwrap_or_else(|| Vec::new());
peco:
import "github.com/peco/peco"
opts := peco.NewConfig()
opts.InitialFilter = "Fuzzy"
opts.Layout = "bottom-up"
p, err := peco.New(opts)
if err != nil {
// handle error
}
Both skim and peco are interactive filtering tools, but they differ in implementation language and performance characteristics. skim, written in Rust, offers better performance and more recent features, while peco, implemented in Go, has a longer history and potentially more stability. The code examples demonstrate the basic setup for each tool, highlighting their different approaches to configuration and execution.
An interactive cheatsheet tool for the command-line
Pros of navi
- Specialized for command-line cheatsheets, offering a more focused and tailored experience
- Supports interactive command execution and variable substitution
- Allows for community-driven cheatsheet repositories and easy sharing
Cons of navi
- More complex setup and configuration compared to skim's simplicity
- Limited to command-line cheatsheets, while skim is a general-purpose fuzzy finder
- Steeper learning curve for users unfamiliar with cheatsheet concepts
Code comparison
skim:
pub fn run(&mut self) -> Result<()> {
self.read_lines()?;
self.process_events()?;
Ok(())
}
navi:
fn main() -> Result<(), Box<dyn std::error::Error>> {
let opts: Opts = Opts::parse();
let config = Config::new(opts)?;
run(config)
}
Both projects use Rust, but navi's main function demonstrates a more complex configuration setup, while skim's run
method shows a simpler event-driven approach.
skim is a general-purpose fuzzy finder that can be used in various contexts, offering flexibility and ease of integration. navi, on the other hand, is specifically designed for managing and executing command-line cheatsheets, providing a more specialized tool for developers and system administrators who frequently work with complex commands.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Life is short, skim!
Half of our life is spent on navigation: files, lines, commands⦠You need skim! It's a general fuzzy finder that saves you time.
skim provides a single executable: sk
. Anywhere you would want to use
grep
, try sk
instead!
Table of contents
- Installation
- Usage
- Tools compatible with
skim
- Customization
- Advanced Topics
- FAQ
- Differences from fzf
- How to contribute
- Troubleshooting
Installation
The skim project contains several components:
sk
executable -- the core.sk-tmux
-- script for launchingsk
in a tmux pane.- Vim/Nvim plugin -- to call
sk
inside Vim/Nvim. Check skim.vim for Vim support.
Package Managers
OS | Package Manager | Command |
---|---|---|
macOS | Homebrew | brew install sk |
macOS | MacPorts | sudo port install skim |
Fedora | dnf | dnf install skim |
Alpine | apk | apk add skim |
Arch | pacman | pacman -S skim |
Gentoo | Portage | emerge --ask app-misc/skim |
Guix | guix | guix install skim |
Void | XBPS | xbps-install -S skim |
Manually
Any of the following applies:
- Using Git
$ git clone --depth 1 git@github.com:skim-rs/skim.git ~/.skim $ ~/.skim/install
- Using Binary: directly download the sk executable.
- Install from crates.io:
cargo install skim
- Build Manually
$ git clone --depth 1 git@github.com:skim-rs/skim.git ~/.skim $ cd ~/.skim $ cargo install $ cargo build --release $ # put the resulting `target/release/sk` executable on your PATH.
Usage
skim can be used as a general filter (like grep
) or as an interactive
interface for invoking commands.
As Vim plugin
Via vim-plug (recommended):
Plug 'skim-rs/skim', { 'dir': '~/.skim', 'do': './install' }
As filter
Try the following:
# directly invoke skim
sk
# or pipe some input to it: (press TAB key to select multiple items with -m enabled)
vim $(find . -name "*.rs" | sk -m)
The above command will allow you to select files with ".rs" extension and open the ones you selected in Vim.
As Interactive Interface
skim
can invoke other commands dynamically. Normally you would want to
integrate it with grep,
ack,
ag, or
rg for searching contents in a
project directory:
# works with grep
sk --ansi -i -c 'grep -rI --color=always --line-number "{}" .'
# works with ack
sk --ansi -i -c 'ack --color "{}"'
# works with ag
sk --ansi -i -c 'ag --color "{}"'
# works with rg
sk --ansi -i -c 'rg --color=always --line-number "{}"'
Note: in these examples,
{}
will be litterally expanded to the current input query. This does mean that these examples will search for the exact query string, and not fuzzily. To achieve fuzzy search, you need to pipe the command output intosk
, without interactive mode.
Key Bindings
Some commonly used key bindings:
Key | Action |
---|---|
Enter | Accept (select current one and quit) |
ESC/Ctrl-G | Abort |
Ctrl-P/Up | Move cursor up |
Ctrl-N/Down | Move cursor Down |
TAB | Toggle selection and move down (with -m ) |
Shift-TAB | Toggle selection and move up (with -m ) |
For the full list of key bindings, check out the man
page (man sk
).
Search Syntax
skim
borrows fzf
's syntax for matching items:
Token | Match type | Description |
---|---|---|
text | fuzzy-match | items that match text |
^music | prefix-exact-match | items that start with music |
.mp3$ | suffix-exact-match | items that end with .mp3 |
'wild | exact-match (quoted) | items that include wild |
!fire | inverse-exact-match | items that do not include fire |
!.mp3$ | inverse-suffix-exact-match | items that do not end with .mp3 |
skim
also supports the combination of tokens.
- Whitespace has the meaning of
AND
. With the termsrc main
,skim
will search for items that match bothsrc
andmain
. |
meansOR
(note the spaces around|
). With the term.md$ | .markdown$
,skim
will search for items ends with either.md
or.markdown
.OR
has higher precedence. Soreadme .md$ | .markdown$
is grouped intoreadme AND (.md$ OR .markdown$)
.
In case that you want to use regular expressions, skim
provides regex
mode:
sk --regex
You can switch to regex
mode dynamically by pressing Ctrl-R
(Rotate Mode).
exit code
Exit Code | Meaning |
---|---|
0 | Exited normally |
1 | No Match found |
130 | Aborted by Ctrl-C/Ctrl-G/ESC/etc... |
Tools compatible with skim
These tools are or aim to be compatible with skim
:
fzf-lua neovim plugin
A neovim plugin allowing fzf and skim to be used in a to navigate your code.
Install it with your package manager, following the README. For instance, with lazy.nvim
:
{
"ibhagwan/fzf-lua",
-- enable `sk` support instead of the default `fzf`
opts = {'skim'}
}
nu_plugin_skim
A nushell plugin to allow for better interaction between skim and nushell.
Following the instruction in the plugin's README, you can install it with cargo:
cargo install nu_plugin_skim
plugin add ~/.cargo/bin/nu_plugin_skim
Customization
The doc here is only a preview, please check the man page (man sk
) for a full
list of options.
Keymap
Specify the bindings with comma separated pairs (no space allowed). For example:
sk --bind 'alt-a:select-all,alt-d:deselect-all'
Additionally, use +
to concatenate actions, such as execute-silent(echo {} | pbcopy)+abort
.
See the KEY BINDINGS section of the man page for details.
Sort Criteria
There are five sort keys for results: score, index, begin, end, length
. You can
specify how the records are sorted by sk --tiebreak score,index,-begin
or any
other order you want.
Color Scheme
It is a high chance that you are a better artist than me. Luckily you won't
be stuck with the default colors - skim
supports customization of the color scheme.
--color=[BASE_SCHEME][,COLOR:ANSI]
The configuration of colors starts with the name of the base color scheme, followed by custom color mappings. For example:
sk --color=current_bg:24
sk --color=light,fg:232,bg:255,current_bg:116,info:27
See the --color
option in the man page for details.
Misc
--ansi
: to parse ANSI color codes (e.g.,\e[32mABC
) of the data source--regex
: use the query as regular expression to match the data source
Advanced Topics
Interactive mode
In interactive mode, you can invoke a command dynamically. Try it out:
sk --ansi -i -c 'rg --color=always --line-number "{}"'
How does it work?
- Skim accepts two kinds of sources: Command output or piped input
- Skim has two kinds of prompts: A query prompt to specify the query pattern and a command prompt to specify the "arguments" of the command
-c
is used to specify the command to execute and defaults toSKIM_DEFAULT_COMMAND
-i
tells skim to open command prompt on startup, which will showc>
by default.
If you want to further narrow down the results returned by the command, press
Ctrl-Q
to toggle interactive mode.
Executing external programs
You can set up key bindings for starting external processes without leaving skim (execute
, execute-silent
).
# Press F1 to open the file with less without leaving skim
# Press CTRL-Y to copy the line to clipboard and aborts skim (requires pbcopy)
sk --bind 'f1:execute(less -f {}),ctrl-y:execute-silent(echo {} | pbcopy)+abort'
Preview Window
This is a great feature of fzf that skim borrows. For example, we use 'ag' to
find the matched lines, and once we narrow down to the target lines, we want to
finally decide which lines to pick by checking the context around the line.
grep
and ag
have the option --context
, and skim can make use of --context
for
a better preview window. For example:
sk --ansi -i -c 'ag --color "{}"' --preview "preview.sh {}"
(Note that preview.sh is a script to print the context given filename:lines:columns)
You get things like this:
How does it work?
If the preview command is given by the --preview
option, skim will replace the
{}
with the current highlighted line surrounded by single quotes, call the
command to get the output, and print the output on the preview window.
Sometimes you don't need the whole line for invoking the command. In this case
you can use {}
, {1..}
, {..3}
or {1..5}
to select the fields. The
syntax is explained in the section Fields Support.
Lastly, you might want to configure the position of preview window with --preview-window
:
--preview-window up:30%
to put the window in the up position with height 30% of the total height of skim.--preview-window left:10:wrap
to specify thewrap
allows the preview window to wrap the output of the preview command.--preview-window wrap:hidden
to hide the preview window at startup, later it can be shown by the actiontoggle-preview
.
Fields support
Normally only plugin users need to understand this.
For example, you have the data source with the format:
<filename>:<line number>:<column number>
However, you want to search <filename>
only when typing in queries. That
means when you type 21
, you want to find a <filename>
that contains 21
,
but not matching line number or column number.
You can use sk --delimiter ':' --nth 1
to achieve this.
You can also use --with-nth
to re-arrange the order of fields.
Range Syntax
<num>
-- to specify thenum
-th fields, starting with 1.start..
-- starting from thestart
-th fields and the rest...end
-- starting from the0
-th field, all the way toend
-th field, includingend
.start..end
-- starting fromstart
-th field, all the way toend
-th field, includingend
.
Use as a library
Skim can be used as a library in your Rust crates.
First, add skim into your Cargo.toml
:
[dependencies]
skim = "*"
Then try to run this simple example:
extern crate skim;
use skim::prelude::*;
use std::io::Cursor;
pub fn main() {
let options = SkimOptionsBuilder::default()
.height(Some("50%"))
.multi(true)
.build()
.unwrap();
let input = "aaaaa\nbbbb\nccc".to_string();
// `SkimItemReader` is a helper to turn any `BufRead` into a stream of `SkimItem`
// `SkimItem` was implemented for `AsRef<str>` by default
let item_reader = SkimItemReader::default();
let items = item_reader.of_bufread(Cursor::new(input));
// `run_with` would read and show items from the stream
let selected_items = Skim::run_with(&options, Some(items))
.map(|out| out.selected_items)
.unwrap_or_else(|| Vec::new());
for item in selected_items.iter() {
print!("{}{}", item.output(), "\n");
}
}
Given an Option<SkimItemReceiver>
, skim will read items accordingly, do its
job and bring us back the user selection including the selected items, the
query, etc. Note that:
SkimItemReceiver
iscrossbeam::channel::Receiver<Arc<dyn SkimItem>>
- If it is none, it will invoke the given command and read items from command output
- Otherwise, it will read the items from the (crossbeam) channel.
Trait SkimItem
is provided to customize how a line could be displayed,
compared and previewed. It is implemented by default for AsRef<str>
Plus, SkimItemReader
is a helper to convert a BufRead
into
SkimItemReceiver
(we can easily turn a File
or String
into BufRead
),
so that you could deal with strings or files easily.
Check out more examples under the examples/ directory.
FAQ
How to ignore files?
Skim invokes find .
to fetch a list of files for filtering. You can override
that by setting the environment variable SKIM_DEFAULT_COMMAND
. For example:
$ SKIM_DEFAULT_COMMAND="fd --type f || git ls-tree -r --name-only HEAD || rg --files || find ."
$ sk
You could put it in your .bashrc
or .zshrc
if you like it to be default.
Some files are not shown in Vim plugin
If you use the Vim plugin and execute the :SK
command, you might find some
of your files not shown.
As described in #3, in the Vim
plugin, SKIM_DEFAULT_COMMAND
is set to the command by default:
let $SKIM_DEFAULT_COMMAND = "git ls-tree -r --name-only HEAD || rg --files || ag -l -g \"\" || find ."
That means, the files not recognized by git will not shown. Either override the
default with let $SKIM_DEFAULT_COMMAND = ''
or find the missing file by
yourself.
Differences from fzf
fzf is a command-line fuzzy finder written in Go and skim tries to implement a new one in Rust!
This project is written from scratch. Some decisions of implementation are different from fzf. For example:
skim
is a binary as well as a library while fzf is only a binary.skim
has an interactive mode.skim
supports pre-selection- The fuzzy search algorithm is different.
UI of showing matched items.(fzf has this now)fzf
will show only the range matched whileskim
will show each character matched.: now it is the same with fzf.skim
's range syntax is Git style
How to contribute
Create new issues if you encounter any bugs or have any ideas. Pull requests are warmly welcomed.
Troubleshooting
No line feed issues with nix, FreeBSD, termux
If you encounter display issues like:
$ for n in {1..10}; do echo "$n"; done | sk
0/10 0/0.> 10/10 10 9 8 7 6 5 4 3 2> 1
For example
You need to set TERMINFO or TERMINFO_DIRS to the path of a correct terminfo database path
For example, with termux, you can add this in your bashrc:
export TERMINFO=/data/data/com.termux/files/usr/share/terminfo
Top Related Projects
:cherry_blossom: A command-line fuzzy finder
Fuzzy Finder in rust!
:mag: A simple, fast fuzzy finder for the terminal
PathPicker accepts a wide range of input -- output from git commands, grep results, searches -- pretty much anything. After parsing the input, PathPicker presents you with a nice UI to select which files you're interested in. After that you can open them in your favorite editor or execute arbitrary commands.
Simplistic interactive filtering tool
An interactive cheatsheet tool for the command-line
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot