9 unstable releases (3 breaking)

0.4.0 Mar 23, 2025
0.3.0 Feb 23, 2025
0.2.3 Feb 7, 2025
0.2.2 Jan 21, 2025
0.1.2 Nov 17, 2024

#2263 in Command line utilities

Download history 10/week @ 2025-01-01 32/week @ 2025-01-08 46/week @ 2025-01-15 71/week @ 2025-01-22 12/week @ 2025-01-29 164/week @ 2025-02-05 20/week @ 2025-02-12 147/week @ 2025-02-19 68/week @ 2025-02-26 16/week @ 2025-03-05 126/week @ 2025-03-19 44/week @ 2025-03-26 18/week @ 2025-04-02 3/week @ 2025-04-09 8/week @ 2025-04-16

84 downloads per month

MIT license

140KB
3.5K SLoC

scooter

Scooter is an interactive find-and-replace terminal UI app.

Search with either a fixed string or a regular expression, enter a replacement, and interactively toggle which instances you want to replace.

If the instance you're attempting to replace has changed since the search was performed, e.g. if you've switched branches and that line no longer exists, that particular replacement won't occur: you'll see all such cases at the end.

Scooter preview

Contents

Features

Scooter respects both .gitignore and .ignore files.

You can add capture groups to the search regex and use them in the replacement string: for instance, if you use (\d) - (\w+) for the search text and ($2) "$1" as the replacement, then 9 - foo would be replaced with (foo) "9".

When viewing search results, you can open the selected file at the relevant line by pressing o. This will use the editor defined by your EDITOR environment variable. Scooter will automatically attempt to open the editor at the correct line number, but if you'd like to override the command used then you can set editor_open in your config file.

Usage

Run

scooter

in a terminal to launch Scooter. By default the current directory is used to search and replace in, but you can pass in a directory as the first argument to override this behaviour:

scooter ../foo/bar

A set of keymappings will be shown at the bottom of the window: these vary slightly depending on the screen you're on.

By default, Scooter uses a regex engine that supports only a subset of features to maximise performance. To use the full range of regex features, such as negative lookahead, start Scooter with the -a (--advanced-regex) flag.

Hidden files (such as those starting with a .) are ignored by default, but can be included by using the --hidden flag.

Search fields

When on the search screen the following fields are available:

  • Search text: Text to search with. Defaults to regex, unless "Fixed strings" is enabled, in which case this reverts to case-sensitive string search.
  • Replace text: Text to replace the search text with. If searching with regex, this can include capture groups.
  • Fixed strings: If enabled, search with plain case-sensitive strings. If disabled, search with regex.
  • Match whole word: If enabled, only match when the search string forms the entire word and not a substring in a larger word. For instance, if the search string is "foo", "foo bar" would be matched but not "foobar".
  • Match case: If enabled, match the case of the search string exactly, e.g. a search string of Bar would match foo Bar baz but not foo bar baz.
  • Files to include: Glob patterns, separated by commas (,), that file paths must match. For instance, *.rs, *.py matches all files with the .rs or .py extensions.
  • Files to exclude: Glob patterns, separated by commas (,), that file paths must not match. For instance, env/** ignores all files in the env directory. This field takes precedence over the pattern in the "Files to include" field.

Note that the glob matching library used in Scooter comes from the brilliant ripgrep, and matches the behaviour there: for instance, if you wanted to include only files in the directory dir1, you'd need to add dir1/** in the "Files to include" field - dir1 alone would not work.

Installation

Packaging status

Homebrew

On macOS and Linux, you can install Scooter using Homebrew:

brew install scooter

NixOS

Scooter is available as scooter in nixpkgs, currently on the unstable channel.

AUR

Install from the Arch User Repository with:

yay -S scooter

Or, to build from the latest commit:

yay -S scooter-git

Prebuilt binaries

You can download binaries from the releases page. After downloading, unzip the binary and move it to a directory in your PATH.

  • Linux
    • Intel/AMD: *-x86_64-unknown-linux-musl.tar.gz
    • ARM64: *-aarch64-unknown-linux-musl.tar.gz
  • macOS
    • Apple silicon: *-aarch64-apple-darwin.tar.gz
    • Intel: *-x86_64-apple-darwin.tar.gz
  • Windows
    • *-x86_64-pc-windows-msvc.zip

Cargo

Ensure you have cargo installed (see here), then run:

cargo install scooter

Building from source

Ensure you have cargo installed (see here), then run the following commands:

git clone git@github.com:thomasschafer/scooter.git
cd scooter
cargo install --path scooter --locked

Configuration options

Scooter looks for a TOML configuration file at:

  • Linux or macOS: ~/.config/scooter/config.toml
  • Windows: %AppData%\scooter\config.toml

The following options can be set in your configuration file:

[editor_open] section

command

The command used when pressing o on the search results page. Two variables are available: %file, which will be replaced with the file path of the seach result, and %line, which will be replaced with the line number of the result. For example:

[editor_open]
command = "vi %file +%line"

exit

Whether to exit after running the command defined by editor_open.command.

Editor configuration

Below are a couple of ways to configure Scooter to run in a floating window, without leaving your editor.

Helix

If you are using Helix in Tmux, you can add a keymap like the following to your Helix config to open Scooter with <enter> s:

[keys.select.ret]
s = ":sh tmux popup -xC -yC -w90% -h90% -E scooter"

You can also add the following to your Scooter config file to open files from the search results page with o:

[editor_open]
command = 'tmux send-keys -t "$TMUX_PANE" ":open %file:%line" Enter'
exit = true

Neovim

Install Toggleterm as per the instructions here, and then add the following Lua configuration, which opens up Scooter with <leader>s:

local Terminal = require("toggleterm.terminal").Terminal

local scooter = Terminal:new({ cmd = "scooter", hidden = true })

function _scooter_toggle()
  scooter:toggle()
end

vim.keymap.set("n", "<leader>s", "<cmd>lua _scooter_toggle()<CR>", {
  noremap = true,
  silent = true,
  desc = "Toggle Scooter"
})

Contributing

Contributions are very welcome! I'd be especially grateful for any contributions to add Scooter to popular package managers. If you'd like to add a new feature, please create an issue first so we can discuss the idea, then create a PR with your changes.

Dependencies

~17–29MB
~440K SLoC