From 017d9a6df918626b79065f650821b40d9c0add15 Mon Sep 17 00:00:00 2001 From: thomasba Date: Thu, 19 Nov 2015 13:10:37 +0100 Subject: [PATCH] Optimized Scripts using shellcheck --- bin/dice | 2 +- bin/ff-opt.sh | 10 +++---- bin/mkd | 72 ++++++++++++++++++++++++----------------------- bin/pandoc-html5 | 2 +- bin/paste42 | 20 ++++++------- bin/ssp | 18 ++++++------ bin/tm | 2 +- bin/tso | 4 +-- bin/vim-highlight | 22 +++++++-------- bin/volume.sh | 4 +-- 10 files changed, 77 insertions(+), 79 deletions(-) diff --git a/bin/dice b/bin/dice index 9533e97..19d95c6 100755 --- a/bin/dice +++ b/bin/dice @@ -1,5 +1,5 @@ #!/bin/bash -z=$(($RANDOM % 6 +1)) +z=$((RANDOM % 6 +1)) case $z in 1) echo "1: ⚀" ;; 2) echo "2: ⚁" ;; diff --git a/bin/ff-opt.sh b/bin/ff-opt.sh index ed3dccd..08c3236 100755 --- a/bin/ff-opt.sh +++ b/bin/ff-opt.sh @@ -2,13 +2,11 @@ # optimize firefox sqlite databases -if [ `ps aux | grep -v grep | grep -c firefox` = "0" ] ; then - IFS=" -" - for i in `find ~/.mozilla -name \*.sqlite`; do +if [ "$(pgrep -c firefox)" = "0" ] ; then + find ~/.mozilla -name \*.sqlite|while read -r i ; do echo "Optimizing \"$i\"..." - sqlite3 $i vacuum - sqlite3 $i reindex + sqlite3 "$i" vacuum + sqlite3 "$i" reindex done echo "done" else diff --git a/bin/mkd b/bin/mkd index b867ab8..0892ac7 100755 --- a/bin/mkd +++ b/bin/mkd @@ -33,7 +33,7 @@ TITLE="" # Read options while getopts lphHo:t: opt ; do case "$opt" in - \-) break;; + -) break;; l) O_LINK=1 ;; p) O_PLAIN=1 ;; o) OUTFILE="$OPTARG";; @@ -41,7 +41,7 @@ while getopts lphHo:t: opt ; do [hH]) usage ;; esac done -shift $(expr $OPTIND - 1) +shift $((OPTIND - 1)) INFILE="$1" @@ -49,42 +49,44 @@ if [ ! -f "$INFILE" ] ; then usage fi -BASENAME="$(basename $INFILE)" -T_="$(echo -n $BASENAME|sed -re 's/\.(markdown|mkd|mk|md)$//')" +BASENAME="$(basename "$INFILE")" +T_="$(echo -n "$BASENAME"|sed -re 's/\.(markdown|mkd|mk|md)$//')" [ "$OUTFILE" = "" ] && OUTFILE="${T_}.html" -[ "$TITLE" = "" ] && TITLE="$(echo -n ${T_}|tr '_' ' ')" +[ "$TITLE" = "" ] && TITLE="$(echo -n "${T_}"|tr '_' ' ')" -echo "" > $OUTFILE -echo "" >> $OUTFILE -echo " " >> $OUTFILE -echo " $TITLE" >> $OUTFILE +( +echo "" +echo "" +echo " " +echo " $TITLE" if [ $O_PLAIN -eq 0 ] ; then - echo " " >> $OUTFILE + echo " " fi -if [ "$MKD" = "multimarkdown" -a $O_LINK -eq 1 ] ; then - echo " " >> $OUTFILE - echo " " >> $OUTFILE +if [ "$MKD" = "multimarkdown" ] && [ $O_LINK -eq 1 ] ; then + echo " " + echo " " fi -echo " " >> $OUTFILE -echo " " >> $OUTFILE -$MKD $INFILE >> $OUTFILE -echo " " >> $OUTFILE -echo "" >> $OUTFILE +echo " " +echo " " +$MKD "$INFILE" +echo " " +echo "" +) > "$OUTFILE" diff --git a/bin/pandoc-html5 b/bin/pandoc-html5 index f8f8f2b..dfa104f 100755 --- a/bin/pandoc-html5 +++ b/bin/pandoc-html5 @@ -12,7 +12,7 @@ html{font:1em/1.5em "Bitstream Vera Sans","Verdana",sans-serif}h1,h2,h3{padding- EOS -pandoc -f markdown -t html5 $@ +pandoc -f markdown -t html5 "$@" cat << EOS diff --git a/bin/paste42 b/bin/paste42 index 1792bbd..da821fa 100755 --- a/bin/paste42 +++ b/bin/paste42 @@ -3,10 +3,8 @@ # paste42.sh [-s] [-t "filetype"] [-l] [-h] [-u] file # Variablen initialisieren & defaults setzen -VERSION="20110621.1" +VERSION="20151119.1" ATTR='' -OPTS="" -EXP='0' TYPE="text" TYPES="4cs 6502acme 6502kickass 6502tasm 68000devpac abap actionscript3 actionscript ada algol68 apache applescript apt_sources asm asp autoconf autohotkey autoit avisynth awk bascomavr bash basic4gl bf bibtex blitzbasic bnf boo caddcl cadlisp cfdg cfm chaiscript cil c_loadrunner clojure c_mac cmake cobol coffeescript c cpp cpp-qt csharp css cuesheet dcs delphi diff div dos dot d ecmascript eiffel email epc e erlang euphoria f1 falcon fo fortran freebasic fsharp gambas gdb genero genie gettext glsl gml gnuplot go groovy gwbasic haskell hicest hq9plus html4strict html5 icon idl ini inno intercal io java5 java javascript j jquery kixtart klonec klonecpp latex lb lisp llvm locobasic logtalk lolcode lotusformulas lotusscript lscript lsl2 lua m68k magiksf make mapbasic matlab mirc mmix modula2 modula3 mpasm mxml mysql newlisp nsis oberon2 objc objeck ocaml-brief ocaml oobas oracle11 oracle8 oxygene oz pascal pcre perl6 perl per pf php-brief php pic16 pike pixelbender pli plsql postgresql povray powerbuilder powershell proftpd progress prolog properties providex purebasic pycon python qbasic q rails rebol reg robots rpmspec rsplus ruby sas scala scheme scilab sdlbasic smalltalk smarty sql systemverilog tcl teraterm text thinbasic tsql typoscript unicon uscript vala vbnet vb verilog vhdl vim visualfoxpro visualprolog whitespace whois winbatch xbasic xml xorg_conf xpp yaml z80 zxbasic" pw=0 @@ -54,17 +52,17 @@ if [ $# -eq 0 ] ; then usage ; exit ; fi # argumente auswerten while getopts pst:lhue: opt ; do case "$opt" in - \-) break;; + -) break;; s) ATTR=$ATTR' -d sec=true';; t) TYPE=$OPTARG;; [hH]) usage;exit;; l) filetypes;exit;; u) checkUpdate;exit;; p) pw=1;; - e) ATTR=$ATTR' -d exp='$(echo $OPTARG|sed -e 's/[^0-9:\.a-zA-Z ,]//g');; + e) ATTR=$ATTR' -d exp='$(echo "$OPTARG"|sed -e 's/[^0-9:\.a-zA-Z ,]//g');; esac done -shift $(expr $OPTIND - 1) +shift $((OPTIND - 1)) # wenn dateiname leer ist, beenden if [ -z "$1" ] ; then @@ -73,7 +71,7 @@ if [ -z "$1" ] ; then fi # wenn datei nicht existiert oder nicht lesbar ist, suizid -if [ ! -f "$1" -o ! -r "$1" ] ; then +if [ ! -f "$1" ] || [ ! -r "$1" ] ; then echo "File \"$1\" not readable!" >&2 exit 1 fi @@ -81,7 +79,7 @@ if [ ! -s "$1" ] ; then echo "File is empty!" >&2 exit 1 fi -if [ -b "$1" -o -c "$1" -o -S "$1" -o -d "$1" ] ; then +if [ -b "$1" ] || [ -c "$1" ] || [ -S "$1" ] || [ -d "$1" ] ; then echo "\"$1\" is no ordinary file!" exit 1 fi @@ -98,14 +96,14 @@ if [ $pw -eq 1 ] ; then while [ ! "$password" = "$password2" ] ; do if [ ! "$password" = "" ] ; then echo "The passwords didn't match." ; fi echo -ne " Password: " - stty -echo ; read password ; stty echo + stty -echo ; read -r password ; stty echo echo -ne "\n Repeat the password: " - stty -echo ; read password2 ; stty echo + stty -echo ; read -r password2 ; stty echo echo "" done fi -filename=`basename $1` +filename=$(basename "$1") # und die daten absenden. curl -s -S --data-urlencode "del=$password" -d "title=curl paste of $filename" $ATTR -d "type=$TYPE" --data-urlencode "text@$1" 'http://paste42.de/save' diff --git a/bin/ssp b/bin/ssp index 0dbc0c7..65a1ed5 100755 --- a/bin/ssp +++ b/bin/ssp @@ -6,7 +6,7 @@ i=0 # print_host function print_host() { let i=i+1 - IP1=$(dig +short $2|tail -n1) + IP1=$(dig +short "$2"|tail -n1) hosts[$i]="$2" if [[ "$IP1" == "$3" ]] ; then echo " $i) $1 [$IP1] (active)" @@ -17,19 +17,19 @@ function print_host() { ZEUS=$(dig +short zeus.lima-premium.de|tail -n1) echo "zeus: [$ZEUS]" -print_host "megatron" "megatron.trafficplex.de" $ZEUS -print_host "optimusprime" "optimusprime.trafficplex.de" $ZEUS +print_host "megatron" "megatron.trafficplex.de" "$ZEUS" +print_host "optimusprime" "optimusprime.trafficplex.de" "$ZEUS" HERA=$(dig +short hera.lima-premium.de|tail -n1) echo "hera: [$HERA]" -print_host "starscream" "starscream.trafficplex.de" $HERA -print_host "bumblebee" "bumblebee.trafficplex.de" $HERA +print_host "starscream" "starscream.trafficplex.de" "$HERA" +print_host "bumblebee" "bumblebee.trafficplex.de" "$HERA" echo -n "> " -read choice -while [ $choice -lt 1 -o $choice -gt $i ] ; do +read -r choice +while [ "$choice" -lt 1 ] || [ "$choice" -gt $i ] ; do echo -n "> " - read choice -p "> " + read choice -rp "> " done -ssh ${hosts[$choice]} +ssh "${hosts[$choice]}" diff --git a/bin/tm b/bin/tm index ba98200..a215c18 100755 --- a/bin/tm +++ b/bin/tm @@ -2,7 +2,7 @@ # export PATH=$PATH:/usr/local/bin # abort if we're already inside a TMUX session -[ "$TMUX" == "" ] || exit 0 +[ -z "$TMUX" ] || exit 0 # startup a "default" session if non currently exists # tmux has-session -t _default || tmux new-session -s _default -d diff --git a/bin/tso b/bin/tso index 51bea9b..59d5d98 100755 --- a/bin/tso +++ b/bin/tso @@ -17,7 +17,7 @@ QUALITY="3.0" while getopts n:h opt ; do case "$opt" in - \-) break ;; + -) break ;; [hH]) usage ; exit ;; n) QUALITY=$OPTARG ;; esac @@ -32,7 +32,7 @@ fi mkdir -p "$DIR/smalleroggs" TMP="$(mktemp)" -find "$DIR" -maxdepth 1 -iname '*.ogg' -o -iname '*.mp3' -o -iname '*.flac'|while read FILE ; do +find "$DIR" -maxdepth 1 -iname '*.ogg' -o -iname '*.mp3' -o -iname '*.flac'|while read -r FILE ; do NAME=$( basename "$FILE" ) echo "Processing \"$NAME\"..." case $FILE in diff --git a/bin/vim-highlight b/bin/vim-highlight index fd5691c..6763758 100755 --- a/bin/vim-highlight +++ b/bin/vim-highlight @@ -5,12 +5,12 @@ lnr="1" while getopts n opt ; do case "$opt" in n) lnr="0" ;; - \-) break ;; + -) break ;; esac done -shift $(expr $OPTIND - 1) -file=$(mktemp) +shift $((OPTIND - 1)) +file="$(mktemp)" if [ -z "$2" ] ; then title="No Title" @@ -18,9 +18,9 @@ else title="$2" fi -cat > $file +cat > "$file" -vim -nEs $file +"syntax on" \ +vim -nEs "$file" +"syntax on" \ +"set t_Co=256 ft=$1 tabstop=4 fileencodings=ucs-bom,utf-8,latin,windows-1252" \ +"colorscheme wombat256_thomasba" \ +"let html_no_progress=1" \ @@ -31,10 +31,10 @@ vim -nEs $file +"syntax on" \ +"w! $file.html" \ +"qall!" &>/dev/null -sed -i 's_/tmp/.*_'"$title"'_' $file.html -sed -i '/^