Initial commit.
[scripts.git] / bashrc
diff --git a/bashrc b/bashrc
index adef316..5066b31 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?
 
@@ -92,6 +92,10 @@ export LESS_TERMCAP_ue=${VT_RESET}
 export LESS_TERMCAP_md=${VT_BLUE_FG}${VT_BOLD}
 export LESS_TERMCAP_me=${VT_RESET}
 
+# I do not like to clutter my home with history files
+
+export LESSHISTFILE=/dev/null
+
 # export LESS_TERMCAP_md=$'\e[1;34;40m'
 
 # This prevents ^S from freezing the shell
@@ -117,12 +121,21 @@ alias pd=pushd
 alias val='valgrind --leak-check=full --show-reachable=yes --db-attach=yes '
 
 alias s='screen -d -R -U && clear'
+alias p='feh --force-aliasing -d --full-screen --auto-zoom'
 
 function nh () {
     export HISTFILE=/dev/null
     unalias cd
 }
 
+function select-tz () {
+    # Select a value for TZ
+    TMP=$(mktemp /tmp/select-tz.XXXXXX)
+    selector -o "${TMP}" <(grep -v ^# /usr/share/zoneinfo/zone.tab  | awk '{print $3}' | sort -u)
+    cat "${TMP}"
+    \rm -f "${TMP}"
+}
+
 function ding () {
     if [[ $1 ]] && which winshepherd.sh; then
         play -q ~/local/sounds/deskbell.wav &
@@ -163,7 +176,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
@@ -242,6 +255,44 @@ function bak () {
     done
 }
 
+function scan () {
+    n=1
+
+    while [[ -f "${HOME}/scan-${n}.jpg" ]]; do
+        n=$((n+1))
+    done
+
+    while [[ "$1" ]]; do
+        if [[ "$1" == "color" ]]; then
+            OPTS+=" --mode Color"
+        elif [[ "$1" == "gray" ]]; then
+            OPTS+=" --mode Gray"
+        elif [[ "$1" == "a4crop" ]]; then
+            OPTS+=" -l 5 -t 0 -x 200 -y 290"
+        else
+            echo "Unknown argument \`$1'"
+        fi
+        shift
+    done
+
+    echo "**"
+    echo "** Scanning to ${HOME}/scan-${n}.jpg"
+    echo "**"
+
+    SCANNER=$(scanimage -L | grep "Canon LiDE 60" | sed -e "s/^.*\`\(.*\)'.*$/\1/")
+
+    scanimage -d ${SCANNER} \
+              --format=pnm \
+              --mode=color \
+              --depth=8 \
+              -v \
+              --resolution=300 \
+              ${OPTS} | \
+        convert -rotate 180 - "${HOME}/scan-${n}.jpg"
+
+    echo "** Done".
+}
+
 # A password generator
 
 function genpw () {
@@ -326,9 +377,10 @@ function cdt () {
 }
 
 alias t='cd /tmp'
+alias a='cd /tmp/at'
 
 function trash () {
-    TRASH=$(date +/tmp/trash-%Y-%b-%d-%Hh)
+    TRASH=$(date +/tmp/trash-${USER}-%Y-%b-%d-%Hh)
     LINK=/tmp/trash
 
     mkdir -p ${TRASH}
@@ -367,11 +419,9 @@ function pho () {
 ## A version of date that shows the time at home if TZ is set
 
 function dt () {
-    echo "Local: $(date)"
-    if [[ ${TZ} ]]; then
-        local TZ=$(cat /etc/timezone)
-        echo "Home:  $(date)"
-    fi
+    echo "Local - $(date)"
+    unset TZ
+    echo "Home  - $(date)"
 }
 
 ######################################################################
@@ -522,8 +572,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 +668,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 +684,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
@@ -701,7 +751,9 @@ function mvtoconfig () {
 export PS1
 
 if [[ "${CONSOLE}" == "yes" ]]; then
+
     PS1=""
+
 else
 
     # If the login is a standard one (as specified in
@@ -736,6 +788,8 @@ else
 
 fi
 
+PS1="${PSCUE}${PS1}"
+
 ######################################################################
 # This implements a local history. If we are in a directory containing
 # a writable local history file, we add the last line of the global
@@ -761,7 +815,7 @@ function keep_local_history () {
 PS1="\[${VT_WHITE_BG}\]\${LOCAL_HISTORY_HINT}\[${VT_RESET}\]${PS1}"
 
 ######################################################################
-# Switch off the history
+# Show the history path if it is unusual
 
 function histfile_cue () {
     if [[ ! "${HISTFILE}" == "${HOME}/.bash_history" ]]; then
@@ -818,11 +872,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 +884,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
 
@@ -865,6 +936,11 @@ function lsn () {
 ######################################################################
 
 function prompt_command () {
+    # if [[ ! "${CORE_CHECK_PWD}" == ${PWD} ]] && [[ $(find . -maxdepth 1 -name "core__*" -print -quit) ]]; then
+
+    [[ "${CORE_CHECK_PWD}" == ${PWD} ]] || find . -maxdepth 1 -name "core__*"
+    CORE_CHECK_PWD=${PWD}
+
     # if [[ $(umask) != 0022 ]]; then
         # echo "Umask changed to $(umask)"
     # fi
@@ -885,8 +961,6 @@ 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}"
-fi
+[[ ${TZ} ]] && echo "${VT_BLUE_FG}Time zone is ${TZ}.${VT_RESET}"
 
 ######################################################################