Optimized Scripts using shellcheck

main
Thomas Ba. 10 years ago
parent 4ea78a0346
commit 017d9a6df9

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
z=$(($RANDOM % 6 +1)) z=$((RANDOM % 6 +1))
case $z in case $z in
1) echo "1: ⚀" ;; 1) echo "1: ⚀" ;;
2) echo "2: ⚁" ;; 2) echo "2: ⚁" ;;

@ -2,13 +2,11 @@
# optimize firefox sqlite databases # optimize firefox sqlite databases
if [ `ps aux | grep -v grep | grep -c firefox` = "0" ] ; then if [ "$(pgrep -c firefox)" = "0" ] ; then
IFS=" find ~/.mozilla -name \*.sqlite|while read -r i ; do
"
for i in `find ~/.mozilla -name \*.sqlite`; do
echo "Optimizing \"$i\"..." echo "Optimizing \"$i\"..."
sqlite3 $i vacuum sqlite3 "$i" vacuum
sqlite3 $i reindex sqlite3 "$i" reindex
done done
echo "done" echo "done"
else else

@ -33,7 +33,7 @@ TITLE=""
# Read options # Read options
while getopts lphHo:t: opt ; do while getopts lphHo:t: opt ; do
case "$opt" in case "$opt" in
\-) break;; -) break;;
l) O_LINK=1 ;; l) O_LINK=1 ;;
p) O_PLAIN=1 ;; p) O_PLAIN=1 ;;
o) OUTFILE="$OPTARG";; o) OUTFILE="$OPTARG";;
@ -41,7 +41,7 @@ while getopts lphHo:t: opt ; do
[hH]) usage ;; [hH]) usage ;;
esac esac
done done
shift $(expr $OPTIND - 1) shift $((OPTIND - 1))
INFILE="$1" INFILE="$1"
@ -49,42 +49,44 @@ if [ ! -f "$INFILE" ] ; then
usage usage
fi fi
BASENAME="$(basename $INFILE)" BASENAME="$(basename "$INFILE")"
T_="$(echo -n $BASENAME|sed -re 's/\.(markdown|mkd|mk|md)$//')" T_="$(echo -n "$BASENAME"|sed -re 's/\.(markdown|mkd|mk|md)$//')"
[ "$OUTFILE" = "" ] && OUTFILE="${T_}.html" [ "$OUTFILE" = "" ] && OUTFILE="${T_}.html"
[ "$TITLE" = "" ] && TITLE="$(echo -n ${T_}|tr '_' ' ')" [ "$TITLE" = "" ] && TITLE="$(echo -n "${T_}"|tr '_' ' ')"
echo "<!DOCTYPE html>" > $OUTFILE (
echo "<html>" >> $OUTFILE echo "<!DOCTYPE html>"
echo " <head>" >> $OUTFILE echo "<html>"
echo " <title>$TITLE</title>" >> $OUTFILE echo " <head>"
echo " <title>$TITLE</title>"
if [ $O_PLAIN -eq 0 ] ; then if [ $O_PLAIN -eq 0 ] ; then
echo " <style type=\"text/css\">" >> $OUTFILE echo " <style type=\"text/css\">"
echo " html {font:1em/1.5em "Bitstream Vera Sans","Verdana",sans-serif}" >> $OUTFILE echo " html {font:1em/1.5em \"Bitstream Vera Sans\",\"Verdana\",sans-serif}"
echo " h1,h2,h3 {padding-bottom:0.1em}" >> $OUTFILE echo " h1,h2,h3 {padding-bottom:0.1em}"
echo " h1 {border-bottom:0.01em solid #666}" >> $OUTFILE echo " h1 {border-bottom:0.01em solid #666}"
echo " h2 {border-bottom:0.01em solid #999}" >> $OUTFILE echo " h2 {border-bottom:0.01em solid #999}"
echo " h3 {border-bottom:0.01em dashed #ccc}" >> $OUTFILE echo " h3 {border-bottom:0.01em dashed #ccc}"
echo " p {text-align: justify}" >> $OUTFILE echo " p {text-align: justify}"
echo " .small {font-size:0.75em}" >> $OUTFILE echo " .small {font-size:0.75em}"
echo " .grey {color:#666666}" >> $OUTFILE echo " .grey {color:#666666}"
echo " blockquote {margin:10px 0px;padding-left:10px;border-left:10px solid #ccc}" >> $OUTFILE echo " blockquote {margin:10px 0px;padding-left:10px;border-left:10px solid #ccc}"
echo " @media screen {body {max-width:800px;margin:auto}}" >> $OUTFILE echo " @media screen {body {max-width:800px;margin:auto}}"
echo " </style>" >> $OUTFILE echo " </style>"
fi fi
if [ "$MKD" = "multimarkdown" -a $O_LINK -eq 1 ] ; then if [ "$MKD" = "multimarkdown" ] && [ $O_LINK -eq 1 ] ; then
echo " <script src=\"http://code.jquery.com/jquery-1.7.1.min.js\" type=\"text/javascript\"></script>" >> $OUTFILE echo " <script src=\"http://code.jquery.com/jquery-1.7.1.min.js\" type=\"text/javascript\"></script>"
echo " <script type="text/javascript">" >> $OUTFILE echo " <script type=\"text/javascript\">"
echo " \$(document).ready(function() {" >> $OUTFILE echo " \$(document).ready(function() {"
echo " \$(\"h1,h2,h3,h4,h5,h6\").click(function() {" >> $OUTFILE echo " \$(\"h1,h2,h3,h4,h5,h6\").click(function() {"
echo " window.location.hash = '#' + \$(this).attr(\"id\");" >> $OUTFILE echo " window.location.hash = '#' + \$(this).attr(\"id\");"
echo " });" >> $OUTFILE echo " });"
echo " });" >> $OUTFILE echo " });"
echo " </script>" >> $OUTFILE echo " </script>"
fi fi
echo " </head>" >> $OUTFILE echo " </head>"
echo " <body>" >> $OUTFILE echo " <body>"
$MKD $INFILE >> $OUTFILE $MKD "$INFILE"
echo " </body>" >> $OUTFILE echo " </body>"
echo "</html>" >> $OUTFILE echo "</html>"
) > "$OUTFILE"

