Update.
authorFrancois Fleuret <francois@fleuret.org>
Sat, 31 Mar 2018 21:10:08 +0000 (23:10 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Sat, 31 Mar 2018 21:10:08 +0000 (23:10 +0200)
bashrc

diff --git a/bashrc b/bashrc
index 20cb77d..b2b3e51 100644 (file)
--- a/bashrc
+++ b/bashrc
@@ -585,11 +585,53 @@ function checkgw () {
 # Show the most recent files, no scroll
 
 function lr () {
-    HEIGHT=$(stty size | awk '{print $1}')
-    WIDTH=$(stty size | awk '{print $2}')
-    \ls -goth --time-style="+%Y %b %d %H:%M" "$@" | \
-        head -$((HEIGHT-2)) | \
-        cut -b1-${WIDTH}
+    TERM_SIZE=($(stty size))
+    \ls -goth --time-style="+${VT_GREEN_FG}%Y %b %d %H:%M${VT_RESET}" "$@" | \
+        head -$((TERM_SIZE[0]-2)) | cut -b1-${TERM_SIZE[1]}
+}
+
+######################################################################
+
+reduce-pdf () {
+
+    # /screen selects low-resolution output
+    # /ebook selects medium-resolution output
+    # /printer selects "Print Optimized" setting.
+    # /prepress selects "Prepress Optimized" setting.
+
+    quality="printer"
+
+    while [[ "$1" ]]
+    do
+        if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]
+        then
+            echo "$0 [<file.pdf>|--quality <screen|ebook|printer|prepress>] ..."
+            return 0
+
+        elif [[ "$1" == "--quality" ]]
+        then
+            shift
+            quality="$1"
+
+        elif [[ -f "$1" ]]
+        then
+            result="$(basename "$1" .pdf)-${quality}.pdf"
+            echo -n "Generating ${result} with quality ${quality} ... "
+            gs -sDEVICE=pdfwrite \
+               -dCompatibilityLevel=1.4 \
+               -dPDFSETTINGS=/${quality} \
+               -dColorConversionStrategy=/LeaveColorUnchanged \
+               -dNOPAUSE -dQUIET -dBATCH \
+               -sOutputFile="${result}" "$1"
+            echo "done."
+            ls -hl "$1" "${result}"
+
+        else
+            echo "Cannot fine $1"
+
+        fi
+        shift
+    done
 }
 
 ######################################################################