Optimized Scripts using shellcheck

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

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

@ -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

@ -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 "<!DOCTYPE html>" > $OUTFILE
echo "<html>" >> $OUTFILE
echo " <head>" >> $OUTFILE
echo " <title>$TITLE</title>" >> $OUTFILE
(
echo "<!DOCTYPE html>"
echo "<html>"
echo " <head>"
echo " <title>$TITLE</title>"
if [ $O_PLAIN -eq 0 ] ; then
echo " <style type=\"text/css\">" >> $OUTFILE
echo " html {font:1em/1.5em "Bitstream Vera Sans","Verdana",sans-serif}" >> $OUTFILE
echo " h1,h2,h3 {padding-bottom:0.1em}" >> $OUTFILE
echo " h1 {border-bottom:0.01em solid #666}" >> $OUTFILE
echo " h2 {border-bottom:0.01em solid #999}" >> $OUTFILE
echo " h3 {border-bottom:0.01em dashed #ccc}" >> $OUTFILE
echo " p {text-align: justify}" >> $OUTFILE
echo " .small {font-size:0.75em}" >> $OUTFILE
echo " .grey {color:#666666}" >> $OUTFILE
echo " blockquote {margin:10px 0px;padding-left:10px;border-left:10px solid #ccc}" >> $OUTFILE
echo " @media screen {body {max-width:800px;margin:auto}}" >> $OUTFILE
echo " </style>" >> $OUTFILE
echo " <style type=\"text/css\">"
echo " html {font:1em/1.5em \"Bitstream Vera Sans\",\"Verdana\",sans-serif}"
echo " h1,h2,h3 {padding-bottom:0.1em}"
echo " h1 {border-bottom:0.01em solid #666}"
echo " h2 {border-bottom:0.01em solid #999}"
echo " h3 {border-bottom:0.01em dashed #ccc}"
echo " p {text-align: justify}"
echo " .small {font-size:0.75em}"
echo " .grey {color:#666666}"
echo " blockquote {margin:10px 0px;padding-left:10px;border-left:10px solid #ccc}"
echo " @media screen {body {max-width:800px;margin:auto}}"
echo " </style>"
fi
if [ "$MKD" = "multimarkdown" -a $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 type="text/javascript">" >> $OUTFILE
echo " \$(document).ready(function() {" >> $OUTFILE
echo " \$(\"h1,h2,h3,h4,h5,h6\").click(function() {" >> $OUTFILE
echo " window.location.hash = '#' + \$(this).attr(\"id\");" >> $OUTFILE
echo " });" >> $OUTFILE
echo " });" >> $OUTFILE
echo " </script>" >> $OUTFILE
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>"
echo " <script type=\"text/javascript\">"
echo " \$(document).ready(function() {"
echo " \$(\"h1,h2,h3,h4,h5,h6\").click(function() {"
echo " window.location.hash = '#' + \$(this).attr(\"id\");"
echo " });"
echo " });"
echo " </script>"
fi
echo " </head>" >> $OUTFILE
echo " <body>" >> $OUTFILE
$MKD $INFILE >> $OUTFILE
echo " </body>" >> $OUTFILE
echo "</html>" >> $OUTFILE
echo " </head>"
echo " <body>"
$MKD "$INFILE"
echo " </body>"
echo "</html>"
) > "$OUTFILE"

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

@ -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'

@ -6,7 +6,7 @@ i=0
# print_host <name> <hostname> <cluster-ip>
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]}"

@ -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

@ -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

@ -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_<title>/tmp/.*</title>_<title>'"$title"'</title>_' $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_<title>/tmp/.*</title>_<title>'"$title"'</title>_' "$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"
rm $file
cat $file.html
rm $file.html
rm "$file"
cat "$file.html"
rm "$file.html"

@ -11,11 +11,11 @@ if [ $# -eq 0 ] ; then
elif [[ $1 = +[0-9]* ]] || [[ $1 = -[0-9]* ]] ; then
volume="$1"
#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
elif [[ $1 = [0-9]* ]] ; then
volume=$1
amixer -q -c $CARD -- sset $CH playback $volume%
amixer -q -c "$CARD" -- sset $CH playback "$volume%"
pkill -RTMIN+1 i3blocks||true
else
echo "Usage: $0 ±<int>"

Loading…
Cancel
Save