Various updates.
authorFrancois Fleuret <francois@fleuret.org>
Fri, 2 Oct 2015 20:05:21 +0000 (22:05 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Fri, 2 Oct 2015 20:05:21 +0000 (22:05 +0200)
bashrc

diff --git a/bashrc b/bashrc
index adef316..4e2a151 100644 (file)
--- a/bashrc
+++ b/bashrc
@@ -52,7 +52,7 @@ shopt -s histappend
 
 # Remove the annoying beeps in console
 
-setterm -blength 0
+setterm -blength 0
 
 # || setterm --blength 0 # Seriously?
 
@@ -163,7 +163,7 @@ function latexdiff () {
     wdiff -n \
         -w $'\033[30;41m' -x $'\033[0m' \
         -y $'\033[30;42m' -z $'\033[0m' \
-        $*
+        "$@"
 }
 
 # Looks for the most recent .log and pdflatex + bibtex the
@@ -522,8 +522,8 @@ KEPT_COMMANDS=${HOME}/.kept_bash_commands
 function keep () {
     if [[ ${KEPT_COMMANDS} ]]; then
         TOKEEP=$(mktemp /tmp/keep.XXXXXX)
-        if [[ "$*" ]]; then
-            echo "$*" > ${TOKEEP}
+        if [[ "$@" ]]; then
+            echo "$@" > ${TOKEEP}
         else
             selector -b -i -d -l ${HISTSIZE} -o "${TOKEEP}" <(history)
         fi
@@ -618,7 +618,7 @@ function ripdvd () {
     mkdir -p ${HOME}/dvds
 
     cd ${HOME}/dvds
-    time dvdbackup -i ${DVD_DEVICE} -v -M $* && eject
+    time dvdbackup -i ${DVD_DEVICE} -v -M "$@" && eject
 }
 
 alias ripcd=abcde
@@ -634,7 +634,7 @@ function mksmall () {
         shift
     fi
 
-    [[ "${PARAMS}" ]] || PARAMS="-geometry 800x600"
+    [[ "${PARAMS}" ]] || PARAMS="-geometry 1280x1024"
 
     # Auto-orient does not seem to work at all, hence the ugly hack
     # with exif below
@@ -818,11 +818,11 @@ function selector-printer () {
 # the current directory
 
 function lsn () {
-    LSN_MEMORY=".lsn-state"
+    [[ "${LSN_STATE_FILE}" ]] || LSN_STATE_FILE=".lsn-state"
 
     if  [[ $1 == "--mem" ]] || [[ "$1" == "-m" ]]; then
 
-        \ls -pa | sort > ${LSN_MEMORY}
+        \ls -pa | sort > "${LSN_STATE_FILE}"
         echo "State updated." >&2
 
     elif [[ $1 == "+" ]]; then
@@ -830,32 +830,49 @@ function lsn () {
         shift
 
         TMP=$(mktemp /tmp/lsn.XXXXXX)
-        \ls -d $* > ${TMP}
-        cat ${LSN_MEMORY} >> ${TMP}
-        sort -u ${TMP} > ${LSN_MEMORY}
+        \ls -d "$@" > ${TMP}
+        cat "${LSN_STATE_FILE}" >> ${TMP}
+        sort ${TMP} | uniq -u > "${LSN_STATE_FILE}"
         \rm ${TMP}
 
     elif [[ "$1" ]]; then
+        cat >&2 <<EOF
+lsn [--help|-h] [--mem|-m] [+ <file> ...]
 
-        echo "lsn [--mem|-m] [+ <file> ...]" >&2
-        return 1
+Where
+
+  --help|-h
+     prints this help
+
+  --mem|-m
+     stores the current state of the directory
+
+  + <file> [<file> ...]
+     switches the presence/absence of the indicated files in the
+     stored state
+
+EOF
+        if [[ ! "$1" == "-h" ]] && [[ ! "$1" == "--help" ]]; then
+            echo >&2 "Unknown option \`\`$1''."
+            return 1
+        fi
 
     else
 
-        if [[ -f ${LSN_MEMORY} ]]; then
+        if [[ -f "${LSN_STATE_FILE}" ]]; then
             TMP=$(mktemp /tmp/lsn.XXXXXX)
             \ls -pa | sort > ${TMP}
-            if diff > /dev/null ${TMP} ${LSN_MEMORY}; then
-                echo "${VT_GREEN_FG}${VT_BOLD}No change (since $(date +"%b %d, %Y" -r ${LSN_MEMORY}))${VT_RESET}"
+            if diff > /dev/null ${TMP} "${LSN_STATE_FILE}"; then
+                echo "${VT_GREEN_FG}${VT_BOLD}No change (since $(date +"%b %d, %Y" -r "${LSN_STATE_FILE}"))${VT_RESET}"
             else
-                \comm -1 -3 ${LSN_MEMORY} ${TMP}
-                \comm -2 -3 ${LSN_MEMORY} ${TMP} | while read line; do
+                \comm -1 -3 "${LSN_STATE_FILE}" ${TMP}
+                \comm -2 -3 "${LSN_STATE_FILE}" ${TMP} | while read line; do
                     echo "${VT_RED_FG}${VT_BOLD}${line}${VT_RESET} (missing)"
                 done
             fi
             \rm ${TMP}
         else
-            echo "No lsn state here." >&2
+            echo "${VT_RED_FG}${VT_BOLD}No lsn state here.${VT_RESET}" >&2
             return 1
         fi
 
@@ -886,7 +903,7 @@ PROMPT_COMMAND="prompt_command"
 # Displaying the timezone if it is set
 
 if [[ ${TZ} ]]; then
-    echo "${VT_BOLD}${VT_BLUE_FG}Time zone is ${TZ}.${VT_RESET}"
+    echo "${VT_BLUE_FG}Time zone is ${TZ}.${VT_RESET}"
 fi
 
 ######################################################################