commit 14a66325f7d03abb566a2c47c2a0b984651f53c1
parent 3f6c34cd8ffe65d8166d3b74abbcdcf0af0de2ae
Author: gearsix <gearsix@tuta.io>
Date: Mon, 26 Jul 2021 16:23:39 +0100
started adding -h/--help prints; compress-pdf bugfix; added -q to xopen
Diffstat:
6 files changed, 51 insertions(+), 9 deletions(-)
diff --git a/src/backup.sh b/src/backup.sh
@@ -1,7 +1,14 @@
#!/bin/sh
# backup
-# description: backup $@ to $@.bak
+# description: cp $@ -> $@.bak
# e.g.$ backup ~/.bashrc ~/.vimrc
+if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ echo "Usage: 'backup FILEPATHS...'"
+ echo ""
+ echo "copy all listed files (in FILEPATHS...) to \$filename.bak"
+ exit
+fi
+
for f in ${@}; do cp $f $f.bak; done
diff --git a/src/compress-pdf.sh b/src/compress-pdf.sh
@@ -4,14 +4,17 @@
# 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 ]; then
- echo "usage: compress-pdf dPDFSETTINGS INPUT [OUTPUT]"
- echo "for dPDFSETTINGS see https://web.mit.edu/ghostscript/www/Ps2pdf.htm#Options"
- echo "INPUT and OUTPUT specify the relevent filepaths"
+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"
+ echo "INPUT should provide the filepath of a PDF to compress"
+ echo "OUTPUT should provided the filepath of the compressed PDF (default: ./compressed.pdf)"
fi
-in="$2"
+in="$1"
out="compressed.pdf"
-if [ -e $3 ]; then out="$3"; fi
+if [ -e $2 ]; then out="$2"; fi
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=$1 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$out $in
+
diff --git a/src/cpc.sh b/src/cpc.sh
@@ -4,6 +4,13 @@
#
# e.g.$ cpc file1.txt file2.txt
+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"
+ echo "WARNING: this will overwrite existing contents in file OUTPUT"
+fi
+
touch $2
echo "$(cat $1)" > $2
diff --git a/src/pomodoro.sh b/src/pomodoro.sh
diff --git a/src/while-true.sh b/src/while-true.sh
@@ -1,7 +1,17 @@
#!/bin/sh
# while-true
# description: clear terminal, run $1, sleep ($2 || 1), repeat (Ctrl+C to cancel)
-# e.g.$ while-true "git-status" 5
+# e.g.$ while-true "git status" 5
+
+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."
+ echo "ACTION should be the terminal command to carry out.
+ echo " Note that it needs to be provided inbetween \"\" marks so as not to be read as multiple arguments"
+ echo "SLEEP should provide the number of seconds to sleep for (default: 1)"
+ exit
+fi
while [ true ]; do
clear
diff --git a/src/xopen.sh b/src/xopen.sh
@@ -3,4 +3,19 @@
# description: open file in xserver (doesn't support multiple files at once yet)
# ARGUMENTS: -q, --quiet send stdout to /dev/null
-xdg-open $@ &>/dev/null
+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."
+ echo ""
+ echo "OPTIONS (must be provided before {FILE|URL})"
+ echo " -q, --quiet send stdout to /dev/null because a lot of tools print too much."
+ exit
+fi
+
+if [ "$1" == "-q" ] || [ "$1" == "--quiet" ]; then
+ shift
+ xdg-open $@ &>/dev/null
+else
+ xdg-open $@
+fi