commit d35e7723d9c37079d1755eddd4007b3b0baeb5b8
parent eb3e76ad3bb53cf1c24edc9d757806a7654b001a
Author: gearsix <gearsix@tuta.io>
Date: Mon, 26 Jul 2021 16:54:04 +0100
finished adding -h/--help prints
Diffstat:
15 files changed, 119 insertions(+), 9 deletions(-)
diff --git a/src/compress-pdf.sh b/src/compress-pdf.sh
@@ -10,6 +10,7 @@ if [ -z $1 ] || [ -z $2 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo "for SETTINGS options, see https://web.mit.edu/ghostscript/www/Ps2pdf.htm#Options"
echo "INPUT should provide the filepath of a PDF to compress"
echo "OUTPUT should provided the filepath of the compressed PDF (default: ./compressed.pdf)"
+ exit
fi
in="$1"
diff --git a/src/cpc.sh b/src/cpc.sh
@@ -9,6 +9,7 @@ if [ -z $1 ] || [ -z $2 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo ""
echo "copy the contents of the file INPUT to file OUTPUT"
echo "WARNING: this will overwrite existing contents in file OUTPUT"
+ exit
fi
touch $2
diff --git a/src/flac2mp3.sh b/src/flac2mp3.sh
@@ -4,6 +4,13 @@
# e.g.$ flac2mp3 ./album
# DEPENDENCIES: ffmpeg
+if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ echo "Usage: flac2mp3 DIRECTORY"
+ echo ""
+ echo "use ffmpeg to convert a directory of .flac files to .mp3 files"
+ exit
+fi
+
for file in $1/*.flac; do
ffmpeg -i "$file" -qscale:a 0 "${file[@]/%flac/mp3}"
done
diff --git a/src/gfind.sh b/src/gfind.sh
@@ -4,5 +4,18 @@
# dependencies: grep
# e.g.$ gfind dogs/ "shades"
-grep -rnw $1 -e "$2" #recursive, print line #, match whole word
+if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ echo "Usage: gfind [OPTIONS] DIRECTORY EXPRESSION"
+ echo ""
+ echo "call grep EXPRESSION on all files in DIRECTORY"
+ echo ""
+ echo "OPTIONS"
+ echo " -r recursively search DIRECTORY"
+ exit
+fi
+
+ARGS="-nw" # print line #, match whole word
+if [ "$1" == "-r" ]; then ARGS="-rnw"; fi # recursive
+
+grep $ARGS $1 -e "$2"
diff --git a/src/git-clone-bulk.sh b/src/git-clone-bulk.sh
@@ -3,4 +3,12 @@
# ARGUMENTS: git-clone-bulk repo1 repo2 repo3 ...
# DEPENDENCIES: git
+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"
+ echo "bash expansion is useful here: 'git-clone-bulk github.com/user/{repo1,repo2}"
+ exit
+fi
+
for repo in $@; do git clone $repo; done
diff --git a/src/git-pull-all.sh b/src/git-pull-all.sh
@@ -2,6 +2,14 @@
# src: https://gist.github.com/grimzy/a1d3aae40412634df29cf86bb74a6f72
# description: pull all remote branches to the local repo
+
+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"
+ exit
+fi
+
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
diff --git a/src/gobuild.sh b/src/gobuild.sh
@@ -2,6 +2,15 @@
# DESCRIPTION: build a go pkg for all supported platforms
# DEPENDENCIES: go
+if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ echo "Usage: gobuild SRC..."
+ echo ""
+ echo "build a go binary for every platform"
+ echo "this will set the GOARCH and GOOS variables and run 'go build'"
+ echo "for when you want to build a binary to distribute for as many platforms as possible"
+ exit
+fi
+
name=$1
src=$2
arch=(amd64 386 arm)
diff --git a/src/mkdcp.sh b/src/mkdcp.sh
@@ -3,6 +3,13 @@
# description: make a directory and copy files into it
# e.g.$ mkdcp ~/new-dir /tmp/file*
+if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ echo "Usage: mkdcp DIRECTORY FILEPATH..."
+ echo ""
+ echo "mkdir DIRECTORY and cp all listed FILEPATH... entries into it"
+ exit
+fi
+
#mkdir $1
dir=$1;
mkdir -p $dir
diff --git a/src/mkdmv.sh b/src/mkdmv.sh
@@ -3,6 +3,13 @@
# description: mkdir $1 && mv ($2...$n) 1to it
# e.g.$ mkdmv ~/new-dir ~/var/tmp/file*
+if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ echo "Usage: mkdmv DIRECTORY FILEPATH..."
+ echo ""
+ echo "mkdir DIRECTORY and mv all listed FILEPATH... files into it"
+ exit
+fi
+
#mkdir $1
dir="$1";
mkdir -p "$dir"
diff --git a/src/mkdnvim.sh b/src/mkdnvim.sh
@@ -3,8 +3,15 @@
# 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
+ echo "Usage: mkdedit DIRECTORY FILENAME"
+ echo ""
+ echo "mkdir DIRECTORY and open \$DIRECTORY/\$FILENAME in \$EDITOR"
+ exit
+fi
+
mkdir $1;
cd $1;
touch $2;
-nvim $2;
+$EDITOR $2;
diff --git a/src/mkdtouch.sh b/src/mkdtouch.sh
@@ -2,6 +2,13 @@
# description: mkdir $1; touch ${2, ...}
# arguments: $1 = dir path to make; $2, ... = filenames to touch
+if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ echo "Usage: mkdtouch DIRECTORY FILEPATH..."
+ echo ""
+ echo "mkdir DIRECTORY and touch listed FILEPATH... into it"
+ exit
+fi
+
mkdir $1
shift
touch $@
diff --git a/src/preview-md.sh b/src/preview-md.sh
@@ -4,6 +4,17 @@
# dependencies: cmark
# e.g.$ preview-md README.md --open
+if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ echo "Usage: preview-md FILE [OPTIONS]"
+ echo ""
+ echo "convert a Markdown file to HTML using cmark"
+ echo "the generated file will have the same filename as FILE, where the extension is replaced with .html"
+ echo ""
+ echo "OPTIONS"
+ echo " -o, --open open the output file (using xdg-open) when finished"
+ exit
+fi
+
mdconv="cmark"
out=$(echo "$1" | sed "s/md/html/")
@@ -11,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,6 +3,13 @@
# description: generate a random string of size $1 (default: 10)
# e.g.$ randstr 10
+if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ echo "Usage: randstr [SIZE]"
+ echo ""
+ echo "print a random string of SIZE length (default: 10)"
+ exit
+fi
+
len=10
if [ $1 ]; then len=$1; fi
diff --git a/src/shh.sh b/src/shh.sh
@@ -3,6 +3,13 @@
# description: run a terminal command ($@) and send stdout to /dev/null
# e.g.$ shh chromium &
+if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ echo "Usage: quiet ARGS"
+ echo ""
+ echo "run all commands in ARGS but send stdout to /dev/null, for when a tool is too noisy"
+ exit
+fi
+
for bin in $@; do
$bin &>/dev/null
done;
diff --git a/src/strindex.sh b/src/strindex.sh
@@ -5,13 +5,23 @@
#
# NOTES: index returned ranges from 0 - (string length)
-#swaps argument (strindex "cat on mat" "mat")
-if [[ -z $3 && $3 == "-r" ]]; then
+if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ echo "Usage: strindex [OPTIONS] SUBSTRING STRING"
+ echo ""
+ echo "print the starting index of SUBSTRING in STRING"
+ echo "-1 will be printed if SUBSTRING could not be found"
+ echo ""
+ echo "OPTIONS (must be provided before SUBSTRING STRING)"
+ echo " -r reverse provided SUBSTRING and STRING order"
+ exit
+fi
+
+if [[ "$1" == "-r" ]]; then # swap arguments (e.g. strindex "cat on mat" "mat")
+ shift
x="${1%%$2*}"
- [[ "$x" = "$1" ]] && echo "ERROR! strindex(): Could not find $2 in $1" || echo "${#x}"
-#standard usage (see e.g.$)
-else
+ [[ "$x" = "$1" ]] && echo "-1" || echo "${#x}"
+else #standard usage (see e.g.$)
x="${2%%$1*}"
- [[ "$x" = "$2" ]] && echo "ERROR! strindex(): could not find $1 in $2" || echo "${#x}"
+ [[ "$x" = "$2" ]] && echo "-1" || echo "${#x}"
fi