• Stars
    star
    1,681
  • Rank 27,769 (Top 0.6 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CLI search and replace | Space Age seD

SAD!

Space Age seD

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)

preview1

If you have delta installed, try --pager 'delta -s' for side by side view

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 :)

preview2

How to use sad?

with fzf

export GIT_PAGER='<highlighter-of-your-choice>'
# ^ can be done in your bash/zsh/rc file.
find "$FIND_ARGS" | sad '<pattern>' '<replacement>'

without fzf

find "$FIND_ARGS" | sad '<pattern>' '<replacement>' | highlighter-of-your-choice

or

find "$FIND_ARGS" | sad '<pattern>' '<replacement>' --pager=<highlighter-of-your-choice>

or

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.

  • run with --commit, and redirect stdout to a file or /dev/null


Requirements

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!

Commandline fuzzer

fzf

sad does not come with a UI, it uses fzf to perform selection.

Diff Colorizer

Any git compatible colourizer would work. I prefer these two:

delta

fd <files> | sad <pattern> <replacement> | delta

diff-so-fancy

fd <files> | sad <pattern> <replacement> | diff-so-fancy | less

Environmental Variables

Name Function
GIT_PAGER sad will use the same pager as git

Flags

Name Function
-f --flags Regex flags, see below
-k --commit No preview, write changes to file
-0 --read0 Use \x00 as stdin delimiter
-e --exact String literal mode
-p --pager Colourizing program, disable = never
--fzf Additional Fzf options, disable = never
-u --unified Same as in GNU diff, affects hunk size

Regex Flags

By default, sad uses smartcase, and multiline matching.

For each options, lowercase toggles on and uppercase toggles off.

ie. i => on, I => off

Name Function
i case insensitive (works for --exact mode as well)
m multiline: ^ $ match each line
s allow . match \n
u swap the meaning of * and *? patterns, (normally * is lazy and *? is greedy)
x ignore whitespace and allow # comments

Exit Codes

Code Meaning
0 Good
1 Bad
130 Interrupted (ie. user cancel), or if using fzf, it will always exit 130.

GET SAD NOW!

For scripting, use the following format:

# replace `x86_64-unknown-linux-gnu.deb` with your desired package
wget 'https://github.com/ms-jpq/sad/releases/latest/download/x86_64-unknown-linux-gnu.deb'

Homebrew:

brew install sad

Scoop:

scoop install sad

Snap Store:

coming soon...

Distribution packages:

Debian/Ubuntu:

You can download sad deb packages from the github release page.

Arch Linux:

There is an official Arch Linux package that can be installed via pacman:

pacman -Syu sad
Other:

Missing a package for your favourite distribution? Let us know!

Compile from source:

Requirements:

To compile sad yourself you'll have to make sure you have Rust and cargo installed.

Install instructions:

To install cargo from source you can run the following commands:

cargo install --locked --all-features \
  --git https://github.com/ms-jpq/sad --branch senpai

If you want to install it in a specific directory you can provide the --root flag, like so:

cargo install --locked --all-features --root="/usr/bin/" \
  --git https://github.com/ms-jpq/sad --branch senpai

What about stdin -> stdout

If you just want to edit the shell stream, I would recommend sd, it uses the same concept, but its more for in stream edits. sad was inspired by my initial usage of sd.

command1 | sd '<pattern>' '<replacement>' | command2

ripgrep with --replace also works

command1 | rg --passthru --replace '<replacement>' -- '<pattern>' | command2

Take note however, rg will exit 1, it it finds no matches.

Thank yous

Special thanks to MadeOfMagicAndWires for their generous contribution for maintaining the AUR package.

Bugs

Please file an issue if you see one <3

More Repositories

1

coq_nvim

Fast as FUCK nvim completion. SQLite, concurrent scheduler, hundreds of hours of optimization.
Python
3,435
star
2

chadtree

File manager for Neovim. Better than NERDTree.
Python
1,618
star
3

noact

Minimalist React (< 70 lines)
TypeScript
317
star
4

lua-async-await

Async Await in 90 lines of code.
Lua
309
star
5

gay

Colour your text / terminal to be more gay. ๐Ÿณ๏ธโ€๐ŸŒˆ
Python
305
star
6

isomorphic_copy

Cross platform clipboard | networkless! remote copy
Python
206
star
7

kde-in-docker

So you can run KDE inside a browser
Dockerfile
109
star
8

docker-time-machine

Zero Configuration, time machine for MacOS | Docker ๐Ÿณ
Shell
83
star
9

markdown-live-preview

markdown live preview | works with any editor
Python
73
star
10

windows-in-docker

Manage Windows in Docker (easy)
Python
61
star
11

coq.thirdparty

Module lua sources for `coq.nvim`, first & third party
Lua
61
star
12

windows-in-docker-old

WHY? So you can run Windows "as a container"
Shell
51
star
13

nvim_rc

Python
49
star
14

simple-traefik-dash

Zero conf service dashboard for Traefik v2 Ingress Controller
F#
33
star
15

sync-dockerhub-readme

Github action to sync <readme.md> to Dockerhub
Python
22
star
16

simple-traefik-identity

Simple & Configurable -- single sign-on auth, for Traefik.
F#
22
star
17

coq.artifacts

Python
16
star
18

docker-home-router

Python
13
star
19

vim.bench

Reproducible nvim completion framework benchmarks.
Python
13
star
20

vim.conf-2023

SCSS
10
star
21

download-windows-iso

Python script to download official windows iso
Python
9
star
22

pynvim_pp

Python
8
star
23

snips

Vim Snippet
7
star
24

tmux_rc

Python
6
star
25

forechan

Go style CSP for Python
Python
6
star
26

lab

We have cloud at home - mom
Shell
6
star
27

kaleidoscope

Interactive & arbitrary Chaos Game fractal visualization tool
TypeScript
5
star
28

vim.benchmarks

5
star
29

nda

NPM - Domain Agnostic :: use with NPM dependency manager
TypeScript
5
star
30

nodebook-docker

Docker in Docker version of Nodebook (multilang repl)
Dockerfile
5
star
31

shell_rc

Shell
5
star
32

simple-markdown-showcase

Responsive personal portfolio pages using Github APIs.
Python
5
star
33

bing-daily-images

A docker container that downloads bing daily images for you.
Python
4
star
34

simple-reeducks

Minimalist Classless Redux in Swift
Swift
4
star
35

auto-github-push

Github action to refresh various Github inactivity countdowns.
Python
4
star
36

sortd

sorting commands for stdin -> stdout
Python
4
star
37

ms-jpq

4
star
38

iterm2

Python
3
star
39

ms-jpq.github.io

https://ms-jpq.github.io
HTML
3
star
40

std2

Python
3
star
41

vim.conf

TeX
3
star
42

defcon604-2023

Shell
2
star
43

emacs_rc

Emacs Lisp
2
star
44

fda

Fsharp - Domain Agnostic :: use with Paket dependency manager
F#
2
star
45

py-dev

Python
2
star
46

deb

2
star
47

kaleidoscope-page

Page for Kaleidoscope
HTML
1
star
48

languagetool-cli

Python
1
star
49

homebrew-sad

Ruby
1
star
50

cda

SASS - Domain Agnostic :: use with NPM dependency manager
SCSS
1
star
51

noact-page

Page for Noact
CSS
1
star
52

deb-src

PPA builder, hosted on Github pages
Makefile
1
star
53

mol

Minimal hardware accelerated `curl -- linux.iso | qemu-system-aarch64` scripts.
Shell
1
star