Skip to content

Instantly share code, notes, and snippets.

@jacekbj
Last active August 25, 2021 08:16
Show Gist options
  • Save jacekbj/e4009851e4af2ba33d54e524041d2161 to your computer and use it in GitHub Desktop.
Save jacekbj/e4009851e4af2ba33d54e524041d2161 to your computer and use it in GitHub Desktop.
bash tools

Format input if it's JSON

some-command | jq -R -r '. as $line | try fromjson catch $line'

Run command in a loop with substitution

array=( one two three )
for i in "${array[@]}"; do commaind $i ; done

Run command x times

for run in {1..3}; do command ; done

Voice signal after command finished

command ; say "command finished"

Rename files (requires ZSH)

autoload zmv
# dry run
zmv -n '(**/)(*).andnav' '$1$2.tile
# execute
zmv -n '(**/)(*).andnav' '$1$2.tile
# real-life example
zmv '(**/)(*)hydra(*)' '$1$2minerva$3'

Compare files in two directories

diff -Naur components modal 

Rename .ts files to .tsx:

find . -name "*.ts" -exec rename 's/\.ts$/\.tsx/' '{}' \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment