scripts

My personal collection of scripts
git clone git://src.gearsix.net/scripts
Log | Files | Refs | Atom | README | LICENSE

commit 750c7014272387afd2a187dbd392da9867ba7cc0
parent 9893ec38fe5767063be9478c008e0a5d56096869
Author: gearsix <gearsix@tuta.io>
Date:   Mon, 23 Aug 2021 13:04:40 +0100

Merge branch 'master' of https://notabug.org/gearsix/scripts

Diffstat:
Msrc/backup.sh | 4++--
Msrc/compress-pdf.sh | 2+-
Msrc/cpc.sh | 2+-
Msrc/flac2mp3.sh | 2+-
Dsrc/gfind.sh | 15---------------
Msrc/git-cfg.sh | 4++--
Msrc/git-clone-bulk.sh | 2+-
Msrc/git-pull-all.sh | 2+-
Msrc/gobuild.sh | 6+++---
Asrc/grepf.sh | 15+++++++++++++++
Msrc/mkdcp.sh | 2+-
Msrc/mkdmv.sh | 2+-
Msrc/mkdnvim.sh | 2+-
Msrc/mkdtouch.sh | 2+-
Msrc/pomodoro.sh | 17+++++++++++------
Msrc/preview-md.sh | 6+++---
Msrc/randstr.sh | 2+-
Msrc/shush.sh | 2+-
Msrc/strindex.sh | 4++--
Msrc/while-true.sh | 2+-
Msrc/xopen.sh | 4++--
21 files changed, 52 insertions(+), 47 deletions(-)

diff --git a/src/backup.sh b/src/backup.sh @@ -3,7 +3,7 @@ # description: cp $@ -> $@.bak # e.g.$ backup ~/.bashrc ~/.vimrc -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: 'backup [OPTIONS] FILEPATHS...'" echo "" echo "copy all listed files (in FILEPATHS...) to \$filename.bak" @@ -14,7 +14,7 @@ if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then fi backup=cp -if [ "$1" == "-r" ]; then backup=mv; fi +if [ "$1" = "-r" ]; then backup=mv; fi for f in ${@}; do $backup $f $f.bak; done diff --git a/src/compress-pdf.sh b/src/compress-pdf.sh @@ -4,7 +4,7 @@ # ARGUMENTS: $1 = input file, [$2 = output file (default: compressed.pdf)] # e.g.$: compress-pdf my-pdf.pdf my-pdf-compressed.pdf -if [ -z $1 ] || [ -z $2 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ -z $1 ] || [ -z $2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: compress-pdf [SETTINGS] INPUT [OUTPUT]" echo "" echo "for SETTINGS options, see https://web.mit.edu/ghostscript/www/Ps2pdf.htm#Options" diff --git a/src/cpc.sh b/src/cpc.sh @@ -4,7 +4,7 @@ # # e.g.$ cpc file1.txt file2.txt -if [ -z $1 ] || [ -z $2 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ -z $1 ] || [ -z $2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: cpc INPUT OUTPUT" echo "" echo "copy the contents of the file INPUT to file OUTPUT" diff --git a/src/flac2mp3.sh b/src/flac2mp3.sh @@ -4,7 +4,7 @@ # e.g.$ flac2mp3 ./album # DEPENDENCIES: ffmpeg -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: flac2mp3 DIRECTORY" echo "" echo "use ffmpeg to convert a directory of .flac files to .mp3 files" diff --git a/src/gfind.sh b/src/gfind.sh @@ -1,15 +0,0 @@ -#!/bin/sh -# gfind (grep find) -# description: find files containing string $2 in directory/file $1 -# dependencies: grep -# e.g.$ gfind dogs/ "shades" - -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then - echo "Usage: gfind DIRECTORY EXPRESSION" - echo "" - echo "call grep EXPRESSION on all files in DIRECTORY" - exit -fi - -grep -rnw $1 -e "$2" - diff --git a/src/git-cfg.sh b/src/git-cfg.sh @@ -3,7 +3,7 @@ # description: set git config user.name ($1) & user.email ($2) in current dir, defaults to using --local # ARGUMENTS: -g, --global = "git config --global ..." | -h, --help = prints help -if [[ $1 == "--help" || $1 == "-h" ]]; then +if [[ $1 = "--help" || $1 = "-h" ]]; then echo "Usage: git-cfg [ARGUMENTS] [NAME] [EMAIL]" echo "" echo "shorthand script to set the user.name and user.email values in a git" @@ -16,7 +16,7 @@ if [[ $1 == "--help" || $1 == "-h" ]]; then fi global=0 -if [[ $1 == "--global" || $1 == "-g" ]]; then +if [[ $1 = "--global" || $1 = "-g" ]]; then global=1 shift fi diff --git a/src/git-clone-bulk.sh b/src/git-clone-bulk.sh @@ -3,7 +3,7 @@ # ARGUMENTS: git-clone-bulk repo1 repo2 repo3 ... # DEPENDENCIES: git -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: git-clone-bulk REPO..." echo "" echo "'git clone' multiple repos in one call. REPO should be a list of git repositories to clone" diff --git a/src/git-pull-all.sh b/src/git-pull-all.sh @@ -3,7 +3,7 @@ # description: pull all remote branches to the local repo -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: git-pull-all" echo "" echo "pull all remote branches of repo in callers working directory to local" diff --git a/src/gobuild.sh b/src/gobuild.sh @@ -2,7 +2,7 @@ # DESCRIPTION: build a go pkg for all supported platforms # DEPENDENCIES: go -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: gobuild SRC..." echo "" echo "build a go binary for every platform" @@ -18,8 +18,8 @@ os=(linux windows darwin dragonfly openbsd netbsd freebsd) for a in ${arch[@]}; do for o in ${os[@]}; do - if [[ $a == "arm" || $a == "386" ]]; then - if [[ $o == "darwin" || $o == "dragonfly" ]]; then + if [[ $a = "arm" || $a = "386" ]]; then + if [[ $o = "darwin" || $o = "dragonfly" ]]; then continue fi fi diff --git a/src/grepf.sh b/src/grepf.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# grepf (grep find) +# description: find files containing string $2 in directory/file $1 +# dependencies: grep +# e.g.$ grepf dogs/ "shades" + +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "Usage: grepf DIRECTORY EXPRESSION" + echo "" + echo "call grep EXPRESSION on all files in DIRECTORY" + exit +fi + +grep -rnw $1 -e "$2" + diff --git a/src/mkdcp.sh b/src/mkdcp.sh @@ -3,7 +3,7 @@ # description: make a directory and copy files into it # e.g.$ mkdcp ~/new-dir /tmp/file* -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: mkdcp DIRECTORY FILEPATH..." echo "" echo "mkdir DIRECTORY and cp all listed FILEPATH... entries into it" diff --git a/src/mkdmv.sh b/src/mkdmv.sh @@ -3,7 +3,7 @@ # description: mkdir $1 && mv ($2...$n) 1to it # e.g.$ mkdmv ~/new-dir ~/var/tmp/file* -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: mkdmv DIRECTORY FILEPATH..." echo "" echo "mkdir DIRECTORY and mv all listed FILEPATH... files into it" diff --git a/src/mkdnvim.sh b/src/mkdnvim.sh @@ -3,7 +3,7 @@ # description: makes directory $1 and opens file $2 using nvim # e.g.$ mkdnvim ~/new file #creates ~/new/file and nvim into it -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: mkdedit DIRECTORY FILENAME" echo "" echo "mkdir DIRECTORY and open \$DIRECTORY/\$FILENAME in \$EDITOR" diff --git a/src/mkdtouch.sh b/src/mkdtouch.sh @@ -2,7 +2,7 @@ # description: mkdir $1; touch ${2, ...} # arguments: $1 = dir path to make; $2, ... = filenames to touch -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: mkdtouch DIRECTORY FILEPATH..." echo "" echo "mkdir DIRECTORY and touch listed FILEPATH... into it" diff --git a/src/pomodoro.sh b/src/pomodoro.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "pomdoro" echo "usage: pomodoro [OPTIONS]" echo "" @@ -11,15 +11,20 @@ if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then exit fi -NOTIFY=$NOTIFY +NAME="pomodoro" WORK=25m BREAK=5m -if [ "$1" == "--long" ]; then BREAK=15m; fi +if [ "$1" = "--long" ]; then BREAK=15m; fi -notify-send -t $NOTIFY -a pomodoro "Begin" "Work for 25m. Break for $BREAK.\nRepeat." +notify-send -a pomodoro "Begin" "Work for 25m. Break for $BREAK.\nRepeat." if [ -s $? ]; then echo "notify-send failed, aborting"; fi while [ true ]; do - sleep "$WORK" && notify-send -t $NOTIFY -a pomodoro "Take a break" "You've been working for $WORK, time for a $BREAK break." - sleep "$BREAK" && notify-send -t $NOTIFY -a pomodoro "Back to work" "$BREAK break is over, back to being busy for 25m." + msg="You've been working for $WORK, time for a $BREAK break." + sleep "$WORK" && notify-send -a $NAME "Take a break" $msg + echo "$msg" + + msg="$BREAK break is over, back to being busy for 25m." + sleep "$BREAK" && notify-send -a $NAME "Back to work" $msg + echo "$msg" done diff --git a/src/preview-md.sh b/src/preview-md.sh @@ -1,10 +1,10 @@ #!/bin/sh # preview-md (preview markdown) -# DESCRIPTION: convert a markdown file $1 to html, optional open in a browser (if $2 == --open). Set converter in src (cmark by default). +# DESCRIPTION: convert a markdown file $1 to html, optional open in a browser (if $2 = --open). Set converter in src (cmark by default). # dependencies: cmark # e.g.$ preview-md README.md --open -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: preview-md FILE [OPTIONS]" echo "" echo "convert a Markdown file to HTML using cmark" @@ -22,7 +22,7 @@ if [ -e "$out" ]; then rm -i $out; fi $mdconv "$1" > "$out" if [ $? -eq 0 ]; then echo "succesfully converted to $out" - if [ ! -z $2 ] && [ "$2" == "--open" ] || [ "$2" == "-o" ]; then + if [ ! -z $2 ] && [ "$2" = "--open" ] || [ "$2" = "-o" ]; then xdg-open "$out" &>/dev/null fi else diff --git a/src/randstr.sh b/src/randstr.sh @@ -3,7 +3,7 @@ # description: generate a random string of size $1 (default: 10) # e.g.$ randstr 10 -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: randstr [SIZE]" echo "" echo "print a random string of SIZE length (default: 10)" diff --git a/src/shush.sh b/src/shush.sh @@ -3,7 +3,7 @@ # description: run a terminal command ($@) and send stdout to /dev/null # e.g.$ shush chromium & -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: shush ARGS" echo "" echo "run all commands in ARGS but send stdout to /dev/null, for when a tool is too noisy" diff --git a/src/strindex.sh b/src/strindex.sh @@ -5,7 +5,7 @@ # # NOTES: index returned ranges from 0 - (string length) -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: strindex [OPTIONS] SUBSTRING STRING" echo "" echo "print the starting index of SUBSTRING in STRING" @@ -16,7 +16,7 @@ if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then exit fi -if [[ "$1" == "-r" ]]; then # swap arguments (e.g. strindex "cat on mat" "mat") +if [[ "$1" = "-r" ]]; then # swap arguments (e.g. strindex "cat on mat" "mat") shift x="${1%%$2*}" [[ "$x" = "$1" ]] && echo "-1" || echo "${#x}" diff --git a/src/while-true.sh b/src/while-true.sh @@ -3,7 +3,7 @@ # description: clear terminal, run $1, sleep ($2 || 1), repeat (Ctrl+C to cancel) # e.g.$ while-true "git status" 5 -if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: while-true \"ACTION\" [SLEEP]" echo "" echo "while-true will loop infinitely and repeat ACTION every [SLEEP] seconds." diff --git a/src/xopen.sh b/src/xopen.sh @@ -3,7 +3,7 @@ # description: open file in xserver (doesn't support multiple files at once yet) # ARGUMENTS: -q, --quiet send stdout to /dev/null -if [ -z $1 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then +if [ -z $1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: xopen [OPTIONS] {FILE|URL}..." echo "" echo "Call 'xdg-open' on all listed {FILE|URL}, see 'xdg --help' for more details." @@ -13,7 +13,7 @@ if [ -z $1 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then exit fi -if [ "$1" == "-q" ] || [ "$1" == "--quiet" ]; then +if [ "$1" = "-q" ] || [ "$1" = "--quiet" ]; then shift xdg-open $@ &>/dev/null else