@ -12,7 +12,7 @@ html{font:1em/1.5em "Bitstream Vera Sans","Verdana",sans-serif}h1,h2,h3{padding-
</head> </head>
<body> <body>
EOS EOS
pandoc -f markdown -t html5 $@ pandoc -f markdown -t html5 "$@"
cat << EOS cat << EOS
</body> </body>
</html> </html>

@ -3,10 +3,8 @@
# paste42.sh [-s] [-t "filetype"] [-l] [-h] [-u] file # paste42.sh [-s] [-t "filetype"] [-l] [-h] [-u] file
# Variablen initialisieren & defaults setzen # Variablen initialisieren & defaults setzen
VERSION="20110621.1" VERSION="20151119.1"
ATTR='' ATTR=''
OPTS=""
EXP='0'
TYPE="text" 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" 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 pw=0
@ -54,17 +52,17 @@ if [ $# -eq 0 ] ; then usage ; exit ; fi
# argumente auswerten # argumente auswerten
while getopts pst:lhue: opt ; do while getopts pst:lhue: opt ; do
case "$opt" in case "$opt" in
\-) break;; -) break;;
s) ATTR=$ATTR' -d sec=true';; s) ATTR=$ATTR' -d sec=true';;
t) TYPE=$OPTARG;; t) TYPE=$OPTARG;;
[hH]) usage;exit;; [hH]) usage;exit;;
l) filetypes;exit;; l) filetypes;exit;;
u) checkUpdate;exit;; u) checkUpdate;exit;;
p) pw=1;; 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 esac
done done
shift $(expr $OPTIND - 1) shift $((OPTIND - 1))
# wenn dateiname leer ist, beenden # wenn dateiname leer ist, beenden
if [ -z "$1" ] ; then if [ -z "$1" ] ; then
@ -73,7 +71,7 @@ if [ -z "$1" ] ; then
fi fi
# wenn datei nicht existiert oder nicht lesbar ist, suizid # 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 echo "File \"$1\" not readable!" >&2
exit 1 exit 1
fi fi
@ -81,7 +79,7 @@ if [ ! -s "$1" ] ; then
echo "File is empty!" >&2 echo "File is empty!" >&2
exit 1 exit 1
fi 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!" echo "\"$1\" is no ordinary file!"
exit 1 exit 1
fi fi
@ -98,14 +96,14 @@ if [ $pw -eq 1 ] ; then
while [ ! "$password" = "$password2" ] ; do while [ ! "$password" = "$password2" ] ; do
if [ ! "$password" = "" ] ; then echo "The passwords didn't match." ; fi if [ ! "$password" = "" ] ; then echo "The passwords didn't match." ; fi
echo -ne " Password: " echo -ne " Password: "
stty -echo ; read password ; stty echo stty -echo ; read -r password ; stty echo
echo -ne "\n Repeat the password: " echo -ne "\n Repeat the password: "
stty -echo ; read password2 ; stty echo stty -echo ; read -r password2 ; stty echo
echo "" echo ""
done done
fi fi
filename=`basename $1` filename=$(basename "$1")
# und die daten absenden. # 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' 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'

