LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

comby

structural code search and replace tool

TLDR

Simple replacement
$ comby 'console.log(:[arg])' 'logger.info(:[arg])' [.js]
copy
Replace in directory
$ comby 'foo(:[x])' 'bar(:[x])' [src/] -matcher [.py]
copy
Preview changes
$ comby 'old' 'new' -match-only
copy
Interactive review
$ comby 'pattern' 'replacement' -review
copy
In-place modification
$ comby 'old' 'new' -in-place [file.go]
copy
Diff output
$ comby 'old' 'new' -diff [file.js]
copy

SYNOPSIS

comby matchtemplate rewritetemplate [path] [options]

DESCRIPTION

comby is a structural code search and replace tool for any language. Uses lightweight templates with holes (:[name]) to match code structures. Understands syntax of code blocks, strings, and comments.

PARAMETERS

-matcher ext

File extension matcher (.py, .js, etc.)
-match-only
Only show matches, don't rewrite
-in-place
Modify files in place
-diff
Show unified diff output
-review
Interactive review mode
-stdin
Read from stdin
-stdout
Write to stdout
-count
Count matches only
-d dir
Target directory

HOLE SYNTAX

:[name]

Match any expression
:[name:e]
Match balanced expression
:[[name]]
Match across lines
:[_]
Anonymous hole (discard)

INSTALL

brew install comby
copy
nix profile install nixpkgs#comby
copy

CAVEATS

Better than regex for nested structures. Does not support indentation-sensitive languages (Python, Haskell).

SEE ALSO

sed(1), ast-grep(1), semgrep(1)

RESOURCES

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid