From 6a45dbe664eebcb3050d0c3dfe9856f7c5815aca Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sun, 21 Nov 2010 16:19:53 +0100 Subject: [PATCH] Fixed multiple bugs related to spaces in filenames. --- archivepics.sh | 2 +- bashrc | 21 +++++++++++----- hotspot.sh | 68 +++++++++++++++++++++++++------------------------- html2text.sh | 4 +-- print.sh | 37 ++++++++++++++++----------- trash.sh | 4 +-- viewer.sh | 46 +++++++++++++++++----------------- 7 files changed, 98 insertions(+), 84 deletions(-) diff --git a/archivepics.sh b/archivepics.sh index 82f3506..40ad62d 100755 --- a/archivepics.sh +++ b/archivepics.sh @@ -34,7 +34,7 @@ # exit 0 # fi -export ARCHIVED_PICS="$*" +export ARCHIVED_PICS="$@" set -e diff --git a/bashrc b/bashrc index 30a4995..ac6d696 100644 --- a/bashrc +++ b/bashrc @@ -109,12 +109,14 @@ if [ -e "${HOME}/.dircolors" ]; then # alias ll='ls --color -lth' alias lt='ls --color -gohtr --time-style="+%Y %b %d %H:%M"' alias ll='ls --color -goh --time-style="+%Y %b %d %H:%M"' + alias lll='ls --color -lth' alias l='ls --color -I "*~" -I "*.o"' alias less='less -R' else # alias ll='ls -lth' alias lt='ls -gohtr --time-style="+%Y %b %d %H:%M"' alias ll='ls -goh --time-style="+%Y %b %d %H:%M"' + alias lll='ls -lth' alias l='ls -I "*~" -I "*.o"' fi @@ -134,7 +136,7 @@ export FIGNORE="CVS" function fn () { name=$1 shift - find $* -name "*${name}*"; + find "$@" -name "*${name}*"; } # Create a dir and cd there @@ -147,8 +149,14 @@ function mcd () { # Capture the screen in a dated png function cap () { - name="capture-$(date +%s).png" + if [[ $2 ]]; then + name=$2 + else + name="capture-$(date +%s).png" + fi + echo "Waiting $1 s and saving to ${name}." [[ $1 ]] && sleep $1 + echo "Please click on the window to capture." xwd | convert - ${name} \ls -l ${name} } @@ -206,7 +214,7 @@ function map () { function pho () { PHO_BIN=/usr/bin/pho TEMP=$(mktemp /tmp/pho.XXXXXXX) - ${PHO_BIN} $* | tee ${TEMP} + ${PHO_BIN} "$@" | tee ${TEMP} PHO_NOTE_1=$(grep ^"Note 1: " ${TEMP} | sed -e "s/^[^:]*: //") PHO_NOTE_2=$(grep ^"Note 2: " ${TEMP} | sed -e "s/^[^:]*: //") PHO_NOTE_3=$(grep ^"Note 3: " ${TEMP} | sed -e "s/^[^:]*: //") @@ -254,7 +262,7 @@ function ifup () { echo "${VT_BOLD}${VT_GREEN_FG}This is the bash function ifup from .bashrc${VT_RESET}" if [[ "$1" == "-s" ]]; then chosen_ifup=$(mktemp /tmp/chosen_ifup.XXXXXX) - selector -o ${chosen_ifup} <(cat ${IFUPRC} | sort | uniq) + selector -i -d -o ${chosen_ifup} ${IFUPRC} ARGS=$(cat ${chosen_ifup}) rm -f ${chosen_ifup} echo ${ARGS} >> ${IFUPRC} @@ -306,8 +314,9 @@ function checkgw () { 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} - # \ls -lth $* | head -$((HEIGHT-2)) | cut -b1-${WIDTH} + \ls -goth --time-style="+%Y %b %d %H:%M" "$@" | \ + head -$((HEIGHT-2)) | \ + cut -b1-${WIDTH} } ###################################################################### diff --git a/hotspot.sh b/hotspot.sh index e3cac28..adcebb9 100755 --- a/hotspot.sh +++ b/hotspot.sh @@ -81,8 +81,8 @@ function scan () { -e "s/Quality=\([0-9]*\).*$/QUALITY,\1/" \ -e "s/Encryption key:/ENCRYPTION,/" | \ awk 'BEGIN { FS="," } - { - if($1 == "ESSID") { essid=$2 } + { + if($1 == "ESSID") { essid=$2 } else if($1 == "AP") { ap=$2 } else if($1 == "QUALITY") { quality=$2; } else if($1 == "ENCRYPTION") { @@ -258,6 +258,8 @@ if [[ $1 == "-k" ]]; then exit 1 fi +trap cleanup-before-quit EXIT + stty_state=$(stty -g) trap sigint-handler SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM @@ -295,58 +297,56 @@ while [[ ${cont} == 1 ]]; do ;; "") - process-key "down" - ;; + process-key "down" + ;; "") - process-key "up" - ;; + process-key "up" + ;; "") #$'\033'") - current_keymap=escape - ;; + current_keymap=escape + ;; *) - ;; - esac - ;; + ;; + esac + ;; - escape) ################################################## - case ${CHAR} in - "$'\033'") + escape) ################################################## + case ${CHAR} in + "$'\033'") process-key "esc-esc" ;; - "[") + "[") current_keymap=cursor ;; - *) + *) current_keymap=default ;; - esac - ;; + esac + ;; - cursor) ################################################## + cursor) ################################################## - current_keymap=default + current_keymap=default - case ${CHAR} in - A) + case ${CHAR} in + A) process-key "up" ;; - B) + B) process-key "down" ;; - *) - ;; - esac - ;; - *) - echo "Unknown keymap. This is an internal and weird bug." - cont=0 - ;; - esac + ;; + esac + ;; - done + *) + echo "Unknown keymap. This is an internal and weird bug." + cont=0 + ;; + esac - cleanup-before-quit +done diff --git a/html2text.sh b/html2text.sh index 8c29b10..dd9dd0a 100755 --- a/html2text.sh +++ b/html2text.sh @@ -12,9 +12,9 @@ set -e echo "(From html)" +echo elinks -no-numbering -no-references -dump -dump-width 80 -dump-charset utf-8 | \ sed -e "s/\[IMG\]//g" -e "s/^[ \t]*$//" -e "s/^ //" | \ awk '/^$/{ if (! blank++) print; next } { blank=0; print }' - # | \ - # sed -e "s/^ *//" + diff --git a/print.sh b/print.sh index fc88668..c3815f4 100755 --- a/print.sh +++ b/print.sh @@ -30,7 +30,13 @@ tmp=$(mktemp /tmp/print.ps.XXXXXX) opts="" printing_cmd="lpr" -for arg in $*; do +function cleanup-before-exit () { + rm ${tmp} +} + +trap cleanup-before-exit EXIT + +for arg in "$@"; do if [ "${arg}" == "-h" ] || [ "${arg}" == "--help" ]; then @@ -50,7 +56,6 @@ for arg in $*; do echo "Contact " echo "Version \$Id: print.sh,v 1.19 2006-11-10 15:53:23 fleuret Exp $" - \rm ${tmp} exit 0 elif [[ ${arg} == "-"* ]]; then @@ -63,42 +68,47 @@ for arg in $*; do # else, it is a filename to print - if [ -e ${arg} ]; then + if [ -e "${arg}" ]; then - TYPE=$(file -L ${arg}) + TYPE=$(file -L "${arg}") noprint="" case $TYPE in *"image data"*) - convert ${arg} ps:${tmp} + convert "${arg}" ps:${tmp} ;; *"TeX DVI"*) - dvips -o ${tmp} ${arg} + dvips -o ${tmp} "${arg}" ;; *"FIG image"*) - fig2dev -L ps ${arg} > ${tmp} + fig2dev -L ps "${arg}" > ${tmp} ;; *"PostScript"*) - cp ${arg} ${tmp} + cp "${arg}" ${tmp} ;; *"PDF"*) - pdf2ps ${arg} ${tmp} + pdf2ps "${arg}" ${tmp} ;; *" text"*) - # a2ps -B -R --columns=1 -f 8 -o ${tmp} ${arg} - a2ps --media=A4 --user-option=lp -o ${tmp} ${arg} + # a2ps -B -R --columns=1 -f 8 -o ${tmp} "${arg}" + # if isutf8 -q ${tmp}; then + # echo "Can not print uf8 text." + # exit 1 + # else + a2ps --media=A4 --user-option=lp -o ${tmp} "${arg}" + # fi ;; *"gzip compressed"*) echo "Unzipping " - zcat ${arg} > ${tmp} + zcat "${arg}" > ${tmp} noprint=1 $0 ${opts} ${tmp} ;; @@ -152,7 +162,6 @@ for arg in $*; do ;; *) echo "Unknown option $f" - \rm ${tmp} exit 1;; esac done @@ -176,8 +185,6 @@ for arg in $*; do done -\rm ${tmp} - if [[ ${show_queue} ]]; then lpq fi diff --git a/trash.sh b/trash.sh index aaef037..30faa3a 100755 --- a/trash.sh +++ b/trash.sh @@ -32,6 +32,4 @@ else echo "Created ${TRASH}:" fi -mv $* ${TRASH} - -# ls -ad ${TRASH}/* +mv "$@" ${TRASH} diff --git a/viewer.sh b/viewer.sh index 27b93df..98682d4 100755 --- a/viewer.sh +++ b/viewer.sh @@ -41,24 +41,24 @@ function getgeometry () { # If no argument is given, we pick the most recent file -if [[ ! $1 ]]; then +if [[ ! "$1" ]]; then file=$(\ls -tQ | head -1 | sed -e s/\"//g) echo "Most recent is ${file}" - $0 ${file} + $0 "${file}" exit 0 fi # If there were arguments, we loop through them -echo "Viewing $*" +echo "Viewing $@" -while [[ $1 ]]; do +while [[ "$1" ]]; do - file=$1 + file="$1" # file=$(\ls -tQd $1 | head -1 | sed -e s/\"//g) - # if [[ ! -a ${file} ]]; then + # if [[ ! -a "${file}" ]]; then # echo "Can not find file $1" # exit 1 # fi @@ -70,7 +70,7 @@ while [[ $1 ]]; do *"FIG image text"*) echo "${file}" temp=$(mktemp /tmp/view.XXXXXX) - fig2dev -L pdf ${file} ${temp} + fig2dev -L pdf "${file}" ${temp} # xpdf -g 800x600+8+8 ${temp} getgeometry xpdf -g ${GEOMETRY} ${temp} @@ -79,67 +79,67 @@ while [[ $1 ]]; do *"image"*) echo "${file}" - # feh -g 800x600 ${file} + # feh -g 800x600 "${file}" getgeometry - feh -g ${GEOMETRY} ${file} + feh -g ${GEOMETRY} "${file}" ;; *"TeX DVI"*) echo "${file}" - xdvi ${file} + xdvi "${file}" ;; # *"FIG image"*) # echo "${file}" - # xfig ${file} + # xfig "${file}" # ;; *"PostScript"*) echo "${file}" - gv ${file} + gv "${file}" ;; *"PDF"*) echo "${file}" - # xpdf -g 800x600+8+8 ${file} + # xpdf -g 800x600+8+8 "${file}" getgeometry - xpdf -g ${GEOMETRY} ${file} + xpdf -g ${GEOMETRY} "${file}" ;; *"WAVE audio"*) echo "${file}" - esdplay ${file} + esdplay "${file}" ;; *"MP3"*|*"MPEG"*|*"movie"*|*"video"*|*"AVI"*|*"Microsoft ASF"*) - mplayer -quiet ${file} + mplayer -quiet "${file}" ;; *" text"*) HEIGHT=$(stty size | awk '{print $1}') - if [[ $(wc -l ${file} | cut -f 1 -d' ') -gt $((HEIGHT-2)) ]]; then - less ${file} + if [[ $(wc -l "${file}" | cut -f 1 -d' ') -gt $((HEIGHT-2)) ]]; then + less "${file}" else - cat ${file} + cat "${file}" fi ;; *"tar archive"*) - tar ztf ${file} + tar ztf "${file}" ;; *"Microsoft Word Document"*) - antiword ${file} | less + antiword "${file}" | less ;; *"directory"*) - echo "${file}:"; ls -lt ${file} + echo ""${file}":"; ls -lt "${file}" ;; *"gzip compressed"*) temp=$(mktemp /tmp/view.XXXXXX) echo "Decompressing to ${temp}" - zcat ${file} > ${temp} + zcat "${file}" > ${temp} $0 ${temp} echo "Removing ${temp}" rm ${temp} -- 2.20.1