Miscellaneous Utils

Published on 30 December 2022

Docker Image for Nvim

docker run -it --rm --init anatolelucet/neovim:nightly ash

Also, see this post.

Watch Stuff and Run Cmd

watchexec --clear -re go,mod go run .

Find and Tell the Number of Files Where the Pattern Is Present

rg -F '../../' -g '\*.scss' -l | wc -l

-F = search for text succeeding -F literally
-g = in files ending with scss, i.e. sass files
-l = and report all the files that match the pattern/text

wc -l = show the count of lines, i.e. show the number of files that have that pattern/text

Find and Replace With Sed

rg '_(.*)\.scss' -g '*.ts\*' --files-with-matches | xargs sed -i 's#_\(.\*\)\.scss#\1.scss#g'

This command searches in .ts and .tsx files and replaces _styles.scss with styles.scss (removes underscore)

--files-with-matches is an alias to -l = report all the files that match the pattern/text

sed -i = -i means in place, otherwise it just prints the output to the console
\(.\*\) = \ backslash is required for capture group

# = you can do s# instead of s/ or any char for that matter. Useful to change the char if that char is appearing in pattern/replacement text and you don’t want to escape it again and again.

Find Exact Word

rg -w find

would search for find but not for finder for example.