scripts: Lint all scripts

master
Pierre Neidhardt 2016-06-23 23:18:36 +02:00
parent 2ae294499a
commit 8f384c3d3f
35 changed files with 117 additions and 120 deletions

View File

@ -48,7 +48,7 @@ while getopts ":him:sv" opt; do
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_usage "$0" _usage "$0"

View File

@ -28,7 +28,7 @@ while getopts ":hd:" opt; do
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_usage "$0" _usage "$0"
@ -41,7 +41,7 @@ if ! command -v readcd >/dev/null 2>&1; then
fi fi
## Fast? ## Fast?
readcd dev=$DRIVE f="$1.iso" -v retries=5 timeout=30 -noerror readcd dev="$DRIVE" f="$1.iso" -v retries=5 timeout=30 -noerror
## Slow ## Slow
# readcd f="$1.iso" -v retries=32 timeout=30 -s speed=16 -noerror # readcd f="$1.iso" -v retries=32 timeout=30 -s speed=16 -noerror

View File

@ -17,4 +17,4 @@ fi
[ $# -ge 1 ] && COLUMN="$1" && shift [ $# -ge 1 ] && COLUMN="$1" && shift
[ $# -ge 1 ] && FORMAT="$1" [ $# -ge 1 ] && FORMAT="$1"
awk -v format="$FORMAT" '{total += $'$COLUMN'; print} END {printf format, total}' awk -v format="$FORMAT" '{total += $'"$COLUMN"'; print} END {printf format, total}'

View File

@ -42,7 +42,7 @@ f2=$(echo "$cpuarray" | cut -f4 -d' ')
f3=$(echo "$cpuarray" | cut -f5 -d' ') f3=$(echo "$cpuarray" | cut -f5 -d' ')
f4=$(echo "$cpuarray" | cut -f6 -d' ') f4=$(echo "$cpuarray" | cut -f6 -d' ')
totalA=$(($f1+$f2+$f3+$f4)) totalA=$((f1+f2+f3+f4))
idleA=$f4 idleA=$f4
sleep 1 sleep 1
@ -52,7 +52,7 @@ f2=$(echo "$cpuarray" | cut -f4 -d' ')
f3=$(echo "$cpuarray" | cut -f5 -d' ') f3=$(echo "$cpuarray" | cut -f5 -d' ')
f4=$(echo "$cpuarray" | cut -f6 -d' ') f4=$(echo "$cpuarray" | cut -f6 -d' ')
totalB=$(($f1+$f2+$f3+$f4)) totalB=$((f1+f2+f3+f4))
idleB=$f4 idleB=$f4
totaldiff=$((${totalB:-0}-${totalA:-0})) totaldiff=$((${totalB:-0}-${totalA:-0}))
@ -60,5 +60,5 @@ totaldiff=$((${totalB:-0}-${totalA:-0}))
if [ $totaldiff -eq 0 ]; then if [ $totaldiff -eq 0 ]; then
echo 0 echo 0
else else
echo "$((100 - 100 * ($idleB-$idleA) / $totaldiff ))" echo "$((100 - 100 * (idleB-idleA) / totaldiff))"
fi fi

View File

@ -7,7 +7,7 @@ usage () {
cat <<EOF cat <<EOF
Usage: ${1##*/} Usage: ${1##*/}
Run `sessionclean' if available and $rawname the system. Run 'sessionclean' if available and $rawname the system.
EOF EOF
} }
@ -32,8 +32,8 @@ command -v sessionclean >/dev/null 2>&1 && sessionclean
if command -v systemctl >/dev/null 2>&1; then if command -v systemctl >/dev/null 2>&1; then
$rawname $rawname
then else
## If you do not want to get prompted for your password, configure sudo ## If you do not want to get prompted for your password, configure sudo
## properly. ## properly.
sudo $rawname sudo "$rawname"
fi fi

View File

@ -2,7 +2,7 @@
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} FILE [FLAGS] Usage: ${0##*/} FILE [CFLAGS]
Simulate a C interpreter by compiling, executing and removing file in one run. Simulate a C interpreter by compiling, executing and removing file in one run.
EOF EOF
@ -10,21 +10,20 @@ EOF
fi fi
[ -z "$CC" ] && CC=gcc [ -z "$CC" ] && CC=gcc
FLAGS="-Wall -Wextra -Wshadow -pthread -lm -g3 -O0"
INPUT="$1" INPUT="$1"
shift shift
[ $# -ne 0 ] && FLAGS="$@" [ $# -eq 0 ] && set -- -Wall -Wextra -Wshadow -pthread -lm -g3 -O0
FILE="$(mktemp)" FILE="$(mktemp)"
echo "==> $CC \"$INPUT\" -o \"$FILE\" $FLAGS" echo "==> $CC \"$INPUT\" -o \"$FILE\" $*"
## Zsh compatibility. We need it otherwise word splitting of parameter will not ## Zsh compatibility. We need it otherwise word splitting of parameter will not
## work. ## work.
STATUS="$(set -o | awk '/shwordsplit / {print $2}')" STATUS="$(set -o | awk '/shwordsplit / {print $2}')"
[ "$STATUS" = "off" ] && set -o shwordsplit [ "$STATUS" = "off" ] && set -o shwordsplit
$CC "$INPUT" -o "$FILE" $FLAGS $CC "$INPUT" -o "$FILE" "$@"
## Restore Zsh previous options. This will not turn off shwordsplit if it ## Restore Zsh previous options. This will not turn off shwordsplit if it
## was on before calling the function. ## was on before calling the function.

View File

@ -41,7 +41,7 @@ while getopts ":fhin:" opt; do
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
if $OPT_CUTFIRST; then if $OPT_CUTFIRST; then
sed $OPT_INPLACE -n "1,${OPT_LINES}!p" "$@" sed $OPT_INPLACE -n "1,${OPT_LINES}!p" "$@"

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
compat="" compat=""
if [ $(awk --version | grep -c GNU) -gt 0 ]; then if awk --version | grep -q GNU; then
# This is for hex-to-decimal conversion. # This is for hex-to-decimal conversion.
compat="--non-decimal" compat="--non-decimal"
fi fi

View File

@ -33,7 +33,7 @@ while getopts ":fhw" opt; do
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_usage "$0" _usage "$0"
@ -47,22 +47,25 @@ if ! command -v realpath >/dev/null 2>&1; then
fi fi
for i ; do for i ; do
## Find over '.*' and '*', is bad practice since if will fail on [ ! -d "$i" ] && continue
## non-existing files or for files beginning with a dash. The 'printf'
## command in find is for GNU find only.
## The two following lines do the same for the same time cost. The former is shorter. ## We strip "./" from find's listing since we don't need it. We could avoid
# find "$i" -type f | awk -v str="$i" '{l=length(str)+2; print substr($0, l)}' | sort > "$OUTPUT" ## printing it in the first place, but there are several shortcomings:
## - Find over '.*' and '*', is bad practice since if will fail on
## non-existing files or for files beginning with a dash.
## - The 'printf' command in find is for GNU find only.
## 'LC_ALL=C sort' is required to make sure to output is consistent across ## 'LC_ALL=C sort' is required to make sure to output is consistent across
## different systems. ## different systems.
## The two following lines do the same for the same time cost. The former is shorter.
# find "$i" -type f | awk -v str="$i" '{l=length(str)+2; print substr($0, l)}' | sort > "$OUTPUT"
(cd -- "$i" && find . -type f) | sed 's/^.\///' | LC_ALL=C sort | \ (cd -- "$i" && find . -type f) | sed 's/^.\///' | LC_ALL=C sort | \
if $opt_file; then if $opt_file; then
i="$(realpath -- "$i")" i="$(realpath -- "$i")"
base="${i##*/}" base="${i##*/}"
[ ! -d "$i" ] && continue
output="$base.index" output="$base.index"
[ -e "$OUTPUT" ] && $opt_noclobber && output="$base-$(date +%F-%T).index" [ -e "$output" ] && $opt_noclobber && output="$base-$(date +%F-%T).index"
echo "$output" echo "$output"
cat > "$output" cat > "$output"
else else

View File

@ -27,7 +27,7 @@ while getopts :bc OPT; do
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_usage "$0" _usage "$0"
exit 1 exit 1

View File

@ -35,5 +35,5 @@ else
fi fi
fi fi
[ ! -e /tmp/emacs$(id -u)/server ] && EMACS_SERVER=t emacs --daemon --no-site-file [ ! -e "/tmp/emacs$(id -u)/server" ] && EMACS_SERVER=t emacs --daemon --no-site-file
emacsclient $param "$@" emacsclient $param "$@"

View File

@ -46,7 +46,7 @@ while getopts ":hfp" opt; do
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_usage "$0" _usage "$0"

View File

@ -33,7 +33,7 @@ while getopts ":hd:u:" opt; do
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
usage "$0" usage "$0"
@ -46,5 +46,5 @@ if ! command -v git >/dev/null 2>&1; then
fi fi
for i; do for i; do
git clone git@$DOMAIN:/$USER/$i git clone "git@$DOMAIN:/$USER/$i"
done done

View File

@ -24,7 +24,7 @@ if [ "$(uname)" != "Linux" ]; then
exit 1 exit 1
fi fi
if [ $(id -u) -ne 0 ]; then if [ "$(id -u)" -ne 0 ]; then
_usage _usage
exit 1 exit 1
fi fi

View File

@ -50,7 +50,7 @@ CHOICE="N"
echo echo
echo ":: Close all applications before cleaning." echo ":: Close all applications before cleaning."
echo "==> Clean home? [y/N]" echo "==> Clean home? [y/N]"
read CHOICE read -r CHOICE
case "$CHOICE" in case "$CHOICE" in
Y|y) ;; Y|y) ;;
*) *)

View File

@ -9,13 +9,13 @@ _mount () {
DEVICE="$(cdemu status | awk 'NR>2 && $2==0 {print $1; found=1; exit} END {if(! found)print NR-2}')" DEVICE="$(cdemu status | awk 'NR>2 && $2==0 {print $1; found=1; exit} END {if(! found)print NR-2}')"
DEV_COUNT="$(cdemu device-mapping | awk 'END {print NR-3}')" DEV_COUNT="$(cdemu device-mapping | awk 'END {print NR-3}')"
if [ $(cdemu status | grep -c "$1") -gt 0 ]; then if cdemu status | grep -q "$1"; then
echo "Image alredy mounted." echo "Image alredy mounted."
return return
fi fi
if [ $DEVICE -gt $DEV_COUNT ]; then if [ "$DEVICE" -gt "$DEV_COUNT" ]; then
while [ $DEVICE -gt $DEV_COUNT ]; do while [ "$DEVICE" -gt "$DEV_COUNT" ]; do
cdemu add-device cdemu add-device
DEV_COUNT="$(cdemu device-mapping | awk 'END {print NR-3}')" DEV_COUNT="$(cdemu device-mapping | awk 'END {print NR-3}')"
done done
@ -23,13 +23,13 @@ _mount () {
## WARNING: adding a new device takes some time. If we want to avoid errors, ## WARNING: adding a new device takes some time. If we want to avoid errors,
## we need to sleep until it is ready. ## we need to sleep until it is ready.
echo "Waiting until ready..." echo "Waiting until ready..."
while [ -z "$(cdemu device-mapping | awk -v devnum=$DEV_COUNT 'NR>2 && $1==devnum {print $2}')" ]; do while [ -z "$(cdemu device-mapping | awk -v devnum="$DEV_COUNT" 'NR>2 && $1==devnum {print $2}')" ]; do
sleep 1 sleep 1
done done
fi fi
cdemu load $DEVICE "$1" cdemu load "$DEVICE" "$1"
if [ $? -ne 0 ] && command -v fuseiso >/dev/null 2>&1; then if [ $? -ne 0 ] && command -v fuseiso >/dev/null 2>&1; then
echo "Falling back to fuseiso." echo "Falling back to fuseiso."
@ -43,15 +43,15 @@ _mount () {
fi fi
COUNT=0 COUNT=0
while [ -n "$(echo "$LIST" | grep "$FUSEROOT/drive-$COUNT" )" ]; do while echo "$LIST" | grep -q "$FUSEROOT/drive-$COUNT"; do
COUNT=$(($COUNT+1)) COUNT=$((COUNT+1))
done done
mkdir -p "$FUSEROOT/drive-$COUNT" mkdir -p "$FUSEROOT/drive-$COUNT"
fuseiso -p "$1" "$FUSEROOT/drive-$COUNT" fuseiso -p "$1" "$FUSEROOT/drive-$COUNT"
else else
NODE="$(cdemu device-mapping | awk -v devnum=$DEVICE 'NR>2 && $1==devnum {print $2}')" NODE="$(cdemu device-mapping | awk -v devnum="$DEVICE" 'NR>2 && $1==devnum {print $2}')"
## TODO: This is terrible, but checking cdemu status does not work. Maybe ## TODO: This is terrible, but checking cdemu status does not work. Maybe
## a kernel limitation. ## a kernel limitation.
echo "Mounting..." echo "Mounting..."
@ -71,7 +71,7 @@ _umount () {
udiskie-umount "$1" udiskie-umount "$1"
DEVICE=$(cdemu device-mapping | awk -v node="$NODE" '$2 == node {print $1; exit}') DEVICE=$(cdemu device-mapping | awk -v node="$NODE" '$2 == node {print $1; exit}')
cdemu unload $DEVICE cdemu unload "$DEVICE"
elif command -v fuseiso >/dev/null; then elif command -v fuseiso >/dev/null; then
fusermount -u "$1" fusermount -u "$1"
rmdir "$1" >/dev/null 2>&1 rmdir "$1" >/dev/null 2>&1
@ -108,7 +108,7 @@ while getopts ":hu" opt; do
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_usage "$0" _usage "$0"

View File

@ -14,7 +14,7 @@ fi
LSOFOUT="$(lsof|awk '{print $1}')" LSOFOUT="$(lsof|awk '{print $1}')"
while IFS= read -r i; do while IFS= read -r i; do
echo -n "$i " printf "%s " "$i"
echo "$LSOFOUT" | grep -c "^$i" echo "$LSOFOUT" | grep -c "^$i"
done<<EOF done<<EOF
$(echo "$LSOFOUT" | sort -u) $(echo "$LSOFOUT" | sort -u)

View File

@ -35,7 +35,7 @@ while getopts ":fhr" opt; do
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_usage "$0" _usage "$0"
exit 1 exit 1
@ -48,7 +48,7 @@ DEST="$(eval "echo \$$#")"
count=0 count=0
for i ; do for i ; do
count=$(($count+1)) count=$((count+1))
[ $count -eq $# ] && break [ $count -eq $# ] && break
while IFS= read -r FILE; do while IFS= read -r FILE; do

View File

@ -24,28 +24,28 @@ else
path="/dev/shm/netspeed" path="/dev/shm/netspeed"
time=$(date +%s) time=$(date +%s)
read rx < /sys/class/net/${interface}/statistics/rx_bytes read -r rx < /sys/class/net/"$interface"/statistics/rx_bytes
read tx < /sys/class/net/${interface}/statistics/tx_bytes read -r tx < /sys/class/net/"$interface"/statistics/tx_bytes
if [ ! -f "$path" ]; then if [ ! -f "$path" ]; then
echo "$time $rx $tx" > "$path" echo "$time $rx $tx" > "$path"
chmod 0666 "$path" chmod 0666 "$path"
fi fi
read time_old rx_old tx_old < "$path" read -r time_old rx_old tx_old < "$path"
echo "$time $rx $tx" > "$path" echo "$time $rx $tx" > "$path"
time_diff=$(($time - $time_old)) time_diff=$((time - time_old))
if [ "$time_diff" -gt 0 ]; then if [ "$time_diff" -gt 0 ]; then
rx_rate=$((($rx - $rx_old) / $time_diff)) rx_rate=$(((rx - rx_old) / time_diff))
tx_rate=$((($tx - $tx_old) / $time_diff)) tx_rate=$(((tx - tx_old) / time_diff))
[ "$rx_rate" -gt 1024 ] && rx_rate=$(($rx_rate / 1024)) && rx_unit=K [ "$rx_rate" -gt 1024 ] && rx_rate=$((rx_rate / 1024)) && rx_unit=K
[ "$rx_rate" -gt 1024 ] && rx_rate=$(($rx_rate / 1024)) && rx_unit=M [ "$rx_rate" -gt 1024 ] && rx_rate=$((rx_rate / 1024)) && rx_unit=M
[ "$tx_rate" -gt 1024 ] && tx_rate=$(($tx_rate / 1024)) && tx_unit=K [ "$tx_rate" -gt 1024 ] && tx_rate=$((tx_rate / 1024)) && tx_unit=K
[ "$tx_rate" -gt 1024 ] && tx_rate=$(($tx_rate / 1024)) && tx_unit=M [ "$tx_rate" -gt 1024 ] && tx_rate=$((tx_rate / 1024)) && tx_unit=M
echo -n "$rx_rate $rx_unit↓ $tx_rate $tx_unit↑" printf "%s %s↓ %s %s↑" "$rx_rate" "$rx_unit" "$tx_rate" "$tx_unit"
fi fi
fi fi

View File

@ -10,4 +10,4 @@ description="$3"
SEP=" " SEP=" "
OUTPUT="$XDG_CONFIG_HOME/newsbeuter/news_starred" OUTPUT="$XDG_CONFIG_HOME/newsbeuter/news_starred"
echo -e "${url}$SEP${title}$SEP${description}" >> "$OUTPUT" echo "${url}$SEP${title}$SEP${description}" >> "$OUTPUT"

View File

@ -34,7 +34,7 @@ while getopts ":hmqe" opt; do
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
echo "Missing argument." echo "Missing argument."

View File

@ -128,7 +128,7 @@ while getopts ":ahnstV" opt; do
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
## All-packages mode. ## All-packages mode.
## We use a dedicated algorithm which is much faster than per-package mode. ## We use a dedicated algorithm which is much faster than per-package mode.
@ -177,7 +177,7 @@ fi
## If package is not found locally (-Q), we use the sync database (-S). We ## If package is not found locally (-Q), we use the sync database (-S). We
## use LC_ALL=C to make sure pacman output is not localized. ## use LC_ALL=C to make sure pacman output is not localized.
buffer=$(LC_ALL=C pacman -Qi "$@" 2>&1 1>&3 3>&- | cut -f2 -d "'") buffer=$(LC_ALL=C pacman -Qi "$@" 2>&1 1>&3 3>&- | cut -f2 -d "'")
[ -n "$buffer" ] && LC_ALL=C pacman -Si $buffer [ -n "$buffer" ] && LC_ALL=C pacman -Si "$buffer"
} 3>&1 | filter | { $opt_sort || remove_duplicates ;} | { $opt_total || cat ;} } 3>&1 | filter | { $opt_sort || remove_duplicates ;} | { $opt_total || cat ;}
# vim: set noet: # vim: set noet:

View File

@ -56,7 +56,7 @@ while getopts ":cfhin" opt; do
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_usage "$0" _usage "$0"
@ -76,7 +76,6 @@ for i ; do
esac esac
DIRNAME="${i%/*}" DIRNAME="${i%/*}"
BASENAME="${i##*/}" BASENAME="${i##*/}"
EXTNAME="${BASENAME##*.}"
BASENAME="${BASENAME%.*}" BASENAME="${BASENAME%.*}"
OUTPUT="$DIRNAME/$BASENAME-compressed.pdf" OUTPUT="$DIRNAME/$BASENAME-compressed.pdf"
if [ -e "$OUTPUT" ] && ! $OPT_OVERWRITE; then if [ -e "$OUTPUT" ] && ! $OPT_OVERWRITE; then
@ -86,7 +85,7 @@ for i ; do
echo "$i" echo "$i"
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite $OPT_COMPRESSION -sOutputFile="$OUTPUT" "$i" gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite "$OPT_COMPRESSION" -sOutputFile="$OUTPUT" "$i"
if $OPT_INPLACE; then if $OPT_INPLACE; then
rm -f "$i" rm -f "$i"
mv "$OUTPUT" "$i" mv "$OUTPUT" "$i"

View File

@ -13,4 +13,4 @@ if [ ! -f "$1" ]; then
echo "$1 is not a valid file." echo "$1 is not a valid file."
fi fi
gs -sDEVICE=pdfwrite -dNOPAUSE -dSAFER -dSAFER -dFirstPage=$2 -dBATCH -dLastPage=$3 -sOutputFile="$4" "$1" gs -sDEVICE=pdfwrite -dNOPAUSE -dSAFER -dSAFER -dFirstPage="$2" -dBATCH -dLastPage="$3" -sOutputFile="$4" "$1"

View File

@ -3,7 +3,6 @@
## Create lists of system- and TeX Live packages. ## Create lists of system- and TeX Live packages.
## Variables ## Variables
HOST="$(hostname)"
PKG_ROOT="$HOME/.pkg" PKG_ROOT="$HOME/.pkg"
mkdir -p "$PKG_ROOT" mkdir -p "$PKG_ROOT"

View File

@ -30,7 +30,7 @@ while getopts ":ih" opt; do
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
if [ $# -lt 2 ]; then if [ $# -lt 2 ]; then
_usage "$0" _usage "$0"

View File

@ -16,7 +16,7 @@ DMASK=$(umask -S)
[ -z "$GID" ] && GID=$(id -g) [ -z "$GID" ] && GID=$(id -g)
for i ; do for i ; do
find "$i" -exec chown -R ${UID}:${GID} {} \; find "$i" -exec chown -R "$UID:$GID" {} \;
find "$i" -type d -exec chmod ${DMASK} {} \; find "$i" -type d -exec chmod "$DMASK" {} \;
find "$i" -type f -exec chmod ${FMASK} {} \; find "$i" -type f -exec chmod "$FMASK" {} \;
done done

View File

@ -9,4 +9,4 @@ EOF
exit exit
fi fi
scanimage -x 297 -y 210 | convert -rotate 90 - scan-$(date "+%F_%T").png scanimage -x 297 -y 210 | convert -rotate 90 - "scan-$(date "+%F_%T").png"

View File

@ -24,11 +24,9 @@ fi
for j; do for j; do
while IFS= read -r i; do while IFS= read -r i; do
BUFFER="$(mediainfo "$i")" BUFFER="$(mediainfo "$i")"
[ -n "$(echo "$BUFFER" | grep "Bit rate mode *: Constant")" ] && echo "$i : CBR" echo "$BUFFER" | grep -q "Bit rate mode *: Constant" && echo "$i : CBR"
echo "$BUFFER" | grep -q "Cover *: Yes" && echo "$i : Cover"
[ -n "$(echo "$BUFFER" | grep "Cover *: Yes")" ] && echo "$i : Cover" echo "$BUFFER" | grep -q "Track name/Position *: 0+" && echo "$i : Leading zeros"
[ -n "$(echo "$BUFFER" | grep "Track name/Position *: 0+")" ] && echo "$i : Leading zeros"
done <<EOF done <<EOF
$(find "$j" \( \ $(find "$j" \( \
-iname '*.mp3' -o \ -iname '*.mp3' -o \

View File

@ -20,29 +20,27 @@ for i ; do
while IFS= read -r j; do while IFS= read -r j; do
CODING=$(file "$j") CODING=$(file "$j")
if [ -n "$(echo $CODING | grep 'ISO-8859')" ]; then case "$CODING" in
*ISO-8859*)
echo "ISO-8859: [$j]" echo "ISO-8859: [$j]"
recode latin1..utf-8 "$j" recode latin1..utf-8 "$j";;
*'Non-ISO extended-ASCII'*)
elif [ -n "$(echo $CODING | grep 'Non-ISO extended-ASCII')" ]; then
echo "cp1252: [$j]" echo "cp1252: [$j]"
recode cp1252..utf-8 "$j" recode cp1252..utf-8 "$j";;
*'UTF-16 Unicode text'*)
elif [ -n "$(echo $CODING | grep 'UTF-16 Unicode text')" ]; then
echo "UTF-16: [$j]" echo "UTF-16: [$j]"
recode utf-16..utf-8 "$j" recode utf-16..utf-8 "$j";;
*'UTF-8 Unicode (with BOM)'*)
elif [ -n "$(echo $CODING | grep 'UTF-8 Unicode (with BOM)')" ]; then
echo "UTF-8 BOM: [$j]" echo "UTF-8 BOM: [$j]"
ex -sc '1s/^.//|xit' "$j" ex -sc '1s/^.//|xit' "$j";;
## The following commands are funny alternatives, but are completely ## The following commands are funny alternatives, but are completely
## overkill. ## overkill.
# dd iflag=skip_bytes skip=3 if=file.srt of=temp.srt # dd iflag=skip_bytes skip=3 if=file.srt of=temp.srt
# dd bs=1 skip=3 if=file.srt of=temp.srt # dd bs=1 skip=3 if=file.srt of=temp.srt
# tail -c +32 file.srt > temp.srt # tail -c +32 file.srt > temp.srt
fi esac
if [ -n "$(echo $CODING | grep 'CRLF')" ]; then if echo "$CODING" | grep -q 'CRLF'; then
echo "CRLF: [$j]" echo "CRLF: [$j]"
ex -sc '%s/ //g|xit' "$j" ex -sc '%s/ //g|xit' "$j"
fi fi

View File

@ -18,7 +18,7 @@ fi
for i ; do for i ; do
while IFS= read -r j; do while IFS= read -r j; do
echo -n "# " printf "# "
file "$j" file "$j"
grep -m1 "\`" "$j" grep -m1 "\`" "$j"
grep -m1 "´" "$j" grep -m1 "´" "$j"

View File

@ -128,7 +128,7 @@ while getopts ":a:b:cCd:fho:pPq:sS:t" opt; do
s) s)
SAMPLE="-ss 60 -t 300" ;; SAMPLE="-ss 60 -t 300" ;;
S) S)
SAMPLE="-ss 60 -t $((60*$OPTARG))" ;; SAMPLE="-ss 60 -t $((60*OPTARG))" ;;
t) t)
OPT_REMOVE_TITLE=true ;; OPT_REMOVE_TITLE=true ;;
\?) \?)
@ -137,7 +137,7 @@ while getopts ":a:b:cCd:fho:pPq:sS:t" opt; do
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_usage "$0" _usage "$0"
exit exit
@ -156,8 +156,8 @@ _highfreq() {
## Return the crop values as ffmpeg output them. ## Return the crop values as ffmpeg output them.
_cropvalue() { _cropvalue() {
local step=$2 local step=$2
for i in $(seq $step $step $((5*$step))); do for i in $(seq "$step" "$step" $((5*step))); do
ffmpeg -nostdin -ss $i -i "$1" -t 10 -vf "cropdetect=24:2:0" -f null - 2>&1 ffmpeg -nostdin -ss "$i" -i "$1" -t 10 -vf "cropdetect=24:2:0" -f null - 2>&1
done | _highfreq done | _highfreq
} }
@ -169,24 +169,24 @@ _cropvalue() {
_audiobitrate() { _audiobitrate() {
local bitrate local bitrate
for i in $(seq 0 $(($format_nb_streams-1)) ); do for i in $(seq 0 $((format_nb_streams-1))); do
## Skip non audio tracks. ## Skip non audio tracks.
[ "$(eval echo \$streams_stream_${i}_codec_type)" != "audio" ] && continue [ "$(eval echo \$streams_stream_"$i"_codec_type)" != "audio" ] && continue
bitrate=$(eval echo \$streams_stream_${i}_bit_rate) bitrate=$(eval echo \$streams_stream_"$i"_bit_rate)
if [ -n "$bitrate" ] && [ "$bitrate" -gt 0 ] 2>/dev/null; then if [ -n "$bitrate" ] && [ "$bitrate" -gt 0 ] 2>/dev/null; then
## If non-empty and a positive number. ## If non-empty and a positive number.
bitrate=$(( $bitrate / 1000)) bitrate=$((bitrate / 1000))
else else
bitrate="$AUDIO_DEFAULT_RATE" bitrate="$AUDIO_DEFAULT_RATE"
fi fi
if [ "$bitrate" -le 0 ] || \ if [ "$bitrate" -le 0 ] || \
[ "$AUDIO_CODEC" = "$(eval echo \$streams_stream_${i}_codec_name)" ] || \ [ "$AUDIO_CODEC" = "$(eval echo \$streams_stream_"$i"_codec_name)" ] || \
[ "$AUDIO_CODEC" = "lib$(eval echo \$streams_stream_${i}_codec_name)" ]; then [ "$AUDIO_CODEC" = "lib$(eval echo \$streams_stream_"$i"_codec_name)" ]; then
printf -- "-c:%s copy " $i printf -- "-c:%s copy " "$i"
else else
[ $bitrate -gt 500 ] && bitrate=500 [ "$bitrate" -gt 500 ] && bitrate=500
printf -- "-c:%s %s -b:%s %sk " $i "$AUDIO_CODEC" $i "$bitrate" printf -- "-c:%s %s -b:%s %sk " "$i" "$AUDIO_CODEC" "$i" "$bitrate"
fi fi
done done
} }
@ -202,12 +202,13 @@ _transcode() {
_error "File [$1] is unsupported by FFmpeg." _error "File [$1] is unsupported by FFmpeg."
return return
fi fi
## The following 'eval' defines variables such as format_nb_streams
eval "$_buffer" eval "$_buffer"
unset _buffer unset _buffer
STREAM_TITLE="" STREAM_TITLE=""
if $OPT_REMOVE_TITLE; then if $OPT_REMOVE_TITLE; then
for i in $(seq 0 $(($format_nb_streams-1)) ); do for i in $(seq 0 $((format_nb_streams-1)) ); do
STREAM_TITLE="${STREAM_TITLE}-metadata:s:$i title= " STREAM_TITLE="${STREAM_TITLE}-metadata:s:$i title= "
done done
fi fi
@ -220,13 +221,13 @@ _transcode() {
## framerate. ## framerate.
STEP=${format_duration:-$streams_stream_0_duration} STEP=${format_duration:-$streams_stream_0_duration}
STEP="${STEP%%.*}" STEP="${STEP%%.*}"
STEP=$(($STEP/6)) STEP=$((STEP/6))
VIDEO_FILTER="-vf $(_cropvalue "$1" "$STEP")" VIDEO_FILTER="-vf $(_cropvalue "$1" "$STEP")"
if $OPT_CROPPREVIEW; then if $OPT_CROPPREVIEW; then
echo "Generating preview... " echo "Generating preview... "
for i in $(seq $STEP $STEP $((5*$STEP))); do for i in $(seq $STEP $STEP $((5*STEP))); do
ffmpeg -nostdin -v warning -y -ss $i -i "$1" \ ffmpeg -nostdin -v warning -y -ss "$i" -i "$1" \
-f image2 -vframes 1 $VIDEO_FILTER "${1%.*}-preview-$i-cropped.png" \ -f image2 -vframes 1 "$VIDEO_FILTER" "${1%.*}-preview-$i-cropped.png" \
-f image2 -vframes 1 "${1%.*}-preview-$i-uncropped.png" -f image2 -vframes 1 "${1%.*}-preview-$i-uncropped.png"
done done
fi fi
@ -255,25 +256,25 @@ EOF
if $OPT_2PASS; then if $OPT_2PASS; then
echo ":: FIRST PASS" echo ":: FIRST PASS"
ffmpeg -nostdin -y $SAMPLE -i "$1" \ ffmpeg -nostdin -y "$SAMPLE" -i "$1" \
$VIDEO_PARAM -pass 1 -tune film $VIDEO_FILTER \ "$VIDEO_PARAM" -pass 1 -tune film "$VIDEO_FILTER" \
$AUDIO_PARAM \ "$AUDIO_PARAM" \
-c:s copy \ -c:s copy \
-dn \ -dn \
-map 0 $STREAM_TITLE \ -map 0 "$STREAM_TITLE" \
$TC_VIDEO_OPT -f matroska /dev/null "$TC_VIDEO_OPT" -f matroska /dev/null
VIDEO_PARAM="$VIDEO_PARAM -pass 2 -tune film" VIDEO_PARAM="$VIDEO_PARAM -pass 2 -tune film"
echo echo
echo ":: SECOND PASS" echo ":: SECOND PASS"
fi fi
ffmpeg -nostdin $OVERWRITE -i "$1" \ ffmpeg -nostdin "$OVERWRITE" -i "$1" \
$VIDEO_PARAM $VIDEO_FILTER \ "$VIDEO_PARAM" "$VIDEO_FILTER" \
$AUDIO_PARAM \ "$AUDIO_PARAM" \
-c:s copy \ -c:s copy \
-dn \ -dn \
-map 0 $STREAM_TITLE \ -map 0 "$STREAM_TITLE" \
$SAMPLE $TC_VIDEO_OPT "$OUTPUT" "$SAMPLE" "$TC_VIDEO_OPT" "$OUTPUT"
$OPT_2PASS && rm -v ffmpeg2pass-0.log ffmpeg2pass-0.log.mbtree $OPT_2PASS && rm -v ffmpeg2pass-0.log ffmpeg2pass-0.log.mbtree

View File

@ -13,7 +13,7 @@ while IFS= read -r i; do
## Some formats (e.g. m2ts) will also return an "audio" channel in the ## Some formats (e.g. m2ts) will also return an "audio" channel in the
## "programs" section. We skip that. ## "programs" section. We skip that.
stream_count=$(ffprobe -v quiet "$i" -print_format flat=s=_ -show_entries stream=codec_type | grep -v '^programs' | cut -f2 -d= | grep -c "audio") stream_count=$(ffprobe -v quiet "$i" -print_format flat=s=_ -show_entries stream=codec_type | grep -v '^programs' | cut -f2 -d= | grep -c "audio")
if [ -n "$stream_count" ] && [ $stream_count -gt 1 ]; then if [ -n "$stream_count" ] && [ "$stream_count" -gt 1 ]; then
echo "$i" echo "$i"
fi fi
done <<EOF done <<EOF

View File

@ -26,7 +26,7 @@ check () {
check transmission-daemon transmission-remote-cli check transmission-daemon transmission-remote-cli
[ $(ps -U $USER | grep -c transmission-da) -eq 0 ] && transmission-daemon ps -U "$USER" | grep -q transmission-da || transmission-daemon
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
exec transmission-remote-cli exec transmission-remote-cli
else else

View File

@ -4,7 +4,7 @@
## Let's check if pacman completion is already loaded. If not, we parse the ## Let's check if pacman completion is already loaded. If not, we parse the
## pacman completion file. ## pacman completion file.
if [ $(type _pacman_action_none | grep -c "not found") -gt 0 ]; then if type _pacman_action_none | grep -q "not found"; then
source "/usr/share/zsh/site-functions/_pacman" source "/usr/share/zsh/site-functions/_pacman"
fi fi