Added another ISO file format check in the burn command.
[scripts.git] / bashrc
diff --git a/bashrc b/bashrc
index ad11407..6310a94 100644 (file)
--- a/bashrc
+++ b/bashrc
@@ -192,10 +192,16 @@ function rl () {
             pdflatex "${FILEBASE}"
             pdflatex "${FILEBASE}"
 
-            if [[ "$1" == "--view" ]]; then
-                xpdf "${FILEBASE}.pdf"
-            elif [[ "$1" == "--print" ]]; then
-                lpr "${FILEBASE}.pdf"
+            if [[ "$1" ]]; then
+                if [[ "$1" == "-v" ]] || [[ "$1" == "--view" ]]; then
+                    xpdf "${FILEBASE}.pdf"
+                elif [[ "$1" == "-p" ]] || [[ "$1" == "--print" ]]; then
+                    lpr "${FILEBASE}.pdf"
+                else
+                    echo "Usage: rl [-v|--view] [-p|--print]" >&2
+                    echo "Unknown option $1" >&2
+                    return 1
+                fi
             fi
 
         else
@@ -237,7 +243,6 @@ function ua () {
     while [[ "$1" ]]; do
 
         case "$1" in
-
             *.tgz|*.tar.gz|*.tbz|*.tar.bz2)
                 tar xvf "$1"
                 ;;
@@ -321,25 +326,10 @@ function trash () {
     echo "Trashed $@"
 }
 
-# alias trash=trash.sh
-
 function mmsget () {
     mplayer "$1" -dumpstream -dumpfile $(basename "$1")
 }
 
-function quicktex () {
-    if [[ $1 ]]; then
-        MAIN=$1
-    else
-        MAIN=$(\ls -t *.tex | head -1 | sed -r -e 's/\.tex//')
-    fi
-    pdflatex ${MAIN}
-    bibtex ${MAIN}
-    pdflatex ${MAIN}
-    pdflatex ${MAIN}
-    xpdf ${MAIN}.pdf
-}
-
 ######################################################################
 # http://www.reddit.com/r/linux/comments/akt3j/a_functional_programming_style_map_function_for/
 
@@ -384,18 +374,6 @@ function pho () {
     \rm ${TEMP}
 }
 
-# function rotjpeg () {
-# if [ "$1" == "90" ] || [ "$1" == "180" ] || [ "$1" == "270" ]; then
-# TEMP=$(mktemp /tmp/rotjpeg.XXXXXX)
-# echo jpegtran -rotate "$1" -copy all $2 > ${TEMP}
-# echo cp $2 ${2/jpg/}original.jpg
-# echo cp ${TEMP} $2
-# rm ${TEMP}
-# else
-# echo "Can not rotate with an angle of "$1" degrees."
-# fi
-# }
-
 ######################################################################
 ## A version of date that shows the time at home if TZ is set
 
@@ -419,6 +397,23 @@ function dt () {
 [[ ${NETUP_HISTORY} ]] || NETUP_HISTORY="${HOME}/.netup_history"
 
 function netup () {
+    WIFI_INTERFACE=wlan0
+
+    if [[ $1 == "--scan" ]]; then
+        if [[ ! $(\ifconfig -s | grep ${WIFI_INTERFACE}) ]]; then
+            sudo ifconfig ${WIFI_INTERFACE} up
+            UPPED_WIFI=1
+        fi
+
+        sudo iwlist ${WIFI_INTERFACE} scan | \grep -E 'ESS|Quali|Encry' | sed -e 's/^[ \t]*//'
+
+        if [[ ${UPPED_WIFI} ]]; then
+            sudo ifconfig ${WIFI_INTERFACE} down
+        fi
+
+        return 0
+    fi
+
     if [[ $(\ifconfig -s | grep -v ^"(Iface|lo) ") ]]; then
         echo "There is already interface(s) up." >&2
         return 1
@@ -517,7 +512,7 @@ function lr () {
 # cd and ls into a directory
 # [from http://www.oreillynet.com/onlamp/blog/2007/01/whats_in_your_bash_history.html]
 
-function c () { cd "$@" && lr; }
+function c () { cd "$@" && lr; }
 
 ######################################################################
 # You can change the xterm background color on the fly!
@@ -559,7 +554,7 @@ function burn () {
     if [[ ! "$1" ]]; then
         echo "burn <iso name | dirname>" >&2
     elif [[ -f "$1" ]]; then
-        if [[ $(file "$1" | grep "ISO 9660") ]]; then
+        if [[ $(file "$1" | grep "ISO 9660") ]] || [[ $(file "$1" | grep "UDF filesystem data") ]]; then
             wodim -eject -v dev=${DEVICE} "$1"
         else
             echo "Unknown type of $1" >&2
@@ -765,12 +760,13 @@ function git-fm () {
     echo "Visited ${NB_SUBDIR} directories."
 }
 
+# Update all the directories provided as argument in their respective
+# versionning systems (SVN and GIT for now)
+
 function vcup () {
     if [[ "$1" ]]; then
-        CURRENT=${PWD}
         while [[ "$1" ]]; do
-            cd ${CURRENT}
-            cd $1
+            pushd > /dev/null "$1"
             if [[ -d ".git" ]]; then
                 echo "${PWD} is under GIT"
                 git pull
@@ -778,8 +774,9 @@ function vcup () {
                 echo "${PWD} is under SVN"
                 svn update
             else
-                echo "No known versioning system."
+                echo "No known versioning system here."
             fi
+            popd > /dev/null 
             shift
         done
         cd ${CURRENT}
@@ -895,6 +892,26 @@ function histfile_cue () {
 
 PS1="\[${VT_YELLOW_BG}\]\${HISTORY_CUE}\[${VT_RESET}\]${PS1}"
 
+######################################################################
+
+# parse_git_branch () {
+  # git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
+# }
+
+# parse_git_tag () {
+  # git describe --tags 2> /dev/null
+# }
+
+# parse_git_branch_or_tag() {
+  # local OUT="$(parse_git_branch)"
+  # if [ "$OUT" == " ((no branch))" ]; then
+    # OUT="($(parse_git_tag))";
+  # fi
+  # echo $OUT
+# }
+
+# PS1="${PS1}\$(parse_git_branch_or_tag)"
+
 ######################################################################
 # The dus command is available on my web site
 #
@@ -938,18 +955,47 @@ function selector-printer () {
 # the current directory
 
 function lsn () {
-    LSN_MEMORY=".lsn-mem"
-    if  [[ $1 == "--mem" ]]; then
-        \ls -p > ${LSN_MEMORY}
+    LSN_MEMORY=".lsn-state"
+
+    if  [[ $1 == "--mem" ]] || [[ "$1" == "-m" ]]; then
+
+        \ls -pa | sort > ${LSN_MEMORY}
+        echo "State updated." >&2
+
+    elif [[ $1 == "+" ]]; then
+
+        shift
+
+        TMP=$(mktemp /tmp/lsn.XXXXXX)
+        \ls -d $* > ${TMP}
+        cat ${LSN_MEMORY} >> ${TMP}
+        sort -u ${TMP} > ${LSN_MEMORY}
+        \rm ${TMP}
+
+    elif [[ -n "$1" ]]; then
+
+        echo "lsn [--mem|-m] [+ <file> ...]" >&2
+        return 1
+
     else
+
         if [[ -f ${LSN_MEMORY} ]]; then
-            comm -1 -3 ${LSN_MEMORY} <(\ls -p)
-            comm -2 -3 ${LSN_MEMORY} <(\ls -p) | while read line; do
-                echo "${VT_RED_FG}${VT_BOLD}${line}${VT_RESET} (missing)"
-            done
+            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${VT_RESET}"
+            else
+                \comm -1 -3 ${LSN_MEMORY} ${TMP}
+                \comm -2 -3 ${LSN_MEMORY} ${TMP} | while read line; do
+                    echo "${VT_RED_FG}${VT_BOLD}${line}${VT_RESET} (missing)"
+                done
+            fi
+            \rm ${TMP}
         else
-            echo "No lsn memory here." >&2
+            echo "No lsn state here." >&2
+            return 1
         fi
+
     fi
 }