scripts: Lint all scripts
parent
2ae294499a
commit
8f384c3d3f
|
@ -48,7 +48,7 @@ while getopts ":him:sv" opt; do
|
|||
done
|
||||
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
_usage "$0"
|
||||
|
|
|
@ -28,7 +28,7 @@ while getopts ":hd:" opt; do
|
|||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
_usage "$0"
|
||||
|
@ -41,7 +41,7 @@ if ! command -v readcd >/dev/null 2>&1; then
|
|||
fi
|
||||
|
||||
## 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
|
||||
# readcd f="$1.iso" -v retries=32 timeout=30 -s speed=16 -noerror
|
||||
|
|
|
@ -17,4 +17,4 @@ fi
|
|||
[ $# -ge 1 ] && COLUMN="$1" && shift
|
||||
[ $# -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}'
|
||||
|
|
|
@ -42,7 +42,7 @@ f2=$(echo "$cpuarray" | cut -f4 -d' ')
|
|||
f3=$(echo "$cpuarray" | cut -f5 -d' ')
|
||||
f4=$(echo "$cpuarray" | cut -f6 -d' ')
|
||||
|
||||
totalA=$(($f1+$f2+$f3+$f4))
|
||||
totalA=$((f1+f2+f3+f4))
|
||||
idleA=$f4
|
||||
sleep 1
|
||||
|
||||
|
@ -52,7 +52,7 @@ f2=$(echo "$cpuarray" | cut -f4 -d' ')
|
|||
f3=$(echo "$cpuarray" | cut -f5 -d' ')
|
||||
f4=$(echo "$cpuarray" | cut -f6 -d' ')
|
||||
|
||||
totalB=$(($f1+$f2+$f3+$f4))
|
||||
totalB=$((f1+f2+f3+f4))
|
||||
idleB=$f4
|
||||
|
||||
totaldiff=$((${totalB:-0}-${totalA:-0}))
|
||||
|
@ -60,5 +60,5 @@ totaldiff=$((${totalB:-0}-${totalA:-0}))
|
|||
if [ $totaldiff -eq 0 ]; then
|
||||
echo 0
|
||||
else
|
||||
echo "$((100 - 100 * ($idleB-$idleA) / $totaldiff ))"
|
||||
echo "$((100 - 100 * (idleB-idleA) / totaldiff))"
|
||||
fi
|
||||
|
|
|
@ -7,7 +7,7 @@ usage () {
|
|||
cat <<EOF
|
||||
Usage: ${1##*/}
|
||||
|
||||
Run `sessionclean' if available and $rawname the system.
|
||||
Run 'sessionclean' if available and $rawname the system.
|
||||
|
||||
EOF
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ command -v sessionclean >/dev/null 2>&1 && sessionclean
|
|||
|
||||
if command -v systemctl >/dev/null 2>&1; then
|
||||
$rawname
|
||||
then
|
||||
else
|
||||
## If you do not want to get prompted for your password, configure sudo
|
||||
## properly.
|
||||
sudo $rawname
|
||||
sudo "$rawname"
|
||||
fi
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
if [ $# -lt 1 ]; then
|
||||
cat<<EOF
|
||||
Usage: ${0##*/} FILE [FLAGS]
|
||||
Usage: ${0##*/} FILE [CFLAGS]
|
||||
|
||||
Simulate a C interpreter by compiling, executing and removing file in one run.
|
||||
EOF
|
||||
|
@ -10,21 +10,20 @@ EOF
|
|||
fi
|
||||
|
||||
[ -z "$CC" ] && CC=gcc
|
||||
FLAGS="-Wall -Wextra -Wshadow -pthread -lm -g3 -O0"
|
||||
INPUT="$1"
|
||||
|
||||
shift
|
||||
[ $# -ne 0 ] && FLAGS="$@"
|
||||
[ $# -eq 0 ] && set -- -Wall -Wextra -Wshadow -pthread -lm -g3 -O0
|
||||
|
||||
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
|
||||
## work.
|
||||
STATUS="$(set -o | awk '/shwordsplit / {print $2}')"
|
||||
[ "$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
|
||||
## was on before calling the function.
|
||||
|
|
|
@ -41,7 +41,7 @@ while getopts ":fhin:" opt; do
|
|||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
if $OPT_CUTFIRST; then
|
||||
sed $OPT_INPLACE -n "1,${OPT_LINES}!p" "$@"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
compat=""
|
||||
if [ $(awk --version | grep -c GNU) -gt 0 ]; then
|
||||
if awk --version | grep -q GNU; then
|
||||
# This is for hex-to-decimal conversion.
|
||||
compat="--non-decimal"
|
||||
fi
|
||||
|
|
|
@ -33,7 +33,7 @@ while getopts ":fhw" opt; do
|
|||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
_usage "$0"
|
||||
|
@ -47,22 +47,25 @@ if ! command -v realpath >/dev/null 2>&1; then
|
|||
fi
|
||||
|
||||
for i ; do
|
||||
## 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.
|
||||
[ ! -d "$i" ] && continue
|
||||
|
||||
## 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"
|
||||
## We strip "./" from find's listing since we don't need it. We could avoid
|
||||
## 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
|
||||
## 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 | \
|
||||
if $opt_file; then
|
||||
i="$(realpath -- "$i")"
|
||||
base="${i##*/}"
|
||||
[ ! -d "$i" ] && continue
|
||||
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"
|
||||
cat > "$output"
|
||||
else
|
||||
|
|
|
@ -27,7 +27,7 @@ while getopts :bc OPT; do
|
|||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
shift $((OPTIND - 1))
|
||||
if [ $# -eq 0 ]; then
|
||||
_usage "$0"
|
||||
exit 1
|
||||
|
|
|
@ -35,5 +35,5 @@ else
|
|||
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 "$@"
|
||||
|
|
|
@ -46,7 +46,7 @@ while getopts ":hfp" opt; do
|
|||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
_usage "$0"
|
||||
|
|
|
@ -33,7 +33,7 @@ while getopts ":hd:u:" opt; do
|
|||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
usage "$0"
|
||||
|
@ -46,5 +46,5 @@ if ! command -v git >/dev/null 2>&1; then
|
|||
fi
|
||||
|
||||
for i; do
|
||||
git clone git@$DOMAIN:/$USER/$i
|
||||
git clone "git@$DOMAIN:/$USER/$i"
|
||||
done
|
||||
|
|
|
@ -24,7 +24,7 @@ if [ "$(uname)" != "Linux" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
if [ $(id -u) -ne 0 ]; then
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
_usage
|
||||
exit 1
|
||||
fi
|
||||
|
|
|
@ -50,7 +50,7 @@ CHOICE="N"
|
|||
echo
|
||||
echo ":: Close all applications before cleaning."
|
||||
echo "==> Clean home? [y/N]"
|
||||
read CHOICE
|
||||
read -r CHOICE
|
||||
case "$CHOICE" in
|
||||
Y|y) ;;
|
||||
*)
|
||||
|
|
|
@ -9,13 +9,13 @@ _mount () {
|
|||
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}')"
|
||||
|
||||
if [ $(cdemu status | grep -c "$1") -gt 0 ]; then
|
||||
if cdemu status | grep -q "$1"; then
|
||||
echo "Image alredy mounted."
|
||||
return
|
||||
fi
|
||||
|
||||
if [ $DEVICE -gt $DEV_COUNT ]; then
|
||||
while [ $DEVICE -gt $DEV_COUNT ]; do
|
||||
if [ "$DEVICE" -gt "$DEV_COUNT" ]; then
|
||||
while [ "$DEVICE" -gt "$DEV_COUNT" ]; do
|
||||
cdemu add-device
|
||||
DEV_COUNT="$(cdemu device-mapping | awk 'END {print NR-3}')"
|
||||
done
|
||||
|
@ -23,13 +23,13 @@ _mount () {
|
|||
## WARNING: adding a new device takes some time. If we want to avoid errors,
|
||||
## we need to sleep until it is 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
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
cdemu load $DEVICE "$1"
|
||||
cdemu load "$DEVICE" "$1"
|
||||
if [ $? -ne 0 ] && command -v fuseiso >/dev/null 2>&1; then
|
||||
echo "Falling back to fuseiso."
|
||||
|
||||
|
@ -43,15 +43,15 @@ _mount () {
|
|||
fi
|
||||
|
||||
COUNT=0
|
||||
while [ -n "$(echo "$LIST" | grep "$FUSEROOT/drive-$COUNT" )" ]; do
|
||||
COUNT=$(($COUNT+1))
|
||||
while echo "$LIST" | grep -q "$FUSEROOT/drive-$COUNT"; do
|
||||
COUNT=$((COUNT+1))
|
||||
done
|
||||
|
||||
mkdir -p "$FUSEROOT/drive-$COUNT"
|
||||
fuseiso -p "$1" "$FUSEROOT/drive-$COUNT"
|
||||
|
||||
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
|
||||
## a kernel limitation.
|
||||
echo "Mounting..."
|
||||
|
@ -71,7 +71,7 @@ _umount () {
|
|||
udiskie-umount "$1"
|
||||
|
||||
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
|
||||
fusermount -u "$1"
|
||||
rmdir "$1" >/dev/null 2>&1
|
||||
|
@ -108,7 +108,7 @@ while getopts ":hu" opt; do
|
|||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
_usage "$0"
|
||||
|
|
|
@ -14,7 +14,7 @@ fi
|
|||
LSOFOUT="$(lsof|awk '{print $1}')"
|
||||
|
||||
while IFS= read -r i; do
|
||||
echo -n "$i "
|
||||
printf "%s " "$i"
|
||||
echo "$LSOFOUT" | grep -c "^$i"
|
||||
done<<EOF
|
||||
$(echo "$LSOFOUT" | sort -u)
|
||||
|
|
|
@ -35,7 +35,7 @@ while getopts ":fhr" opt; do
|
|||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
shift $((OPTIND - 1))
|
||||
if [ $# -eq 0 ]; then
|
||||
_usage "$0"
|
||||
exit 1
|
||||
|
@ -48,7 +48,7 @@ DEST="$(eval "echo \$$#")"
|
|||
count=0
|
||||
|
||||
for i ; do
|
||||
count=$(($count+1))
|
||||
count=$((count+1))
|
||||
[ $count -eq $# ] && break
|
||||
|
||||
while IFS= read -r FILE; do
|
||||
|
|
|
@ -24,28 +24,28 @@ else
|
|||
path="/dev/shm/netspeed"
|
||||
time=$(date +%s)
|
||||
|
||||
read rx < /sys/class/net/${interface}/statistics/rx_bytes
|
||||
read tx < /sys/class/net/${interface}/statistics/tx_bytes
|
||||
read -r rx < /sys/class/net/"$interface"/statistics/rx_bytes
|
||||
read -r tx < /sys/class/net/"$interface"/statistics/tx_bytes
|
||||
|
||||
if [ ! -f "$path" ]; then
|
||||
echo "$time $rx $tx" > "$path"
|
||||
chmod 0666 "$path"
|
||||
fi
|
||||
|
||||
read time_old rx_old tx_old < "$path"
|
||||
read -r time_old rx_old tx_old < "$path"
|
||||
echo "$time $rx $tx" > "$path"
|
||||
time_diff=$(($time - $time_old))
|
||||
time_diff=$((time - time_old))
|
||||
|
||||
if [ "$time_diff" -gt 0 ]; then
|
||||
rx_rate=$((($rx - $rx_old) / $time_diff))
|
||||
tx_rate=$((($tx - $tx_old) / $time_diff))
|
||||
rx_rate=$(((rx - rx_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=M
|
||||
[ "$rx_rate" -gt 1024 ] && rx_rate=$((rx_rate / 1024)) && rx_unit=K
|
||||
[ "$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=M
|
||||
[ "$tx_rate" -gt 1024 ] && tx_rate=$((tx_rate / 1024)) && tx_unit=K
|
||||
[ "$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
|
||||
|
|
|
@ -10,4 +10,4 @@ description="$3"
|
|||
SEP=" "
|
||||
OUTPUT="$XDG_CONFIG_HOME/newsbeuter/news_starred"
|
||||
|
||||
echo -e "${url}$SEP${title}$SEP${description}" >> "$OUTPUT"
|
||||
echo "${url}$SEP${title}$SEP${description}" >> "$OUTPUT"
|
||||
|
|
|
@ -34,7 +34,7 @@ while getopts ":hmqe" opt; do
|
|||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Missing argument."
|
||||
|
|
|
@ -128,7 +128,7 @@ while getopts ":ahnstV" opt; do
|
|||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
## All-packages 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
|
||||
## 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 "'")
|
||||
[ -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 ;}
|
||||
|
||||
# vim: set noet:
|
||||
|
|
|
@ -56,7 +56,7 @@ while getopts ":cfhin" opt; do
|
|||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
_usage "$0"
|
||||
|
@ -76,7 +76,6 @@ for i ; do
|
|||
esac
|
||||
DIRNAME="${i%/*}"
|
||||
BASENAME="${i##*/}"
|
||||
EXTNAME="${BASENAME##*.}"
|
||||
BASENAME="${BASENAME%.*}"
|
||||
OUTPUT="$DIRNAME/$BASENAME-compressed.pdf"
|
||||
if [ -e "$OUTPUT" ] && ! $OPT_OVERWRITE; then
|
||||
|
@ -86,7 +85,7 @@ for i ; do
|
|||
|
||||
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
|
||||
rm -f "$i"
|
||||
mv "$OUTPUT" "$i"
|
||||
|
|
|
@ -13,4 +13,4 @@ if [ ! -f "$1" ]; then
|
|||
echo "$1 is not a valid file."
|
||||
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"
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
## Create lists of system- and TeX Live packages.
|
||||
|
||||
## Variables
|
||||
HOST="$(hostname)"
|
||||
PKG_ROOT="$HOME/.pkg"
|
||||
mkdir -p "$PKG_ROOT"
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ while getopts ":ih" opt; do
|
|||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
if [ $# -lt 2 ]; then
|
||||
_usage "$0"
|
||||
|
|
|
@ -16,7 +16,7 @@ DMASK=$(umask -S)
|
|||
[ -z "$GID" ] && GID=$(id -g)
|
||||
|
||||
for i ; do
|
||||
find "$i" -exec chown -R ${UID}:${GID} {} \;
|
||||
find "$i" -type d -exec chmod ${DMASK} {} \;
|
||||
find "$i" -type f -exec chmod ${FMASK} {} \;
|
||||
find "$i" -exec chown -R "$UID:$GID" {} \;
|
||||
find "$i" -type d -exec chmod "$DMASK" {} \;
|
||||
find "$i" -type f -exec chmod "$FMASK" {} \;
|
||||
done
|
||||
|
|
|
@ -9,4 +9,4 @@ EOF
|
|||
exit
|
||||
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"
|
||||
|
|
|
@ -24,11 +24,9 @@ fi
|
|||
for j; do
|
||||
while IFS= read -r i; do
|
||||
BUFFER="$(mediainfo "$i")"
|
||||
[ -n "$(echo "$BUFFER" | grep "Bit rate mode *: Constant")" ] && echo "$i : CBR"
|
||||
|
||||
[ -n "$(echo "$BUFFER" | grep "Cover *: Yes")" ] && echo "$i : Cover"
|
||||
|
||||
[ -n "$(echo "$BUFFER" | grep "Track name/Position *: 0+")" ] && echo "$i : Leading zeros"
|
||||
echo "$BUFFER" | grep -q "Bit rate mode *: Constant" && echo "$i : CBR"
|
||||
echo "$BUFFER" | grep -q "Cover *: Yes" && echo "$i : Cover"
|
||||
echo "$BUFFER" | grep -q "Track name/Position *: 0+" && echo "$i : Leading zeros"
|
||||
done <<EOF
|
||||
$(find "$j" \( \
|
||||
-iname '*.mp3' -o \
|
||||
|
|
|
@ -20,29 +20,27 @@ for i ; do
|
|||
while IFS= read -r j; do
|
||||
CODING=$(file "$j")
|
||||
|
||||
if [ -n "$(echo $CODING | grep 'ISO-8859')" ]; then
|
||||
case "$CODING" in
|
||||
*ISO-8859*)
|
||||
echo "ISO-8859: [$j]"
|
||||
recode latin1..utf-8 "$j"
|
||||
|
||||
elif [ -n "$(echo $CODING | grep 'Non-ISO extended-ASCII')" ]; then
|
||||
recode latin1..utf-8 "$j";;
|
||||
*'Non-ISO extended-ASCII'*)
|
||||
echo "cp1252: [$j]"
|
||||
recode cp1252..utf-8 "$j"
|
||||
|
||||
elif [ -n "$(echo $CODING | grep 'UTF-16 Unicode text')" ]; then
|
||||
recode cp1252..utf-8 "$j";;
|
||||
*'UTF-16 Unicode text'*)
|
||||
echo "UTF-16: [$j]"
|
||||
recode utf-16..utf-8 "$j"
|
||||
|
||||
elif [ -n "$(echo $CODING | grep 'UTF-8 Unicode (with BOM)')" ]; then
|
||||
recode utf-16..utf-8 "$j";;
|
||||
*'UTF-8 Unicode (with BOM)'*)
|
||||
echo "UTF-8 BOM: [$j]"
|
||||
ex -sc '1s/^.//|xit' "$j"
|
||||
ex -sc '1s/^.//|xit' "$j";;
|
||||
## The following commands are funny alternatives, but are completely
|
||||
## overkill.
|
||||
# dd iflag=skip_bytes 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
|
||||
fi
|
||||
esac
|
||||
|
||||
if [ -n "$(echo $CODING | grep 'CRLF')" ]; then
|
||||
if echo "$CODING" | grep -q 'CRLF'; then
|
||||
echo "CRLF: [$j]"
|
||||
ex -sc '%s/
//g|xit' "$j"
|
||||
fi
|
||||
|
|
|
@ -18,7 +18,7 @@ fi
|
|||
|
||||
for i ; do
|
||||
while IFS= read -r j; do
|
||||
echo -n "# "
|
||||
printf "# "
|
||||
file "$j"
|
||||
grep -m1 "\`" "$j"
|
||||
grep -m1 "´" "$j"
|
||||
|
|
|
@ -128,7 +128,7 @@ while getopts ":a:b:cCd:fho:pPq:sS:t" opt; do
|
|||
s)
|
||||
SAMPLE="-ss 60 -t 300" ;;
|
||||
S)
|
||||
SAMPLE="-ss 60 -t $((60*$OPTARG))" ;;
|
||||
SAMPLE="-ss 60 -t $((60*OPTARG))" ;;
|
||||
t)
|
||||
OPT_REMOVE_TITLE=true ;;
|
||||
\?)
|
||||
|
@ -137,7 +137,7 @@ while getopts ":a:b:cCd:fho:pPq:sS:t" opt; do
|
|||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
shift $((OPTIND - 1))
|
||||
if [ $# -eq 0 ]; then
|
||||
_usage "$0"
|
||||
exit
|
||||
|
@ -156,8 +156,8 @@ _highfreq() {
|
|||
## Return the crop values as ffmpeg output them.
|
||||
_cropvalue() {
|
||||
local step=$2
|
||||
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
|
||||
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
|
||||
done | _highfreq
|
||||
}
|
||||
|
||||
|
@ -169,24 +169,24 @@ _cropvalue() {
|
|||
_audiobitrate() {
|
||||
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.
|
||||
[ "$(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 non-empty and a positive number.
|
||||
bitrate=$(( $bitrate / 1000))
|
||||
bitrate=$((bitrate / 1000))
|
||||
else
|
||||
bitrate="$AUDIO_DEFAULT_RATE"
|
||||
fi
|
||||
if [ "$bitrate" -le 0 ] || \
|
||||
[ "$AUDIO_CODEC" = "$(eval echo \$streams_stream_${i}_codec_name)" ] || \
|
||||
[ "$AUDIO_CODEC" = "lib$(eval echo \$streams_stream_${i}_codec_name)" ]; then
|
||||
printf -- "-c:%s copy " $i
|
||||
[ "$AUDIO_CODEC" = "$(eval echo \$streams_stream_"$i"_codec_name)" ] || \
|
||||
[ "$AUDIO_CODEC" = "lib$(eval echo \$streams_stream_"$i"_codec_name)" ]; then
|
||||
printf -- "-c:%s copy " "$i"
|
||||
else
|
||||
[ $bitrate -gt 500 ] && bitrate=500
|
||||
printf -- "-c:%s %s -b:%s %sk " $i "$AUDIO_CODEC" $i "$bitrate"
|
||||
[ "$bitrate" -gt 500 ] && bitrate=500
|
||||
printf -- "-c:%s %s -b:%s %sk " "$i" "$AUDIO_CODEC" "$i" "$bitrate"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
@ -202,12 +202,13 @@ _transcode() {
|
|||
_error "File [$1] is unsupported by FFmpeg."
|
||||
return
|
||||
fi
|
||||
## The following 'eval' defines variables such as format_nb_streams
|
||||
eval "$_buffer"
|
||||
unset _buffer
|
||||
|
||||
STREAM_TITLE=""
|
||||
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= "
|
||||
done
|
||||
fi
|
||||
|
@ -220,13 +221,13 @@ _transcode() {
|
|||
## framerate.
|
||||
STEP=${format_duration:-$streams_stream_0_duration}
|
||||
STEP="${STEP%%.*}"
|
||||
STEP=$(($STEP/6))
|
||||
STEP=$((STEP/6))
|
||||
VIDEO_FILTER="-vf $(_cropvalue "$1" "$STEP")"
|
||||
if $OPT_CROPPREVIEW; then
|
||||
echo "Generating preview... "
|
||||
for i in $(seq $STEP $STEP $((5*$STEP))); do
|
||||
ffmpeg -nostdin -v warning -y -ss $i -i "$1" \
|
||||
-f image2 -vframes 1 $VIDEO_FILTER "${1%.*}-preview-$i-cropped.png" \
|
||||
for i in $(seq $STEP $STEP $((5*STEP))); do
|
||||
ffmpeg -nostdin -v warning -y -ss "$i" -i "$1" \
|
||||
-f image2 -vframes 1 "$VIDEO_FILTER" "${1%.*}-preview-$i-cropped.png" \
|
||||
-f image2 -vframes 1 "${1%.*}-preview-$i-uncropped.png"
|
||||
done
|
||||
fi
|
||||
|
@ -255,25 +256,25 @@ EOF
|
|||
|
||||
if $OPT_2PASS; then
|
||||
echo ":: FIRST PASS"
|
||||
ffmpeg -nostdin -y $SAMPLE -i "$1" \
|
||||
$VIDEO_PARAM -pass 1 -tune film $VIDEO_FILTER \
|
||||
$AUDIO_PARAM \
|
||||
ffmpeg -nostdin -y "$SAMPLE" -i "$1" \
|
||||
"$VIDEO_PARAM" -pass 1 -tune film "$VIDEO_FILTER" \
|
||||
"$AUDIO_PARAM" \
|
||||
-c:s copy \
|
||||
-dn \
|
||||
-map 0 $STREAM_TITLE \
|
||||
$TC_VIDEO_OPT -f matroska /dev/null
|
||||
-map 0 "$STREAM_TITLE" \
|
||||
"$TC_VIDEO_OPT" -f matroska /dev/null
|
||||
VIDEO_PARAM="$VIDEO_PARAM -pass 2 -tune film"
|
||||
echo
|
||||
echo ":: SECOND PASS"
|
||||
fi
|
||||
|
||||
ffmpeg -nostdin $OVERWRITE -i "$1" \
|
||||
$VIDEO_PARAM $VIDEO_FILTER \
|
||||
$AUDIO_PARAM \
|
||||
ffmpeg -nostdin "$OVERWRITE" -i "$1" \
|
||||
"$VIDEO_PARAM" "$VIDEO_FILTER" \
|
||||
"$AUDIO_PARAM" \
|
||||
-c:s copy \
|
||||
-dn \
|
||||
-map 0 $STREAM_TITLE \
|
||||
$SAMPLE $TC_VIDEO_OPT "$OUTPUT"
|
||||
-map 0 "$STREAM_TITLE" \
|
||||
"$SAMPLE" "$TC_VIDEO_OPT" "$OUTPUT"
|
||||
|
||||
$OPT_2PASS && rm -v ffmpeg2pass-0.log ffmpeg2pass-0.log.mbtree
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ while IFS= read -r i; do
|
|||
## Some formats (e.g. m2ts) will also return an "audio" channel in the
|
||||
## "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")
|
||||
if [ -n "$stream_count" ] && [ $stream_count -gt 1 ]; then
|
||||
if [ -n "$stream_count" ] && [ "$stream_count" -gt 1 ]; then
|
||||
echo "$i"
|
||||
fi
|
||||
done <<EOF
|
||||
|
|
|
@ -26,7 +26,7 @@ check () {
|
|||
|
||||
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
|
||||
exec transmission-remote-cli
|
||||
else
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
## Let's check if pacman completion is already loaded. If not, we parse the
|
||||
## 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"
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in New Issue