What does it do?
Basically sad is a Batch File Edit tool.
It will show you a really nice diff of proposed changes before you commit them.
Unlike sed, you can double check before you fat finger your edit.
Preview (with fzf)
Selectively replace std
-> joseph joestar in the sad repo.
You can pick and choose which changes to apply.
You can also choose the clustering factor for changes using
--unified=<n>. (Same as in GNU diff)
Preview (no fzf)
Replace all'"(\d+)"' -> '🌈$1🌈' in the chromium repo.
use --commit or -k to commit changes all at once.
-c is taken because sad has to trick fzf into thinking it's bash :)
How to use sad?
export GIT_PAGER='<highlighter-of-your-choice>' # ^ can be done in your bash/zsh/rc file. find "$FIND_ARGS" | sad '<pattern>' '<replacement>'
find "$FIND_ARGS" | sad '<pattern>' '<replacement>' | highlighter-of-your-choice
find "$FIND_ARGS" | sad '<pattern>' '<replacement>' --pager=<highlighter-of-your-choice>
export GIT_PAGER='<highlighter-of-your-choice>' find "$FIND_ARGS" | sad '<pattern>' '<replacement>'
gotta go fast
If you wanna go fast.
preview to verify you really want the changes.
--commit, and redirect
stdoutto a file or
Technically none of these are "required", but they make
sad so much happier.
If you install the things below,
sad will automatically use them. It's progressive enhancement!
sad does not come with a UI, it uses
fzf to perform selection.
git compatible colourizer would work. I perfer these two:
fd <files> | sad <pattern> <replacement> | delta
fd <files> | sad <pattern> <replacement> | diff-so-fancy | less
||Regex flags, see below|
||No preview, write changes to file|
||String literal mode|
||Colourizing program, disable =
||Additional Fzf options, disable =
||Same as in GNU
sad uses smartcase, and multiline matching.
||case insensitive (works for
||case sensitive (works for
||ignore whitespace and allow
||Interrupted (ie. user cancel), or if using
GET SAD NOW!
brew install ms-jpq/sad/sad
You can download
sad deb packages from the github release page.
You can find the
PKGBUILD on the AUR.
Missing a package for your favourite distribution? Let us know!
Compile from source:
To compile sad yourself you'll have to make sure you have
To install cargo from source you can run the following commands:
cargo install --locked --all-features --path .
If you want to install it in a specific directory you can provide the
flag, like so:
cargo install --locked --all-features --root="/usr/bin/" --path .
What about stdin -> stdout
If you just want to edit the shell stream, I would recommand
sd, it uses the same concept, but its more for in stream edits.
sad was inspired by my initial useage of
command1 | sd '<pattern>' '<replacement>' | command2
--replace also works
command1 | rg --passthru --replace '<replacement>' -- '<pattern>' | command2
Take note however,
exit 1, it it finds no matches.