@ -6,7 +6,7 @@ i=0
# print_host <name> <hostname> <cluster-ip> # print_host <name> <hostname> <cluster-ip>
function print_host() { function print_host() {
let i=i+1 let i=i+1
IP1=$(dig +short $2|tail -n1) IP1=$(dig +short "$2"|tail -n1)
hosts[$i]="$2" hosts[$i]="$2"
if [[ "$IP1" == "$3" ]] ; then if [[ "$IP1" == "$3" ]] ; then
echo " $i) $1 [$IP1] (active)" echo " $i) $1 [$IP1] (active)"
@ -17,19 +17,19 @@ function print_host() {
ZEUS=$(dig +short zeus.lima-premium.de|tail -n1) ZEUS=$(dig +short zeus.lima-premium.de|tail -n1)
echo "zeus: [$ZEUS]" echo "zeus: [$ZEUS]"
print_host "megatron" "megatron.trafficplex.de" $ZEUS print_host "megatron" "megatron.trafficplex.de" "$ZEUS"
print_host "optimusprime" "optimusprime.trafficplex.de" $ZEUS print_host "optimusprime" "optimusprime.trafficplex.de" "$ZEUS"
HERA=$(dig +short hera.lima-premium.de|tail -n1) HERA=$(dig +short hera.lima-premium.de|tail -n1)
echo "hera: [$HERA]" echo "hera: [$HERA]"
print_host "starscream" "starscream.trafficplex.de" $HERA print_host "starscream" "starscream.trafficplex.de" "$HERA"
print_host "bumblebee" "bumblebee.trafficplex.de" $HERA print_host "bumblebee" "bumblebee.trafficplex.de" "$HERA"
echo -n "> " echo -n "> "
read choice read -r choice
while [ $choice -lt 1 -o $choice -gt $i ] ; do while [ "$choice" -lt 1 ] || [ "$choice" -gt $i ] ; do
echo -n "> " echo -n "> "
read choice -p "> " read choice -rp "> "
done done
ssh ${hosts[$choice]} ssh "${hosts[$choice]}"

@ -2,7 +2,7 @@
# export PATH=$PATH:/usr/local/bin # export PATH=$PATH:/usr/local/bin
# abort if we're already inside a TMUX session # abort if we're already inside a TMUX session
[ "$TMUX" == "" ] || exit 0 [ -z "$TMUX" ] || exit 0
# startup a "default" session if non currently exists # startup a "default" session if non currently exists
# tmux has-session -t _default || tmux new-session -s _default -d # tmux has-session -t _default || tmux new-session -s _default -d

@ -17,7 +17,7 @@ QUALITY="3.0"
while getopts n:h opt ; do while getopts n:h opt ; do
case "$opt" in case "$opt" in
\-) break ;; -) break ;;
[hH]) usage ; exit ;; [hH]) usage ; exit ;;
n) QUALITY=$OPTARG ;; n) QUALITY=$OPTARG ;;
esac esac
@ -32,7 +32,7 @@ fi
mkdir -p "$DIR/smalleroggs" mkdir -p "$DIR/smalleroggs"
TMP="$(mktemp)" 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" ) NAME=$( basename "$FILE" )
echo "Processing \"$NAME\"..." echo "Processing \"$NAME\"..."
case $FILE in case $FILE in

@ -5,12 +5,12 @@ lnr="1"
while getopts n opt ; do while getopts n opt ; do
case "$opt" in case "$opt" in
n) lnr="0" ;; n) lnr="0" ;;
\-) break ;; -) break ;;
esac esac
done done
shift $(expr $OPTIND - 1) shift $((OPTIND - 1))
file=$(mktemp) file="$(mktemp)"
if [ -z "$2" ] ; then if [ -z "$2" ] ; then
title="No Title" title="No Title"
@ -18,9 +18,9 @@ else
title="$2" title="$2"
fi 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" \ +"set t_Co=256 ft=$1 tabstop=4 fileencodings=ucs-bom,utf-8,latin,windows-1252" \
+"colorscheme wombat256_thomasba" \ +"colorscheme wombat256_thomasba" \
+"let html_no_progress=1" \ +"let html_no_progress=1" \
@ -31,10 +31,10 @@ vim -nEs $file +"syntax on" \
+"w! $file.html" \ +"w! $file.html" \
+"qall!" &>/dev/null +"qall!" &>/dev/null
sed -i 's_<title>/tmp/.*</title>_<title>'"$title"'</title>_' $file.html sed -i 's_<title>/tmp/.*</title>_<title>'"$title"'</title>_' "$file.html"
sed -i '/^<style type="text\/css">/,/^<\/style>/d' $file.html sed -i '/^<style type="text\/css">/,/^<\/style>/d' "$file.html"
sed -i 's/^<\/head>/<link href="vim.css" type="text\/css" rel="stylesheet"\/>\n<\/head>/' $file.html sed -i 's/^<\/head>/<link href="vim.css" type="text\/css" rel="stylesheet"\/>\n<\/head>/' "$file.html"
rm $file rm "$file"
cat $file.html cat "$file.html"
rm $file.html rm "$file.html"

@ -11,11 +11,11 @@ if [ $# -eq 0 ] ; then
elif [[ $1 = +[0-9]* ]] || [[ $1 = -[0-9]* ]] ; then elif [[ $1 = +[0-9]* ]] || [[ $1 = -[0-9]* ]] ; then
volume="$1" volume="$1"
#amixer -q -c 0 -- sset Master playback $(calc $(amixer sget Master | sed -rn 's/^.*Front Right: [^\[]*\[([0-9]+)%\].*$/\1/p')$volume)% #amixer -q -c 0 -- sset Master playback $(calc $(amixer sget Master | sed -rn 's/^.*Front Right: [^\[]*\[([0-9]+)%\].*$/\1/p')$volume)%
amixer -c $CARD set $CH $(echo $1|sed -e 's/^\(.\)\(.*\)$/\2%\1/') > /dev/null amixer -c "$CARD" set $CH "$(echo "$1"|sed -e 's/^\(.\)\(.*\)$/\2%\1/')" > /dev/null
pkill -RTMIN+1 i3blocks||true pkill -RTMIN+1 i3blocks||true
elif [[ $1 = [0-9]* ]] ; then elif [[ $1 = [0-9]* ]] ; then
volume=$1 volume=$1
amixer -q -c $CARD -- sset $CH playback $volume% amixer -q -c "$CARD" -- sset $CH playback "$volume%"
pkill -RTMIN+1 i3blocks||true pkill -RTMIN+1 i3blocks||true
else else
echo "Usage: $0 ±<int>" echo "Usage: $0 ±<int>"

Loading…
Cancel
Save