From 9857145fb158c4e232643ec4b25114668152bd4d Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Wed, 12 Nov 2014 16:15:39 +0100 Subject: [PATCH] scripts: Reformat with tabs and more consistent style --- .scripts/.tc-video-custom.in | 67 ++++---- .scripts/abs-wrapper | 247 ++++++++++++++-------------- .scripts/archive | 120 +++++++------- .scripts/asciify | 108 ++++++------- .scripts/blind-append | 16 +- .scripts/browser-autostart | 4 +- .scripts/bsdman | 23 ++- .scripts/clonecd | 33 ++-- .scripts/colsum | 4 +- .scripts/cpuusage | 12 +- .scripts/creboot | 28 ++-- .scripts/crun | 4 +- .scripts/csv2abook.awk | 71 ++++----- .scripts/currency | 8 +- .scripts/cutlines | 39 +++-- .scripts/cxev | 22 +-- .scripts/dataindex | 76 +++++---- .scripts/echopath | 20 +-- .scripts/einfo | 16 +- .scripts/elisp | 35 ++-- .scripts/em | 18 +-- .scripts/extract | 94 ++++++----- .scripts/git-check | 19 ++- .scripts/git-compare | 4 +- .scripts/git-get | 39 +++-- .scripts/git-sync | 31 ++-- .scripts/gnac | 4 +- .scripts/greader2plain.awk | 8 +- .scripts/hdmi-switch | 25 ++- .scripts/homeclean | 94 +++++------ .scripts/homeinit | 116 +++++++------- .scripts/hsync | 120 +++++++------- .scripts/imagemount | 168 ++++++++++--------- .scripts/lsofstat | 10 +- .scripts/ltx | 10 +- .scripts/mover | 65 ++++---- .scripts/musawk | 52 +++--- .scripts/netinit | 131 ++++++++------- .scripts/netmap | 12 +- .scripts/netscan | 4 +- .scripts/netspeed | 12 +- .scripts/pacfiles | 35 ++-- .scripts/pacman-diff | 44 +++-- .scripts/pacsize | 36 ++--- .scripts/pdfcompress | 87 +++++----- .scripts/pdfextract | 2 +- .scripts/pdfresize | 3 +- .scripts/pgex | 12 +- .scripts/pkggen | 24 +-- .scripts/prepend | 8 +- .scripts/probe | 8 +- .scripts/random | 4 +- .scripts/renamelower | 20 +-- .scripts/renamelowerrec | 10 +- .scripts/renameswap | 14 +- .scripts/replace | 50 +++--- .scripts/rsync-preview | 4 +- .scripts/sanitize | 10 +- .scripts/sessionclean | 14 +- .scripts/strip-comments | 31 ++-- .scripts/switchdriver | 64 ++++---- .scripts/task2org.awk | 95 ++++++----- .scripts/tc-audio-scan | 27 ++-- .scripts/tc-text-2utf8 | 56 +++---- .scripts/tc-text-scan | 20 +-- .scripts/tc-video-custom | 31 ++-- .scripts/tc-video-generic | 301 +++++++++++++++++------------------ .scripts/texclean | 34 ++-- .scripts/texi2latex | 6 +- .scripts/translate | 133 ++++++++-------- .scripts/trc | 31 ++-- .scripts/wget-batch | 4 +- .scripts/winefps | 15 +- .scripts/zshcd | 20 +-- 74 files changed, 1592 insertions(+), 1650 deletions(-) diff --git a/.scripts/.tc-video-custom.in b/.scripts/.tc-video-custom.in index 30831906..99a62f30 100644 --- a/.scripts/.tc-video-custom.in +++ b/.scripts/.tc-video-custom.in @@ -1,8 +1,7 @@ #!/bin/sh -_printhelp() -{ - cat </dev/null 2>&1; then - echo >&2 "'ffmpeg' not found in PATH. Exiting." - exit 1 + echo >&2 "'ffmpeg' not found in PATH. Exiting." + exit 1 fi -_transcode () -{ - ## You can choose here to process all files at the same time. Useful if you - ## need to remux streams or to concatenate. - # ffmpeg -i ###FILELIST \ - ffmpeg -nostdin -i "$@" \ - -c:v libx264 -preset slow -crf 20 \ - -c:a libvorbis -b:a 192k -ac 2 \ - -c:s copy \ - -map 0 \ - $SAMPLE \ - "${1%.*}-$(date '+%F-%H%M%S').mkv" +_transcode () { + ## You can choose here to process all files at the same time. Useful if you + ## need to remux streams or to concatenate. + # ffmpeg -i ###FILELIST \ + ffmpeg -nostdin -i "$@" \ + -c:v libx264 -preset slow -crf 20 \ + -c:a libvorbis -b:a 192k -ac 2 \ + -c:s copy \ + -map 0 \ + $SAMPLE \ + "${1%.*}-$(date '+%F-%H%M%S').mkv" } set -- ###FILENAMES ## Choose to process all files one after another. for i ; do - _transcode "$i" + _transcode "$i" done ## Or all files at the same time. You have to change the ffmpeg input in the diff --git a/.scripts/abs-wrapper b/.scripts/abs-wrapper index 27dba29b..f0ca03b1 100755 --- a/.scripts/abs-wrapper +++ b/.scripts/abs-wrapper @@ -4,9 +4,8 @@ UPSTREAM_SOURCE="srcdir" ## End of user config -_printhelp () -{ - cat </dev/null; then - echo "You need makepkg to run this script." - exit 1 + echo "You need makepkg to run this script." + exit 1 fi HAS_ABS=false @@ -111,123 +124,115 @@ command -v abs >/dev/null && HAS_ABS=true command -v yaourt >/dev/null && HAS_YAOURT=true if ! $HAS_ABS && ! $HAS_YAOURT; then - echo "Please install either an ABS-tree or yaourt." - exit 1 + echo "Please install either an ABS-tree or yaourt." + exit 1 fi if $HAS_ABS && [ -f "/etc/abs.conf" ]; then - . "/etc/abs.conf" - [ "$ABSROOT" = "" ] && ABSROOT="/var/abs/" + . "/etc/abs.conf" + [ "$ABSROOT" = "" ] && ABSROOT="/var/abs/" fi ################################################################################ -abs_pkgbuild () -{ - pacman -Si $1 >/dev/null 2>&1 - if [ $? -eq 0 ] && $HAS_ABS && [ -d "$ABSROOT" ]; then - cp -r /var/abs/*/$1 . - else - yaourt -G "$1" --noconfirm - fi +abs_pkgbuild () { + pacman -Si $1 >/dev/null 2>&1 + if [ $? -eq 0 ] && $HAS_ABS && [ -d "$ABSROOT" ]; then + cp -r /var/abs/*/$1 . + else + yaourt -G "$1" --noconfirm + fi } -abs_source () -{ - (cd "$1" && \ - mkdir -p "$UPSTREAM_SOURCE" && \ - SRCDEST="$UPSTREAM_SOURCE" makepkg -o) +abs_source () { + (cd "$1" && \ + mkdir -p "$UPSTREAM_SOURCE" && \ + SRCDEST="$UPSTREAM_SOURCE" makepkg -o) } ## TODO: unused function. Add 'build all deps from source' parameter? -abs_builddeps () -{ - DEPLIST=$(awk -F"'" '/^(make)?depends *= *\(/,/\)/ {for (n=2 ; n/dev/null) +abs_mrproper () { + (cd "$1" && \ + echo "Removing archives." && \ + rm -v *.tar.gz *.tar.xz *.tar.bz *.tar.bz2 *.tgz *.txz *.tbz *.tbz2 2>/dev/null) } -abs_install () -{ - sudo sh -c ' - (cd "$0" && pacman '$PACMAN_OPT' --noconfirm -U *.pkg.tar.xz) - for i; do - (cd "$i" && pacman '$PACMAN_OPT' --noconfirm -U *.pkg.tar.xz) - done +abs_install () { + sudo sh -c ' + (cd "$0" && pacman '$PACMAN_OPT' --noconfirm -U *.pkg.tar.xz) + for i; do + (cd "$i" && pacman '$PACMAN_OPT' --noconfirm -U *.pkg.tar.xz) + done ' "$@" } for i ; do - echo "==> Processing $i." + echo "==> Processing $i." - ## Fetch PKGBUILD. - if [ ! -f "$i/PKGBUILD" ] || $OPT_FORCE; then - abs_pkgbuild "$i" - fi + ## Fetch PKGBUILD. + if [ ! -f "$i/PKGBUILD" ] || $OPT_FORCE; then + abs_pkgbuild "$i" + fi - ## Skip because $i does not exist. - [ ! -d "$i" ] && continue + ## Skip because $i does not exist. + [ ! -d "$i" ] && continue - ## Fetch source code. - if $OPT_SOURCE; then - abs_source "$i" - fi + ## Fetch source code. + if $OPT_SOURCE; then + abs_source "$i" + fi - ## Build. - if $OPT_BUILD || ($OPT_INSTALL && [ ! -f $i/*.pkg.tar.xz ]); then - abs_build "$i" - fi + ## Build. + if $OPT_BUILD || ($OPT_INSTALL && [ ! -f $i/*.pkg.tar.xz ]); then + abs_build "$i" + fi - ## Clean build folder. - if $OPT_CLEAN; then - abs_clean "$i" - fi + ## Clean build folder. + if $OPT_CLEAN; then + abs_clean "$i" + fi - ## Remove archives. - if $OPT_MRPROPER; then - abs_mrproper "$i" - fi + ## Remove archives. + if $OPT_MRPROPER; then + abs_mrproper "$i" + fi done ## Install packages. We put the install part outside the loop so that we prompt ## for password one time only. if $OPT_INSTALL; then - abs_install "$@" + abs_install "$@" fi diff --git a/.scripts/archive b/.scripts/archive index 4745e175..1ed9cdb1 100755 --- a/.scripts/archive +++ b/.scripts/archive @@ -1,8 +1,7 @@ #!/bin/sh -_printhelp() -{ - cat </dev/null 2>&1; then - echo >&2 "'realpath' not found in PATH. Exiting." - exit 1 + echo >&2 "'realpath' not found in PATH. Exiting." + exit 1 fi -_archive() -{ - ## Only one input entry: use it as base name for the archive. - if [ $# -eq 1 ]; then - REALPATH="$(realpath "$1")" - OUTFILE="${REALPATH##*/}-$(date +%F-%H%M%S).tar${ARCEXT}" - else - OUTFILE="${PWD##*/}-$(date +%F-%H%M%S).tar${ARCEXT}" - fi +_archive () { + ## Only one input entry: use it as base name for the archive. + if [ $# -eq 1 ]; then + REALPATH="$(realpath "$1")" + OUTFILE="${REALPATH##*/}-$(date +%F-%H%M%S).tar${ARCEXT}" + else + OUTFILE="${PWD##*/}-$(date +%F-%H%M%S).tar${ARCEXT}" + fi - REALPWD="$(realpath "$PWD")" - for i; do - REALPATH="$(realpath "$i")" + REALPWD="$(realpath "$PWD")" + for i; do + REALPATH="$(realpath "$i")" - ## Check if one of the arguments is current folder. We need to make sure the - ## archive is not created in an input folder, otherwise it will include - ## itself. - if [ "$REALPATH" = "$REALPWD" ]; then - OUTPATH="$(realpath "$REALPWD/..")" - break - fi - done + ## Check if one of the arguments is current folder. We need to make sure the + ## archive is not created in an input folder, otherwise it will include + ## itself. + if [ "$REALPATH" = "$REALPWD" ]; then + OUTPATH="$(realpath "$REALPWD/..")" + break + fi + done - if [ ! -w "$OUTPATH" ]; then - echo "[$OUTPATH] is not writable. Exiting." - return - fi + if [ ! -w "$OUTPATH" ]; then + echo "[$OUTPATH] is not writable. Exiting." + return + fi - echo "==> [$OUTPATH/$OUTFILE]" - for i; do - REALPATH="$(realpath "$i")" - echo "${REALPATH}" >&2 - echo "-C '${REALPATH%/*}'" - echo "${REALPATH##*/}" - done | tar $OPTIONS -${ARCOPT}cf "$OUTPATH/$OUTFILE" -T - + echo "==> [$OUTPATH/$OUTFILE]" + for i; do + REALPATH="$(realpath "$i")" + echo "${REALPATH}" >&2 + echo "-C '${REALPATH%/*}'" + echo "${REALPATH##*/}" + done | tar $OPTIONS -${ARCOPT}cf "$OUTPATH/$OUTFILE" -T - } if $OPT_SPLIT; then - for j ; do - _archive "$j" - done + for j ; do + _archive "$j" + done else - _archive "$@" + _archive "$@" fi diff --git a/.scripts/asciify b/.scripts/asciify index 5cc65c33..548bdfd0 100755 --- a/.scripts/asciify +++ b/.scripts/asciify @@ -1,7 +1,7 @@ #!/bin/sh if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then - cat <=/g' \ - -e 's/[±]/+\/-/g' \ - -e 's/[≠]/!=/g' \ - -e 's/[⋅]/./g' \ - -e 's/[×]/x/g' \ - -e 's/[÷]/\//g' \ - -e 's/[↓]/|/g' \ - -e 's/[↑]/^/g' \ - -e 's/[←]/<=/g' \ - -e 's/[→]/=>/g' \ - "$@" + -e 's/[áàâä]/a/g' \ + -e 's/[éèêë]/e/g' \ + -e 's/[íìîï]/i/g' \ + -e 's/[óòôö]/o/g' \ + -e 's/[úùûü]/u/g' \ + -e 's/[ýỳŷÿ]/y/g' \ + -e 's/[ÁÀÂÄ]/A/g' \ + -e 's/[ÉÈÊË]/E/g' \ + -e 's/[ÍÌÎÏ]/I/g' \ + -e 's/[ÓÒÔÖ]/O/g' \ + -e 's/[ÚÙÛÜ]/U/g' \ + -e 's/[ÝỲŶŸ]/Y/g' \ + -e 's/[ñ]/n/g' \ + -e 's/[œ]/oe/g' \ + -e 's/[Œ]/Oe/g' \ + -e 's/[æ]/ae/g' \ + -e 's/[Æ]/Ae/g' \ + -e 's/[ç]/c/g' \ + -e 's/[Ç]/C/g' \ + -e 's/[ß]/ss/g' \ + -e 's/[«»„“”‚‘’]/"/g' \ + -e 's/[©]/(C)/g' \ + -e 's/[®]/(R)/g' \ + -e 's/[™]/(TM)/g' \ + -e 's/[¥]/Y/g' \ + -e 's/[Ð]/D/g' \ + -e 's/[ŀ]/l/g' \ + -e 's/[Ŀ]/L/g' \ + -e 's/[€]/euro/g' \ + -e 's/[¢]/cent/g' \ + -e 's/[£]/pound/g' \ + -e 's/[µ]/mu/g' \ + -e 's/[²]/^2/g' \ + -e 's/[³]/^3/g' \ + -e 's/[¡]/!/g' \ + -e 's/[¿]/?/g' \ + -e 's/[–‑]/-/g' \ + -e 's/[…]/.../g' \ + -e 's/[≤]/<=/g' \ + -e 's/[≥]/>=/g' \ + -e 's/[±]/+\/-/g' \ + -e 's/[≠]/!=/g' \ + -e 's/[⋅]/./g' \ + -e 's/[×]/x/g' \ + -e 's/[÷]/\//g' \ + -e 's/[↓]/|/g' \ + -e 's/[↑]/^/g' \ + -e 's/[←]/<=/g' \ + -e 's/[→]/=>/g' \ + "$@" diff --git a/.scripts/blind-append b/.scripts/blind-append index 6c1ccf09..e9833637 100755 --- a/.scripts/blind-append +++ b/.scripts/blind-append @@ -1,7 +1,7 @@ #!/usr/bin/env zsh if [ $# -gt 2 ] || [ $# -lt 1 ] || [ "$1" = "-h" ]; then - cat <> "$FILE" - echo "Secret appended to ${FILE} at the end." - exit + echo "$DUMMY" >> "$FILE" + echo "Secret appended to ${FILE} at the end." + exit fi if [ $# -eq 1 ]; then - echo "$DUMMY" >> "$FILE" + echo "$DUMMY" >> "$FILE" else - ex -sc "%s/${STRING}/${STRING}${DUMMY}/g|xit" "${FILE}" + ex -sc "%s/${STRING}/${STRING}${DUMMY}/g|xit" "${FILE}" fi echo "Secret appended to ${FILE}." diff --git a/.scripts/browser-autostart b/.scripts/browser-autostart index a2e6e3d8..47904f51 100755 --- a/.scripts/browser-autostart +++ b/.scripts/browser-autostart @@ -5,8 +5,8 @@ ## then exit to shell, without closing the terminal. if [ -z "$TERMCMD" ]; then - echo 'TERMCMD not set. Exiting.' - exit + echo 'TERMCMD not set. Exiting.' + exit fi export BROWSER_AUTOSTART=true diff --git a/.scripts/bsdman b/.scripts/bsdman index ebf3537d..fa51c857 100755 --- a/.scripts/bsdman +++ b/.scripts/bsdman @@ -1,37 +1,36 @@ #!/bin/sh if [ "${0##*/}" = "obsdman" ]; then - OS=OpenBSD - DOMAIN="http://www.openbsd.org/cgi-bin" - MANPATH="OpenBSD+Current" + OS=OpenBSD + DOMAIN="http://www.openbsd.org/cgi-bin" + MANPATH="OpenBSD+Current" else - OS=FreeBSD - DOMAIN="http://www.freebsd.org/cgi" - MANPATH="FreeBSD+10-current" + OS=FreeBSD + DOMAIN="http://www.freebsd.org/cgi" + MANPATH="FreeBSD+10-current" fi if [ $# -eq 0 ] || [ "$1" = "-h" ]; then - cat</dev/null 2>&1; then - AGENT="wget -q -O - " + AGENT="wget -q -O - " fi $AGENT "$DOMAIN/man.cgi?query=$PAGE&apropos=0&sektion=$SECTION&manpath=$MANPATH&arch=default&format=ascii" | less - diff --git a/.scripts/clonecd b/.scripts/clonecd index 48527ff1..65d12c1b 100755 --- a/.scripts/clonecd +++ b/.scripts/clonecd @@ -1,8 +1,7 @@ #!/bin/sh -_printhelp () -{ - cat</dev/null 2>&1; then - echo >&2 "'readcd' not found in PATH. Exiting." - exit 1 + echo >&2 "'readcd' not found in PATH. Exiting." + exit 1 fi ## Fast? diff --git a/.scripts/colsum b/.scripts/colsum index 7c9ba798..911c0a16 100755 --- a/.scripts/colsum +++ b/.scripts/colsum @@ -4,14 +4,14 @@ COLUMN="1" FORMAT="TOTAL: %s\n" if [ "$1" = "-h" ]; then - cat</dev/null 2>&1 && sessionclean if command -v systemctl >/dev/null 2>&1; then - $rawname + $rawname then - ## If you do not want to get prompted for your password, configure sudo - ## properly. - sudo $rawname + ## If you do not want to get prompted for your password, configure sudo + ## properly. + sudo $rawname fi diff --git a/.scripts/crun b/.scripts/crun index 2ea67412..785e3ba1 100755 --- a/.scripts/crun +++ b/.scripts/crun @@ -1,12 +1,12 @@ #!/bin/sh if [ $# -lt 1 ]; then - cat<' '/^1 / {print value * substr($3, 1, index($3," "))}' - - + awk -v value=$1 -F '<|>' '/^1 / {print value * substr($3, 1, index($3," "))}' diff --git a/.scripts/cutlines b/.scripts/cutlines index 10f39acd..64511380 100755 --- a/.scripts/cutlines +++ b/.scripts/cutlines @@ -1,8 +1,7 @@ #!/bin/sh -_printhelp () -{ - cat</dev/null 2>&1; then - echo "'realpath' not found in PATH. Exiting." >&2 - exit 1 + echo "'realpath' not found in PATH. Exiting." >&2 + exit 1 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. + ## 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. - ## 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" + ## 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" - ## 'LC_ALL=C sort' is required to make sure to output is consistent across - ## different systems. - (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" - echo "$output" - cat > "$output" - else - cat - fi + ## 'LC_ALL=C sort' is required to make sure to output is consistent across + ## different systems. + (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" + echo "$output" + cat > "$output" + else + cat + fi done - diff --git a/.scripts/echopath b/.scripts/echopath index 3697e865..091d293e 100755 --- a/.scripts/echopath +++ b/.scripts/echopath @@ -1,29 +1,29 @@ #!/bin/sh if [ "$1" = "-h" ]; then - cat</dev/null 2>&1; then - echo "'$i' not found in PATH. Exiting." >&2 - exit 1 - fi - done +check() { + for i ; do + if ! command -v $i >/dev/null 2>&1; then + echo "'$i' not found in PATH. Exiting." >&2 + exit 1 + fi + done } + check emacs realpath [ -f "$1" ] && node="$(realpath "$1")" || node="$1" diff --git a/.scripts/elisp b/.scripts/elisp index 381d34d1..5e06d5f3 100755 --- a/.scripts/elisp +++ b/.scripts/elisp @@ -1,8 +1,7 @@ #!/bin/sh -_printhelp () -{ - cat</dev/null 2>&1; then - echo 'emacs not found in PATH. Exiting.' >&2 - exit 1 + echo 'emacs not found in PATH. Exiting.' >&2 + exit 1 fi script="$1" if $OPT_BYTE && [ "${1##*.}" = "el" ]; then - script="${1%.*}.elc" - emacs -Q --batch -f batch-byte-compile "$1" 2>/dev/null + script="${1%.*}.elc" + emacs -Q --batch -f batch-byte-compile "$1" 2>/dev/null fi shift diff --git a/.scripts/em b/.scripts/em index e0f9a591..90d01af4 100755 --- a/.scripts/em +++ b/.scripts/em @@ -3,7 +3,7 @@ ## daemon since we want to pass additional parameters to emacs. if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then - cat <&1)" = TTY ]; then - param="-t" + [ "$(emacs --batch -Q --eval='(if (fboundp '"'"'tool-bar-mode) (message "X") (message "TTY"))' 2>&1)" = TTY ]; then + param="-t" else - if [ "${0##*/}" = "emw" ]; then - param="-c" - else - param="-nc" - fi + if [ "${0##*/}" = "emw" ]; then + param="-c" + else + param="-nc" + fi fi [ ! -e /tmp/emacs$(id -u)/server ] && emacs --daemon --no-site-file diff --git a/.scripts/extract b/.scripts/extract index 8df6515b..e299d520 100755 --- a/.scripts/extract +++ b/.scripts/extract @@ -1,9 +1,8 @@ #!/usr/bin/env zsh ## zsh is needed for the password. -_printhelp () -{ - cat</dev/null 2>&1 && echo "You should use atool instead." && echo -_extract() -{ - echo "[$1]" - case "$1" in - */*) FOLDER="${1%/*}";; - *) FOLDER="." ;; - esac +_extract () { + echo "[$1]" + case "$1" in + */*) FOLDER="${1%/*}";; + *) FOLDER="." ;; + esac case "$1" in - *.tar*|*.tbz2|*.tbz|*.tgz|*.txz) tar xf "$1" -C "$FOLDER" ;; - *.7z) 7z x "$PASS" -o"$FOLDER" "$1";; - *.bz2) bunzip2 "$1" ;; - *.rar) unrar x "$1" ;; - *.gz) gunzip "$1" ;; - *.zip) unzip "$1" ;; - *.Z) uncompress "$1" ;; - *.xz) unxz "$1" ;; - *.exe) cabextract "$1" ;; + *.tar*|*.tbz2|*.tbz|*.tgz|*.txz) tar xf "$1" -C "$FOLDER" ;; + *.7z) 7z x "$PASS" -o"$FOLDER" "$1";; + *.bz2) bunzip2 "$1" ;; + *.rar) unrar x "$1" ;; + *.gz) gunzip "$1" ;; + *.zip) unzip "$1" ;; + *.Z) uncompress "$1" ;; + *.xz) unxz "$1" ;; + *.exe) cabextract "$1" ;; + *) + case "$(file "$1")" in + *7-zip*) 7z x "$PASS" -o"$FOLDER" "$1" ;; + *gzip*|*bzip2*|*XZ*) tar xf "$1" -C "$FOLDER" ;; *) - case "$(file "$1")" in - *7-zip*) 7z x "$PASS" -o"$FOLDER" "$1" ;; - *gzip*|*bzip2*|*XZ*) tar xf "$1" -C "$FOLDER" ;; - *) - echo "[$1]: unrecognized archive format." ;; - esac + echo "[$1]: unrecognized archive format." ;; + esac esac $OPT_DELAFTER && rm -v "$1" @@ -88,13 +86,13 @@ _extract() for i ; do - if [ -d "$i" ]; then - while IFS= read -r FILE; do - _extract "$FILE" - done </dev/null 2>&1; then - echo >&2 "'git' not found in PATH. Exiting." - exit 1 + echo >&2 "'git' not found in PATH. Exiting." + exit 1 fi for i; do - git clone git@$DOMAIN:/$USER/$i + git clone git@$DOMAIN:/$USER/$i done diff --git a/.scripts/git-sync b/.scripts/git-sync index c116b737..9a8ddaa7 100755 --- a/.scripts/git-sync +++ b/.scripts/git-sync @@ -1,30 +1,25 @@ #!/bin/sh -_printhelp() -{ - cat< "$ALSACONF" + cat< "$ALSACONF" pcm.!default { - type hw - card $CARD - device $DEVICE + type hw + card $CARD + device $DEVICE } EOF - chmod 644 "${ALSACONF}" - echo "HDMI sound enabled" + chmod 644 "${ALSACONF}" + echo "HDMI sound enabled" else - rm -f "$ALSACONF" - echo "HDMI sound disabled" + rm -f "$ALSACONF" + echo "HDMI sound disabled" fi - diff --git a/.scripts/homeclean b/.scripts/homeclean index 0102413c..62b2b4a2 100755 --- a/.scripts/homeclean +++ b/.scripts/homeclean @@ -1,45 +1,45 @@ #!/bin/sh set -- "$HOME/.cache/dwb" \ - "$HOME/.cache/emacs" \ - "$HOME/.cache/mutt" \ - "$HOME/.cache/rtorrent" \ - "$HOME/.cache/zsh" \ - "$HOME/.cmus/autosave" \ - "$HOME/.cmus/cache" \ - "$HOME/.cmus/lib.pl" \ - "$HOME/.cmus/playlist.pl" \ - "$HOME/.cmus/queue.pl" \ - "$HOME/.cmus/resume" \ - "$HOME/.cmus/search-history" \ - "$HOME/.config/dwb/default/commands.history" \ - "$HOME/.config/dwb/default/cookies" \ - "$HOME/.config/dwb/default/cookies_session.allow" \ - "$HOME/.config/dwb/default/dwb-uni.fifo" \ - "$HOME/.config/dwb/default/history" \ - "$HOME/.config/dwb/default/hsts" \ - "$HOME/.config/dwb/default/navigate.history" \ - "$HOME/.config/dwb/default/plugindb" \ - "$HOME/.config/dwb/default/plugins.allow" \ - "$HOME/.config/dwb/default/scripts.allow" \ - "$HOME/.config/dwb/default/search.history" \ - "$HOME/.config/dwb/default/session" \ - "$HOME/.config/gtk-2.0" \ - "$HOME/.config/gtk-3.0" \ - "$HOME/.config/ranger/bookmarks" \ - "$HOME/.config/ranger/history" \ - "$HOME/.config/ranger/tagged" \ - "$HOME/.fehbg" \ - "$HOME/.gtk-bookmarks" \ - "$HOME/.lesshst" \ - "$HOME/.local/share/newsbeuter" \ - "$HOME/.local/share/webkit" \ - "$HOME/.mpv/watch_later" \ - "$HOME/.mtap.fuseiso" \ - "$HOME/.pulse-cookie" \ - "$HOME/.viminfo" \ - "$HOME/.w3m" \ - "$HOME/.zcompdump" + "$HOME/.cache/emacs" \ + "$HOME/.cache/mutt" \ + "$HOME/.cache/rtorrent" \ + "$HOME/.cache/zsh" \ + "$HOME/.cmus/autosave" \ + "$HOME/.cmus/cache" \ + "$HOME/.cmus/lib.pl" \ + "$HOME/.cmus/playlist.pl" \ + "$HOME/.cmus/queue.pl" \ + "$HOME/.cmus/resume" \ + "$HOME/.cmus/search-history" \ + "$HOME/.config/dwb/default/commands.history" \ + "$HOME/.config/dwb/default/cookies" \ + "$HOME/.config/dwb/default/cookies_session.allow" \ + "$HOME/.config/dwb/default/dwb-uni.fifo" \ + "$HOME/.config/dwb/default/history" \ + "$HOME/.config/dwb/default/hsts" \ + "$HOME/.config/dwb/default/navigate.history" \ + "$HOME/.config/dwb/default/plugindb" \ + "$HOME/.config/dwb/default/plugins.allow" \ + "$HOME/.config/dwb/default/scripts.allow" \ + "$HOME/.config/dwb/default/search.history" \ + "$HOME/.config/dwb/default/session" \ + "$HOME/.config/gtk-2.0" \ + "$HOME/.config/gtk-3.0" \ + "$HOME/.config/ranger/bookmarks" \ + "$HOME/.config/ranger/history" \ + "$HOME/.config/ranger/tagged" \ + "$HOME/.fehbg" \ + "$HOME/.gtk-bookmarks" \ + "$HOME/.lesshst" \ + "$HOME/.local/share/newsbeuter" \ + "$HOME/.local/share/webkit" \ + "$HOME/.mpv/watch_later" \ + "$HOME/.mtap.fuseiso" \ + "$HOME/.pulse-cookie" \ + "$HOME/.viminfo" \ + "$HOME/.w3m" \ + "$HOME/.zcompdump" ## POSIX can store only one list at a time. Here we rely on the fact there is no ## space in the file names. @@ -58,18 +58,18 @@ echo "==> Clean home? [y/N]" read CHOICE CHOICE="$(echo $CHOICE | tr [:lower:] [:upper:])" if [ "$CHOICE" != "Y" ]; then - echo "Nothing done." - exit + echo "Nothing done." + exit fi ## Clean trash if possible. echo echo "==> Emptying trash." if ! command -v trash-empty >/dev/null 2>&1; then - echo ":: 'trash-empty' not installed, you have to clean other drives manually." - rm -rvf "$HOME/.local/share/Trash" + echo ":: 'trash-empty' not installed, you have to clean other drives manually." + rm -rvf "$HOME/.local/share/Trash" else - trash-empty + trash-empty fi ## Remove data. @@ -81,10 +81,10 @@ rm -rvf "$@" echo echo "==> Remove critical data." if [ "$(echo "$HOME" | grep -c ' ')" -ne 0 ]; then - echo 'WARNING: $HOME contains spaces, skipping.' + echo 'WARNING: $HOME contains spaces, skipping.' else - shred -zuv $RMLIST_CRITICAL - # wipe -rdzp2 $RMLIST_CRITICAL + shred -zuv $RMLIST_CRITICAL + # wipe -rdzp2 $RMLIST_CRITICAL fi echo diff --git a/.scripts/homeinit b/.scripts/homeinit index 5a10061c..4d4b45a9 100755 --- a/.scripts/homeinit +++ b/.scripts/homeinit @@ -1,8 +1,6 @@ #!/bin/sh -################################################################################ ## Home session initialization. -## 2013-06-14 -################################################################################ + SOURCEDIR="$HOME/personal/dataperso" [ -z "$XDG_CONFIG_HOME" ] && XDG_CONFIG_HOME="$HOME/.config" [ -z "$XDG_DATA_HOME" ] && XDG_DATA_HOME="$HOME/.local/share" @@ -14,97 +12,97 @@ mkdir -p "$HOME/temp" echo if [ -d "$SOURCEDIR/contacts" ]; then - echo "==> Abook" - ln -snf "$SOURCEDIR/contacts" "$HOME/.abook" - echo + echo "==> Abook" + ln -snf "$SOURCEDIR/contacts" "$HOME/.abook" + echo fi if command -v mutt >/dev/null 2>&1; then - echo "==> Mutt" - [ -d "$SOURCEDIR" ] && ln -snf "$SOURCEDIR/mails" "$HOME/.mutt.d" - mkdir -p "$HOME/.cache/mutt/hcache" - echo + echo "==> Mutt" + [ -d "$SOURCEDIR" ] && ln -snf "$SOURCEDIR/mails" "$HOME/.mutt.d" + mkdir -p "$HOME/.cache/mutt/hcache" + echo fi if [ -d "$SOURCEDIR/todo" ]; then - echo "==> To-Do" - ln -snf "$SOURCEDIR/todo/todo.org" "$HOME/todo.org" - echo + echo "==> To-Do" + ln -snf "$SOURCEDIR/todo/todo.org" "$HOME/todo.org" + echo fi if command -v rtorrent >/dev/null 2>&1; then - echo "==> rtorrent" - ## We need the evaluation of the result, otherwise the variables will not - ## get expanded, should it be '~' or "$HOME". - mkdir -p "$(eval echo $(awk -F'=' '/^session *= */{gsub(/^ +| +$/,"",$2); res=$2} END {printf res}' ~/.rtorrent.rc))" - echo + echo "==> rtorrent" + ## We need the evaluation of the result, otherwise the variables will not + ## get expanded, should it be '~' or "$HOME". + mkdir -p "$(eval echo $(awk -F'=' '/^session *= */{gsub(/^ +| +$/,"",$2); res=$2} END {printf res}' ~/.rtorrent.rc))" + echo fi ## Luakit -- Install the adblock modules if command -v luakit >/dev/null 2>&1; then - echo "==> Luakit" - git clone https://github.com/Plaque-fcc/luakit-adblock/ "$HOME/luakit-adblock" - cp -fv ~/luakit-adblock/*.lua "$XDG_CONFIG_HOME/luakit" - rm -rvf "$HOME/luakit-adblock" + echo "==> Luakit" + git clone https://github.com/Plaque-fcc/luakit-adblock/ "$HOME/luakit-adblock" + cp -fv ~/luakit-adblock/*.lua "$XDG_CONFIG_HOME/luakit" + rm -rvf "$HOME/luakit-adblock" - ## Update the adblock lists - mkdir -p "$XDG_DATA_HOME/luakit/adblock" - wget https://easylist-downloads.adblockplus.org/easylist.txt \ - https://easylist-downloads.adblockplus.org/easyprivacy.txt \ - https://easylist-downloads.adblockplus.org/easylistgermany.txt \ - http://lian.info.tm/liste_fr.txt \ - -P "$XDG_DATA_HOME/luakit/adblock" - echo + ## Update the adblock lists + mkdir -p "$XDG_DATA_HOME/luakit/adblock" + wget https://easylist-downloads.adblockplus.org/easylist.txt \ + https://easylist-downloads.adblockplus.org/easyprivacy.txt \ + https://easylist-downloads.adblockplus.org/easylistgermany.txt \ + http://lian.info.tm/liste_fr.txt \ + -P "$XDG_DATA_HOME/luakit/adblock" + echo fi ## dwb -- Install extensions. if command -v dwbem >/dev/null 2>&1; then - echo "==> dwb" + echo "==> dwb" - [ $(dwbem -l | grep -c "adblock_subscriptions") -eq 0 ] && dwbem -Ni adblock_subscriptions - [ $(dwbem -l | grep -c "navtools") -eq 0 ] && dwbem -Ni navtools - [ $(dwbem -l | grep -c "contenthandler") -eq 0 ] && dwbem -Ni contenthandler - # dwbem -Ni youtube_html5 + [ $(dwbem -l | grep -c "adblock_subscriptions") -eq 0 ] && dwbem -Ni adblock_subscriptions + [ $(dwbem -l | grep -c "navtools") -eq 0 ] && dwbem -Ni navtools + [ $(dwbem -l | grep -c "contenthandler") -eq 0 ] && dwbem -Ni contenthandler + # dwbem -Ni youtube_html5 - (cd ~/.config/dwb/userscripts/ && git checkout extension_loader.js) - echo + (cd ~/.config/dwb/userscripts/ && git checkout extension_loader.js) + echo fi ## Bookmarks if [ -d "$SOURCEDIR" ]; then - echo "==> Bookmarks" - if [ -z "$BROWSER" ]; then - echo "Variable BROWSER is not set." - else - BROWSER_DATA_DIR="$XDG_DATA_HOME/$BROWSER/" - [ "$BROWSER" = "dwb" ] && BROWSER_DATA_DIR="$XDG_CONFIG_HOME/$BROWSER/default/" + echo "==> Bookmarks" + if [ -z "$BROWSER" ]; then + echo "Variable BROWSER is not set." + else + BROWSER_DATA_DIR="$XDG_DATA_HOME/$BROWSER/" + [ "$BROWSER" = "dwb" ] && BROWSER_DATA_DIR="$XDG_CONFIG_HOME/$BROWSER/default/" - [ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/bookmarks/bookmarks" "$BROWSER_DATA_DIR" - [ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/bookmarks/quickmarks" "$BROWSER_DATA_DIR" - [ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/bookmarks/cookies.allow" "$BROWSER_DATA_DIR" - fi - echo + [ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/bookmarks/bookmarks" "$BROWSER_DATA_DIR" + [ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/bookmarks/quickmarks" "$BROWSER_DATA_DIR" + [ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/bookmarks/cookies.allow" "$BROWSER_DATA_DIR" + fi + echo fi ## News if command -v newsbeuter >/dev/null 2>&1; then - echo "==> Newsbeuter" - mkdir -p "$XDG_DATA_HOME/newsbeuter" - [ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/news/urls" "$XDG_CONFIG_HOME/newsbeuter/" - [ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/news/news_starred" "$XDG_CONFIG_HOME/newsbeuter/" - echo + echo "==> Newsbeuter" + mkdir -p "$XDG_DATA_HOME/newsbeuter" + [ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/news/urls" "$XDG_CONFIG_HOME/newsbeuter/" + [ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/news/news_starred" "$XDG_CONFIG_HOME/newsbeuter/" + echo fi ## Launchers if [ -d "$SOURCEDIR" ]; then - echo "==> Launchers" - ln -snf "$SOURCEDIR/launchers" "$HOME/.launchers" - echo + echo "==> Launchers" + ln -snf "$SOURCEDIR/launchers" "$HOME/.launchers" + echo fi ## Temp scripts if [ -d "$SOURCEDIR" ]; then - echo "==> Hackpool" - ln -snf "$SOURCEDIR/hackpool" "$HOME/.hackpool" - echo + echo "==> Hackpool" + ln -snf "$SOURCEDIR/hackpool" "$HOME/.hackpool" + echo fi diff --git a/.scripts/hsync b/.scripts/hsync index 4f079c71..4783b325 100755 --- a/.scripts/hsync +++ b/.scripts/hsync @@ -30,7 +30,7 @@ ## we go for the first algorithm. function _printhelp() { - print "Filesystem hierarchy synchronizer\n\ + print "Filesystem hierarchy synchronizer\n\ \n\ Usage: hsync SOURCE TARGET\n\ \n\ @@ -48,78 +48,78 @@ evaluation:\n\ } function _info(s) { - print "\n==> " s | "cat >&2" - close("cat >&2") + print "\n==> " s | "cat >&2" + close("cat >&2") } function _msg(s) { - print ":: " s | "cat >&2" - close("cat >&2") + print ":: " s | "cat >&2" + close("cat >&2") } BEGIN { - ## Both parameters must be existing folders. - if (ARGC != 3 || - ("test -d " ARGV[1] " && test -d " ARGV[2] " || echo KO" | getline) > 0 ) - { - _printhelp() - exit - } + ## Both parameters must be existing folders. + if (ARGC != 3 || + ("test -d " ARGV[1] " && test -d " ARGV[2] " || echo KO" | getline) > 0 ) + { + _printhelp() + exit + } - _info("Scanning " ARGV[1] "...") - while ( ("cd -- " ARGV[1] " && find . -type f -exec md5sum {} +" | getline ) > 0) - { - sum = $1 - ## We need to remove sum from line since filename may contain - ## spaces. substr is faster than sub. - name = substr($0, 35) + _info("Scanning " ARGV[1] "...") + while ( ("cd -- " ARGV[1] " && find . -type f -exec md5sum {} +" | getline ) > 0) + { + sum = $1 + ## We need to remove sum from line since filename may contain + ## spaces. substr is faster than sub. + name = substr($0, 35) - if (sum in source || sum in source_dup) - { - _msg("Skipping duplicate: " name) - ## Note: it is not necessary to delete source[sum] since it will not - ## be used anyway if source_dup[sum] is set to 1. - source_dup[sum] = 1 - continue - } - source[sum] = name - } + if (sum in source || sum in source_dup) + { + _msg("Skipping duplicate: " name) + ## Note: it is not necessary to delete source[sum] since it will not + ## be used anyway if source_dup[sum] is set to 1. + source_dup[sum] = 1 + continue + } + source[sum] = name + } - _info("Scanning " ARGV[2] "...") - while ( ("cd -- " ARGV[2] " && find . -type f -exec md5sum {} +" | getline ) > 0) - { - sum = $1 - name = substr($0, 35) + _info("Scanning " ARGV[2] "...") + while ( ("cd -- " ARGV[2] " && find . -type f -exec md5sum {} +" | getline ) > 0) + { + sum = $1 + name = substr($0, 35) - ## Skip if duplicate, not existant in source, or identical. - if (sum in source_dup || ! (sum in source) || source[sum] == name) - continue + ## Skip if duplicate, not existant in source, or identical. + if (sum in source_dup || ! (sum in source) || source[sum] == name) + continue - if (sum in target || sum in target_dup) - { - _msg("Skipping duplicate: " name) - delete target[sum] - target_dup[sum] = 1 - continue - } - target[sum] = name - } + if (sum in target || sum in target_dup) + { + _msg("Skipping duplicate: " name) + delete target[sum] + target_dup[sum] = 1 + continue + } + target[sum] = name + } - _info("Hierarchy syncing preview of " ARGV[2] " based on " ARGV[1]) - for (i in target) - { - dirname = source[i] - sub(/[^/]+$/, "", dirname) + _info("Hierarchy syncing preview of " ARGV[2] " based on " ARGV[1]) + for (i in target) + { + dirname = source[i] + sub(/[^/]+$/, "", dirname) - ## Target -> Source - cmd = "'" ARGV[2] "/" target[i] "' '" ARGV[2] "/" source[i] "'" + ## Target -> Source + cmd = "'" ARGV[2] "/" target[i] "' '" ARGV[2] "/" source[i] "'" - ## We only create a new folder if necessary. - cmd = "[ ! -d '" dirname "' ] && mkdir -p \"" ARGV[2] "/" dirname "\" ; mv -nv " cmd + ## We only create a new folder if necessary. + cmd = "[ ! -d '" dirname "' ] && mkdir -p \"" ARGV[2] "/" dirname "\" ; mv -nv " cmd - ## We can sort preview by uncommenting the following pipe. This is - ## not very useful however, and it costs some n*log(n) more - ## operations. - print cmd #|"sort" - } + ## We can sort preview by uncommenting the following pipe. This is + ## not very useful however, and it costs some n*log(n) more + ## operations. + print cmd #|"sort" + } } diff --git a/.scripts/imagemount b/.scripts/imagemount index 3345e376..1e070c73 100755 --- a/.scripts/imagemount +++ b/.scripts/imagemount @@ -6,86 +6,83 @@ FUSEROOT="$HOME/fuse" ################################################################################ -_mount () -{ - [ ! -f "$1" ] && return +_mount () { + [ ! -f "$1" ] && return - 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}')" + 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 - echo "Image alredy mounted." - return - fi + if [ $(cdemu status | grep -c "$1") -gt 0 ]; then + echo "Image alredy mounted." + return + fi - 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 + 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 - ## 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 - sleep 1 - done + ## 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 + sleep 1 + done - fi + fi - cdemu load $DEVICE "$1" - if [ $? -ne 0 ] && command -v fuseiso >/dev/null 2>&1; then - echo "Falling back to fuseiso." + cdemu load $DEVICE "$1" + if [ $? -ne 0 ] && command -v fuseiso >/dev/null 2>&1; then + echo "Falling back to fuseiso." - # LIST="$(mount | awk -v root="$FUSEROOT" '$1 == "fuseiso" && $3 ~ root {print $3}')" - LIST=$(mount | awk -v root="$FUSEROOT" '$1 == "fuseiso" && $3 ~ root {sub(/^fuseiso on /,"");sub(/ type fuse.fuseiso [^ ]*$/, ""); print $0}') - ALREADY="$(lsof -c fuseiso -F n | grep "$1")" + # LIST="$(mount | awk -v root="$FUSEROOT" '$1 == "fuseiso" && $3 ~ root {print $3}')" + LIST=$(mount | awk -v root="$FUSEROOT" '$1 == "fuseiso" && $3 ~ root {sub(/^fuseiso on /,"");sub(/ type fuse.fuseiso [^ ]*$/, ""); print $0}') + ALREADY="$(lsof -c fuseiso -F n | grep "$1")" - if [ -n "$ALREADY" ]; then - echo "Image alredy mounted." - return - fi + if [ -n "$ALREADY" ]; then + echo "Image alredy mounted." + return + fi - COUNT=0 - while [ -n "$(echo "$LIST" | grep "$FUSEROOT/drive-$COUNT" )" ]; do - COUNT=$(($COUNT+1)) - done + COUNT=0 + while [ -n "$(echo "$LIST" | grep "$FUSEROOT/drive-$COUNT" )" ]; do + COUNT=$(($COUNT+1)) + done - mkdir -p "$FUSEROOT/drive-$COUNT" - fuseiso -p "$1" "$FUSEROOT/drive-$COUNT" + 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}')" - ## TODO: This is terrible, but checking cdemu status does not work. Maybe - ## a kernel limitation. - echo "Mounting..." - sleep 2 - udiskie-mount "$NODE" - fi + else + 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..." + sleep 2 + udiskie-mount "$NODE" + fi } -_umount () -{ - [ ! -d "$1" ] && return +_umount () { + [ ! -d "$1" ] && return - NODE="$(df | awk -v mount="$1" '$0 ~ mount {node=$1; gsub(/[^%]+% /, ""); if ($0 ~ mount){print node; exit}}')" + NODE="$(df | awk -v mount="$1" '$0 ~ mount {node=$1; gsub(/[^%]+% /, ""); if ($0 ~ mount){print node; exit}}')" - if [ -n "$NODE" ]; then - udiskie-umount "$1" + if [ -n "$NODE" ]; then + udiskie-umount "$1" - DEVICE=$(cdemu device-mapping | awk -v node="$NODE" '$2 == node {print $1; exit}') - cdemu unload $DEVICE - elif command -v fuseiso >/dev/null; then - fusermount -u "$1" - rmdir "$1" >/dev/null 2>&1 - fi + DEVICE=$(cdemu device-mapping | awk -v node="$NODE" '$2 == node {print $1; exit}') + cdemu unload $DEVICE + elif command -v fuseiso >/dev/null; then + fusermount -u "$1" + rmdir "$1" >/dev/null 2>&1 + fi } -_printhelp () -{ - cat</dev/null 2>&1; then - echo >&2 "'$i' not found in PATH. Exiting." - exit 1 - fi - done +check () { + for i ; do + if ! command -v $i >/dev/null 2>&1; then + echo >&2 "'$i' not found in PATH. Exiting." + exit 1 + fi + done } ## realpath is needed to check if image was already mounted or not. check udiskie cdemu realpath if $OPT_UNMOUNT; then - for i ; do - _umount "$(realpath "$i")" - done + for i ; do + _umount "$(realpath "$i")" + done else - for i ; do - _mount "$(realpath "$i")" - done + for i ; do + _mount "$(realpath "$i")" + done fi diff --git a/.scripts/lsofstat b/.scripts/lsofstat index 13078460..b6fabb33 100755 --- a/.scripts/lsofstat +++ b/.scripts/lsofstat @@ -1,21 +1,21 @@ #!/bin/sh if [ "$1" = "-h" ]; then - cat</dev/null - fi - fi + if $OPT_DELEMPTY; then + PARENT="$FOLDER/../$FILE" + PARENT="${PARENT%/*}" + rmdir "$PARENT" 2>/dev/null + fi + fi - ## We switch to $i so that 'find' strips the parent dirs from the path. - done <wla) - {a=0; ca*=-1}; - if (b>wlb) - {b=0; cb*=-1}; - if (di>de) - {di=0; ca*=0.9; cb*=0.9}; - printf("%c",c)}; - c=int(c); - while(c!=128) { - c<128?c++:c--; - printf("%c",c)};};}' | aplay -r $rate + return (rate/160)*(0.87055^(int(rand()*10)))}; + BEGIN { + srand(); + wla=wl(); + while(1) { + wlb=wla; + wla=wl(); + if (wla==wlb) + {wla*=2;}; + d=(rand()*10+5)*rate/4; + a=b=0; c=128; + ca=40/wla; cb=20/wlb; + de=rate/10; di=0; + for (i=0;iwla) + {a=0; ca*=-1}; + if (b>wlb) + {b=0; cb*=-1}; + if (di>de) + {di=0; ca*=0.9; cb*=0.9}; + printf("%c",c)}; + c=int(c); + while(c!=128) { + c<128?c++:c--; + printf("%c",c)};};}' | aplay -r $rate diff --git a/.scripts/netinit b/.scripts/netinit index b2471d90..b987727d 100755 --- a/.scripts/netinit +++ b/.scripts/netinit @@ -4,19 +4,19 @@ ## better off running the dhcpcd daemon with ## /etc/wpa_supplicant/wpa_supplicant.conf configured if needed. See ## dhcpcd-run-hooks(8). - +## ## Deps: wpa_supplicant, ccrypt (optional) - +## ## We need to use wpa_supplicant's unencrypted config file. We store it in a ## variable to keep it secure, but the 'wpa_supplicant' command requires a ## file. We cannot use a pipe for that, because in that case the config would be ## accessible unencrypted. So we need to use an internal path with a syntax like ## <(...) which is not specified by POSIX. Ksh, bash and Zsh can handle it. - +## ## Use 'wpa_passphrase ESSID $PW >> /etc/wpa_supplicant.conf', where PW is a ## variable containing the password. You can set PW securely by using a shell ## built-in like 'read -s PW'. - +## ## There is an Emacs plugin for editing crypted files directly. See 'man ## ccrypt'. @@ -25,9 +25,8 @@ TIMEOUT_LIMIT=500 USE_DHCP=0 USE_CRYPT=0 -_printhelp () -{ - cat</dev/null 2>&1; then - echo >&2 "'ccat' not found in PATH. Exiting." - exit 1 - fi + if ! command -v ccat >/dev/null 2>&1; then + echo >&2 "'ccat' not found in PATH. Exiting." + exit 1 + fi - WPA_SUPPLICANT_CONF="$(ccat "$WSFILE")" - if [ $? -ne 0 ]; then - echo "Failed to decrypt wpa_supplicant config from $WSFILE." - exit - fi + WPA_SUPPLICANT_CONF="$(ccat "$WSFILE")" + if [ $? -ne 0 ]; then + echo "Failed to decrypt wpa_supplicant config from $WSFILE." + exit + fi else - WPA_SUPPLICANT_CONF="$(cat "$WSFILE")" - if [ $? -ne 0 ]; then - echo "Failed to get wpa_supplicant config from $WSFILE." - exit - fi + WPA_SUPPLICANT_CONF="$(cat "$WSFILE")" + if [ $? -ne 0 ]; then + echo "Failed to get wpa_supplicant config from $WSFILE." + exit + fi fi ## Note: systemd-197 introduced Predictable Network Interface Names, so we need @@ -94,41 +93,41 @@ NET_INTERFACE=$(ls -1 /sys/class/net | grep -m1 "^wl") pkill wpa_supplicant if [ "$OSTYPE" = "linux-gnu" ] ; then - ## Clean running processes if any. - pkill dhcpcd + ## Clean running processes if any. + pkill dhcpcd - ## In case network inteface is not up. - ip link set ${NET_INTERFACE} up + ## In case network inteface is not up. + ip link set ${NET_INTERFACE} up - # Associate if needed. - if [ "$1" = "-f" ] || [ -z "$(iw dev ${NET_INTERFACE} link | grep SSID)" ]; then - wpa_supplicant -B -i ${NET_INTERFACE} -D wext -c <(echo "${WPA_SUPPLICANT_CONF}") - fi + # Associate if needed. + if [ "$1" = "-f" ] || [ -z "$(iw dev ${NET_INTERFACE} link | grep SSID)" ]; then + wpa_supplicant -B -i ${NET_INTERFACE} -D wext -c <(echo "${WPA_SUPPLICANT_CONF}") + fi - ## Wait until wpa_supplicant has finished association. - i=0 - while [ -z "$(iw dev ${NET_INTERFACE} link | grep SSID)" ] && [ $i -lt $TIMEOUT_LIMIT ] ; do - i=$(($i+1)) - done + ## Wait until wpa_supplicant has finished association. + i=0 + while [ -z "$(iw dev ${NET_INTERFACE} link | grep SSID)" ] && [ $i -lt $TIMEOUT_LIMIT ] ; do + i=$(($i+1)) + done - ## Get IP. - [ $USE_DHCP -eq 1 ] && dhcpcd ${NET_INTERFACE} + ## Get IP. + [ $USE_DHCP -eq 1 ] && dhcpcd ${NET_INTERFACE} else -## BSD -## Same comments as for Linux. + ## BSD + ## Same comments as for Linux. - pkill dhclient - ifconfig wlan0 up + pkill dhclient + ifconfig wlan0 up - if [ -n "$(ifconfig ${NET_INTERFACE} | grep 'ssid ""')" ]; then - wpa_supplicant -B -i ${NET_INTERFACE} -c <(echo "${WPA_SUPPLICANT_CONF}") - fi + if [ -n "$(ifconfig ${NET_INTERFACE} | grep 'ssid ""')" ]; then + wpa_supplicant -B -i ${NET_INTERFACE} -c <(echo "${WPA_SUPPLICANT_CONF}") + fi - i=0 - while [ -n "$(ifconfig ${NET_INTERFACE} | grep 'ssid ""')" ] && [ $i -lt $TIMEOUT_LIMIT ] ; do - i=$(($i+1)) - done + i=0 + while [ -n "$(ifconfig ${NET_INTERFACE} | grep 'ssid ""')" ] && [ $i -lt $TIMEOUT_LIMIT ] ; do + i=$(($i+1)) + done - [ $USE_DHCP -eq 1 ] && dhclient ${NET_INTERFACE} + [ $USE_DHCP -eq 1 ] && dhclient ${NET_INTERFACE} fi diff --git a/.scripts/netmap b/.scripts/netmap index 7e92da3a..cfb0a03e 100755 --- a/.scripts/netmap +++ b/.scripts/netmap @@ -1,22 +1,22 @@ #!/bin/sh if [ $# -ne 1 ] || [ "$1" = "-h" ] ; then - cat</dev/null 2>&1; then - echo >&2 "'nmap' not found in PATH. Exiting." - exit 1 + echo >&2 "'nmap' not found in PATH. Exiting." + exit 1 fi echo "$1" for SCANIP in $( nmap -sL "$1" | grep -i "\([[:digit:]]\+\.\)\{3,\}[[:digit:]]\+" | awk '{print $5}' ); do - sudo nmap -oX - -n -sT -T Normal -O -sR -I -F -P0 "$SCANIP" - echo + sudo nmap -oX - -n -sT -T Normal -O -sR -I -F -P0 "$SCANIP" + echo done diff --git a/.scripts/netscan b/.scripts/netscan index 362653d1..3c95d7f5 100755 --- a/.scripts/netscan +++ b/.scripts/netscan @@ -1,8 +1,8 @@ #!/bin/sh if ! command -v nmap >/dev/null 2>&1; then - echo >&2 "'nmap' not found in PATH. Exiting." - exit 1 + echo >&2 "'nmap' not found in PATH. Exiting." + exit 1 fi SUBNET="$(ifconfig | awk '/inet/ && $0 !~ "127.0.0.1" {gsub(/\.[0-9]+$/, ".*", $2) ; print $2}')" diff --git a/.scripts/netspeed b/.scripts/netspeed index 4ad74d10..d38ff731 100755 --- a/.scripts/netspeed +++ b/.scripts/netspeed @@ -1,19 +1,19 @@ #!/bin/sh if [ "$1" = "-h" ] || [ $# -gt 1 ]; then - cat</dev/null && echo "You need pacman to run this script." && exit 1 if [ $(pacman -Qq "$@" 2>/dev/null | wc -l) -eq 0 ]; then - echo "No valid package given." >&2 - exit + echo "No valid package given." >&2 + exit fi ## We use "eval" to be compatible with non-POSIX wordsplitting (e.g. zsh). diff --git a/.scripts/pacman-diff b/.scripts/pacman-diff index 3ec4b413..288bfc63 100755 --- a/.scripts/pacman-diff +++ b/.scripts/pacman-diff @@ -1,8 +1,7 @@ #!/bin/sh -_printhelp() -{ - cat </dev/null 2>&1; then - echo >&2 "'pacman' not found in PATH. Exiting." - exit 1 + echo >&2 "'pacman' not found in PATH. Exiting." + exit 1 fi PKGLIST="$(mktemp)" @@ -57,4 +56,3 @@ rm -f "$PKGLIST" "$FILE" ## Zsh version. # comm -3 ${OPTION_LOCAL} <(pacman -Qq${OPTION_FOREIGN}${OPTION_EXPLICIT} | sort) <(sort "$*") - diff --git a/.scripts/pacsize b/.scripts/pacsize index bb2c676e..badc87c7 100755 --- a/.scripts/pacsize +++ b/.scripts/pacsize @@ -51,7 +51,7 @@ remove_duplicates () { } usage () { - cat </dev/null 2>&1; then - ## Note: the "-n" option was added between 2012 and 2013. - pacman -Qnq | sort >"$PKG_ROOT/arch-official-${HOST}" - pacman -Qmq | sort >"$PKG_ROOT/arch-aur-${HOST}" + ## Note: the "-n" option was added between 2012 and 2013. + pacman -Qnq | sort >"$PKG_ROOT/arch-official-${HOST}" + pacman -Qmq | sort >"$PKG_ROOT/arch-aur-${HOST}" fi ## FreeBSD if [ "$(uname)" = "FreeBSD" ]; then - pkg_info | cut -f1 -d' ' >"$PKG_ROOT/freebsd-${HOST}" + pkg_info | cut -f1 -d' ' >"$PKG_ROOT/freebsd-${HOST}" fi ## TeXlive if command -v tlmgr >/dev/null 2>&1; then - ## We use in the sed expressions. - TEXLIVE_BASIC="$(mktemp)" - tlmgr info collection-basic --list | sed -n '/^ /{s/ //g;p;}' | sort >"$TEXLIVE_BASIC" + ## We use in the sed expressions. + TEXLIVE_BASIC="$(mktemp)" + tlmgr info collection-basic --list | sed -n '/^ /{s/ //g;p;}' | sort >"$TEXLIVE_BASIC" - TEXLIVE_ALL="$(mktemp)" - tlmgr info --only-installed | grep -v 'x86_64\|amd64' | cut -d' ' -f2 | cut -f1 -d':' | sort >"$TEXLIVE_ALL" + TEXLIVE_ALL="$(mktemp)" + tlmgr info --only-installed | grep -v 'x86_64\|amd64' | cut -d' ' -f2 | cut -f1 -d':' | sort >"$TEXLIVE_ALL" - comm -3 "$TEXLIVE_BASIC" "$TEXLIVE_ALL" | sed 's/ //g' | \ - grep -vi 'collection-basic\|scheme-minimal\|texlive-common\|texlive-docindex\|texlive-en' >"$PKG_ROOT/texlive-$(uname)-${HOST}" + comm -3 "$TEXLIVE_BASIC" "$TEXLIVE_ALL" | sed 's/ //g' | \ + grep -vi 'collection-basic\|scheme-minimal\|texlive-common\|texlive-docindex\|texlive-en' >"$PKG_ROOT/texlive-$(uname)-${HOST}" - rm "$TEXLIVE_ALL" "$TEXLIVE_BASIC" + rm "$TEXLIVE_ALL" "$TEXLIVE_BASIC" fi ## Zsh version diff --git a/.scripts/prepend b/.scripts/prepend index 82a31660..f66fb2db 100755 --- a/.scripts/prepend +++ b/.scripts/prepend @@ -1,7 +1,7 @@ #!/bin/sh if [ $# -eq 0 ] || [ "$1" = "-h" ]; then - cat </dev/null + nf="$(echo "$filename" | awk '{print tolower($0)}')" + newname="${dirname}/${nf}" + mv -nv "$f" "$newname" 2>/dev/null done diff --git a/.scripts/renamelowerrec b/.scripts/renamelowerrec index 20cf2f9c..7bc119cb 100755 --- a/.scripts/renamelowerrec +++ b/.scripts/renamelowerrec @@ -1,23 +1,23 @@ #!/bin/sh if [ $# -eq 0 ] || [ "$1" = "-h" ] ; then - cat</dev/null 2>&1; then - echo "'renamelower' not found in PATH. Exiting." >&2 - exit 1 + echo "'renamelower' not found in PATH. Exiting." >&2 + exit 1 fi ## Note: the -name check is not mandatory, but greatly improves the average ## performance. for i ; do - find "$i" -depth -name '*[[:upper:]]*' -exec renamelower {} + + find "$i" -depth -name '*[[:upper:]]*' -exec renamelower {} + done diff --git a/.scripts/renameswap b/.scripts/renameswap index f3f3e152..0b2bf98e 100755 --- a/.scripts/renameswap +++ b/.scripts/renameswap @@ -1,14 +1,14 @@ #!/bin/sh if [ $# -ne 2 ] || [ "$1" = "-h" ] ; then - cat<&2 "Race condition, exiting. Try again." + echo >&2 "Race condition, exiting. Try again." fi mv -n "$2" "$DIR2/${1##*/}" mv -n "$TEMPFILE" "$DIR1/${2##*/}" diff --git a/.scripts/replace b/.scripts/replace index 9b1732ff..1816d81c 100755 --- a/.scripts/replace +++ b/.scripts/replace @@ -1,8 +1,7 @@ #!/bin/sh -_printhelp () -{ - cat< "$out" - mv "$out" "$i" - done + for i ; do + out="$(mktemp "$i.XXXXXX")" + _replace "$i" > "$out" + mv "$out" "$i" + done fi diff --git a/.scripts/rsync-preview b/.scripts/rsync-preview index d376356b..50ba49c6 100755 --- a/.scripts/rsync-preview +++ b/.scripts/rsync-preview @@ -1,14 +1,14 @@ #!/bin/sh if [ "$1" = "-h" ] || [ $# -ne 2 ]; then - cat</dev/null 2>&1; then - if emacsclient -e '(kill-emacs)' >/dev/null 2>&1; then - echo "Emacs terminated." >&2 - fi + if emacsclient -e '(kill-emacs)' >/dev/null 2>&1; then + echo "Emacs terminated." >&2 + fi fi if [ -S "$SSH_AUTH_SOCK" ]; then - echo "SSH agent terminated." >&2 - eval "$(ssh-agent -k)" + echo "SSH agent terminated." >&2 + eval "$(ssh-agent -k)" fi diff --git a/.scripts/strip-comments b/.scripts/strip-comments index 259946f5..4ff5cf3d 100755 --- a/.scripts/strip-comments +++ b/.scripts/strip-comments @@ -8,25 +8,24 @@ ## to use shell comment delimiters. BEGIN { - ## Since 'begin' and 'end' are regexes, we need to escape some sequences. - if(begin == "") - begin="/\\*" - if(end == "") - end="\\*/" + ## Since 'begin' and 'end' are regexes, we need to escape some sequences. + if(begin == "") + begin="/\\*" + if(end == "") + end="\\*/" } { - while (match ($0, begin)) - { - before = substr ($0, 1, RSTART-1) - $0 = substr($0, RSTART) - printf("%s", before) + while (match ($0, begin)) { + before = substr ($0, 1, RSTART-1) + $0 = substr($0, RSTART) + printf("%s", before) - ## Reach line where first 'end' is found. - while (! match($0, end) ) - getline + ## Reach line where first 'end' is found. + while (! match($0, end) ) + getline - $0 = substr($0, RSTART + length(end) -1) - } - print + $0 = substr($0, RSTART + length(end) -1) + } + print } diff --git a/.scripts/switchdriver b/.scripts/switchdriver index 03ae94d2..583939ee 100755 --- a/.scripts/switchdriver +++ b/.scripts/switchdriver @@ -1,45 +1,45 @@ #!/bin/sh if [ -z "$(lspci|grep "VGA.*Radeon")" ]; then - echo "You must have a Radeon graphic adapter. Exit." - exit + echo "You must have a Radeon graphic adapter. Exit." + exit fi if [ $(id -u) -ne 0 ]; then - echo "You must be root to run this script. Exit." - exit + echo "You must be root to run this script. Exit." + exit fi if [ $(pacman -Qi catalyst-utils 2>/dev/null |wc -l) -ge 2 ]; then - pacman -Rdd --noconfirm catalyst catalyst-utils lib32-catalyst-utils - rm -f "/etc/X11/xorg.conf" - pacman -S --noconfirm ati-dri lib32-ati-dri xf86-video-ati - pacman -S --noconfirm mesa-libgl lib32-mesa-libgl - pacman -S --noconfirm libcl lib32-libcl - if [ -f "/boot/syslinux/syslinux.cfg" ]; then - ex -sc '/^LABEL arch$/+3 s/ nomodeset//|xit' '/boot/syslinux/syslinux.cfg' - echo - echo "#### Syslinux entry:" - grep -A4 '^LABEL arch$' '/boot/syslinux/syslinux.cfg' - else - echo "You do not seem to use Syslinux. No configuration done." - echo "You have to remove 'nomodeset' kernel parameter manually." - fi + pacman -Rdd --noconfirm catalyst catalyst-utils lib32-catalyst-utils + rm -f "/etc/X11/xorg.conf" + pacman -S --noconfirm ati-dri lib32-ati-dri xf86-video-ati + pacman -S --noconfirm mesa-libgl lib32-mesa-libgl + pacman -S --noconfirm libcl lib32-libcl + if [ -f "/boot/syslinux/syslinux.cfg" ]; then + ex -sc '/^LABEL arch$/+3 s/ nomodeset//|xit' '/boot/syslinux/syslinux.cfg' + echo + echo "#### Syslinux entry:" + grep -A4 '^LABEL arch$' '/boot/syslinux/syslinux.cfg' + else + echo "You do not seem to use Syslinux. No configuration done." + echo "You have to remove 'nomodeset' kernel parameter manually." + fi else - pacman -Rs --noconfirm ati-dri lib32-ati-dri xf86-video-ati - pacman -Rdd --noconfirm mesa-libgl lib32-mesa-libgl - pacman -Rdd --noconfirm libcl lib32-libcl - pacman -S --noconfirm catalyst catalyst-utils lib32-catalyst-utils - aticonfig --initial - if [ $? -eq 0 ] && [ -f '/boot/syslinux/syslinux.cfg' ]; then - ex -sc '/^LABEL arch$/+3 s/$/ nomodeset/|xit' '/boot/syslinux/syslinux.cfg' - echo - echo "#### Syslinux entry:" - grep -A4 "^LABEL arch$" "/boot/syslinux/syslinux.cfg" - else - echo "You do not seem to use Syslinux. No configuration done." - echo "You have to add 'nomodeset' kernel parameter manually." - fi + pacman -Rs --noconfirm ati-dri lib32-ati-dri xf86-video-ati + pacman -Rdd --noconfirm mesa-libgl lib32-mesa-libgl + pacman -Rdd --noconfirm libcl lib32-libcl + pacman -S --noconfirm catalyst catalyst-utils lib32-catalyst-utils + aticonfig --initial + if [ $? -eq 0 ] && [ -f '/boot/syslinux/syslinux.cfg' ]; then + ex -sc '/^LABEL arch$/+3 s/$/ nomodeset/|xit' '/boot/syslinux/syslinux.cfg' + echo + echo "#### Syslinux entry:" + grep -A4 "^LABEL arch$" "/boot/syslinux/syslinux.cfg" + else + echo "You do not seem to use Syslinux. No configuration done." + echo "You have to add 'nomodeset' kernel parameter manually." + fi fi diff --git a/.scripts/task2org.awk b/.scripts/task2org.awk index 6e4ce317..082d83bb 100644 --- a/.scripts/task2org.awk +++ b/.scripts/task2org.awk @@ -4,73 +4,72 @@ ## format. WARNING: unpolished work. Use at your own risk! BEGIN { - FS="\" " + FS="\" " - tagsep=" " - project_empty="" + tagsep=" " + project_empty="" - prio_array["H"]="[#A]" - prio_array["M"]="[#B]" - prio_array["L"]="[#C]" + prio_array["H"]="[#A]" + prio_array["M"]="[#B]" + prio_array["L"]="[#C]" - recur_array["yearly"]="+1y" - recur_array["monthly"]="+1m" - recur_array["weekly"]="+1w" - recur_array["daily"]="+1d" + recur_array["yearly"]="+1y" + recur_array["monthly"]="+1m" + recur_array["weekly"]="+1w" + recur_array["daily"]="+1d" } { - gsub(/^\[|\]$/,"") - gsub(/:"/,":") + gsub(/^\[|\]$/,"") + gsub(/:"/,":") - description="" - project=project_empty - annotation="" - start="" - priority="" - recur="" - due="" - tags="" + description="" + project=project_empty + annotation="" + start="" + priority="" + recur="" + due="" + tags="" - for (i = 1; i <= NF; i++) - { - split($i, a, ":") + for (i = 1; i <= NF; i++) { + split($i, a, ":") - if (a[1] ~ "^description$") - description=a[2] " " - else if (a[1] ~ "^project$") - project=a[2] - else if (a[1] ~ "^annotation") - annotation=annotation "\n " a[2] - else if (a[1] ~ "^priority$") - priority=prio_array[a[2]] " " - else if (a[1] ~ "^tags$") - tags=tagsep ":" a[2] ": " - else if (a[1] ~ "^start$") - start="TODO " + if (a[1] ~ "^description$") + description=a[2] " " + else if (a[1] ~ "^project$") + project=a[2] + else if (a[1] ~ "^annotation") + annotation=annotation "\n " a[2] + else if (a[1] ~ "^priority$") + priority=prio_array[a[2]] " " + else if (a[1] ~ "^tags$") + tags=tagsep ":" a[2] ": " + else if (a[1] ~ "^start$") + start="TODO " - if (a[1] ~ "^recur$") - recur=" " recur_array[a[2]] + if (a[1] ~ "^recur$") + recur=" " recur_array[a[2]] - if (a[1] ~ "^due$") - due="<" strftime("%F",a[2]) + if (a[1] ~ "^due$") + due="<" strftime("%F",a[2]) - delete a - } + delete a + } - ## Close 'due' after loop in case 'recur' was encountered after 'due'. - if (due != "") - due = due recur "> " + ## Close 'due' after loop in case 'recur' was encountered after 'due'. + if (due != "") + due = due recur "> " - result[project]= result[project] "\n** " start priority description due tags annotation + result[project]= result[project] "\n** " start priority description due tags annotation } function capitalize(s) { - return toupper(substr(s,1,1)) tolower(substr(s,2)) + return toupper(substr(s,1,1)) tolower(substr(s,2)) } END { - for ( var in result) - printf ("\n* %s%s\n", capitalize(var), result[var]) + for ( var in result) + printf ("\n* %s%s\n", capitalize(var), result[var]) } diff --git a/.scripts/tc-audio-scan b/.scripts/tc-audio-scan index 999fe5c6..301e33c1 100755 --- a/.scripts/tc-audio-scan +++ b/.scripts/tc-audio-scan @@ -1,26 +1,25 @@ #!/bin/sh if ! command -v mediainfo >/dev/null 2>&1; then - echo "mediainfo required." - exit + echo "mediainfo required." + exit fi ## This will check for badly encoded audio. while IFS= read -r i; do - BUFFER="$(mediainfo "$i")" - [ -n "$(echo "$BUFFER" | grep "Bit rate mode *: Constant")" ] && echo "$i : CBR" + 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 "Cover *: Yes")" ] && echo "$i : Cover" - [ -n "$(echo "$BUFFER" | grep "Track name/Position *: 0+")" ] && echo "$i : Leading zeros" + [ -n "$(echo "$BUFFER" | grep "Track name/Position *: 0+")" ] && echo "$i : Leading zeros" done </dev/null 2>&1; then - echo "recode needed." - exit + echo "recode needed." + exit fi for i ; do - while IFS= read -r j; do - CODING=$(file "$j") + while IFS= read -r j; do + CODING=$(file "$j") - if [ -n "$(echo $CODING | grep 'ISO-8859')" ]; then - echo "ISO-8859: [$j]" - recode latin1..utf-8 "$j" + if [ -n "$(echo $CODING | grep 'ISO-8859')" ]; then + echo "ISO-8859: [$j]" + recode latin1..utf-8 "$j" - elif [ -n "$(echo $CODING | grep 'Non-ISO extended-ASCII')" ]; then - echo "cp1252: [$j]" - recode cp1252..utf-8 "$j" + elif [ -n "$(echo $CODING | grep 'Non-ISO extended-ASCII')" ]; then + echo "cp1252: [$j]" + recode cp1252..utf-8 "$j" - elif [ -n "$(echo $CODING | grep 'UTF-16 Unicode text')" ]; then - echo "UTF-16: [$j]" - recode utf-16..utf-8 "$j" + elif [ -n "$(echo $CODING | grep 'UTF-16 Unicode text')" ]; then + echo "UTF-16: [$j]" + recode utf-16..utf-8 "$j" - elif [ -n "$(echo $CODING | grep 'UTF-8 Unicode (with BOM)')" ]; then - echo "UTF-8 BOM: [$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 + elif [ -n "$(echo $CODING | grep 'UTF-8 Unicode (with BOM)')" ]; then + echo "UTF-8 BOM: [$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 - if [ -n "$(echo $CODING | grep 'CRLF')" ]; then - echo "CRLF: [$j]" - ex -sc '%s/ //g|xit' "$j" - fi + if [ -n "$(echo $CODING | grep 'CRLF')" ]; then + echo "CRLF: [$j]" + ex -sc '%s/ //g|xit' "$j" + fi - done </dev/null 2>&1; then - echo "recode needed." - exit + echo "recode needed." + exit fi for i ; do - while IFS= read -r j; do - echo -n "# " - file "$j" - grep -m1 "\`" "$j" - grep -m1 "´" "$j" - grep -m1 "oe" "$j" - done </dev/null; then - echo "ffmpeg required." - exit + echo "ffmpeg required." + exit fi -_highfreq() -{ - awk 'BEGIN{max=0} /crop=/ {t[$NF]++; if (t[$NF]>max) {max=t[$NF]; val=$NF}} END{print val}' +_highfreq() { + awk 'BEGIN{max=0} /crop=/ {t[$NF]++; if (t[$NF]>max) {max=t[$NF]; val=$NF}} END{print val}' } ## Usage: _cropvalue FILE STEP ## 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 - done | _highfreq +_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 + done | _highfreq } ## Return the audio encoding parameters. For instance @@ -161,81 +158,79 @@ _cropvalue() ## If input codec is $AUDIO_CODEC, we copy. If some stream bitrates are missing ## or 0, we encode it to a default value. If default value is 0, then we copy ## stream. -_audiobitrate() -{ - local bitrate +_audiobitrate() { + local bitrate - for i in $(seq 0 $(($format_nb_streams-1)) ); do - ## Skip non audio tracks. - [ "$(eval echo \$streams_stream_${i}_codec_type)" != "audio" ] && continue + for i in $(seq 0 $(($format_nb_streams-1)) ); do + ## Skip non audio tracks. + [ "$(eval echo \$streams_stream_${i}_codec_type)" != "audio" ] && continue - 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)) - 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 - else - [ $bitrate -gt 500 ] && bitrate=500 - printf -- "-c:%s %s -b:%s %sk " $i "$AUDIO_CODEC" $i "$bitrate" - fi - done + 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)) + 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 + else + [ $bitrate -gt 500 ] && bitrate=500 + printf -- "-c:%s %s -b:%s %sk " $i "$AUDIO_CODEC" $i "$bitrate" + fi + done } -_transcode() -{ - echo "==> [$1]" - OUTPUT="${1%.*}.$EXT" - [ -e "$OUTPUT" ] && OUTPUT="${1%.*}-$(date '+%F-%H%M%S').$EXT" +_transcode() { + echo "==> [$1]" + OUTPUT="${1%.*}.$EXT" + [ -e "$OUTPUT" ] && OUTPUT="${1%.*}-$(date '+%F-%H%M%S').$EXT" - ## Metadata (i.e. tags + technical data). - _buffer="$(ffprobe -v quiet -print_format flat=s=_ -show_streams -show_format "$1")" - if [ $? -ne 0 ]; then - _error "File [$1] is unsupported by FFmpeg." - return - fi - eval "$_buffer" - unset _buffer + ## Metadata (i.e. tags + technical data). + _buffer="$(ffprobe -v quiet -print_format flat=s=_ -show_streams -show_format "$1")" + if [ $? -ne 0 ]; then + _error "File [$1] is unsupported by FFmpeg." + return + fi + eval "$_buffer" + unset _buffer - STREAM_TITLE="" - if $OPT_REMOVE_TITLE; then - for i in $(seq 0 $(($format_nb_streams-1)) ); do - STREAM_TITLE="${STREAM_TITLE}-metadata:s:$i title= " - done - fi + STREAM_TITLE="" + if $OPT_REMOVE_TITLE; then + for i in $(seq 0 $(($format_nb_streams-1)) ); do + STREAM_TITLE="${STREAM_TITLE}-metadata:s:$i title= " + done + fi - if $OPT_CROP; then - echo "Computing crop values... " - ## For 5 different timeslices of 1 second at every 1/6th of the video, - ## we sample the crop values. We keep the values with highest - ## frequency. This is much faster than encoding in one pass with low - ## framerate. - STEP=${format_duration:-$streams_stream_0_duration} - STEP="${STEP%%.*}" - 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" \ - -f image2 -vframes 1 "${1%.*}-preview-$i-uncropped.png" - done - fi - fi + if $OPT_CROP; then + echo "Computing crop values... " + ## For 5 different timeslices of 1 second at every 1/6th of the video, + ## we sample the crop values. We keep the values with highest + ## frequency. This is much faster than encoding in one pass with low + ## framerate. + STEP=${format_duration:-$streams_stream_0_duration} + STEP="${STEP%%.*}" + 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" \ + -f image2 -vframes 1 "${1%.*}-preview-$i-uncropped.png" + done + fi + fi - ## WARNING: we mix down audio to 2 channels with '-ac 2'. This greatly - ## reduce file size and avoid any confusion for playback, which is often the - ## case when converting DTS to any other format because DTS has embedded - ## channel description which is not available in these formats. - ! $OPT_COPY && AUDIO_PARAM="$(_audiobitrate "$1") -ac 2" + ## WARNING: we mix down audio to 2 channels with '-ac 2'. This greatly + ## reduce file size and avoid any confusion for playback, which is often the + ## case when converting DTS to any other format because DTS has embedded + ## channel description which is not available in these formats. + ! $OPT_COPY && AUDIO_PARAM="$(_audiobitrate "$1") -ac 2" - cat</dev/null - done </dev/null + done </dev/null + ex - "$i" <<'EOF' >/dev/null g/^@node/d g/@tex/d g/@end tex/d diff --git a/.scripts/translate b/.scripts/translate index 4d90ee8c..a3b05296 100755 --- a/.scripts/translate +++ b/.scripts/translate @@ -2,9 +2,8 @@ ## TODO: support for long texts. -_printhelp () -{ - cat</dev/null 2>&1; then - ## Input may have empty fields, which is not normally allowed in - ## json. Let's fix this. - input="$(sed -e 's/,\+/,/g' -e 's/\[,\+/\[/g' -e 's/,\+\]/\]/g')" + if command -v jshon >/dev/null 2>&1; then + ## Input may have empty fields, which is not normally allowed in + ## json. Let's fix this. + input="$(sed -e 's/,\+/,/g' -e 's/\[,\+/\[/g' -e 's/,\+\]/\]/g')" - ## The use of jshon without checking the array size is unsafe. If the - ## size is not as expected, it probably means that source and target - ## languages are the same. Anyhow, we drop the error output. + ## The use of jshon without checking the array size is unsafe. If the + ## size is not as expected, it probably means that source and target + ## languages are the same. Anyhow, we drop the error output. - ## Google Translate does not have the same structure when English is - ## involved. With English, the list of translations is in cell 1, - ## whitout English it is in cell 3. Without English, there is no - ## distinction on grammatical type. - if [ "$(echo "$input" | jshon -e 1 -t)" = "string" ]; then - ## No English - echo "$input" | jshon -e 3 -e 0 -e 2 -a -e 0 -u | tr '\n' ',' | sed 's/,$/\n/' - else - count=0 - ## Fetch grammatical type in 'type'. - while read -r type; do - echo -n $type: + ## Google Translate does not have the same structure when English is + ## involved. With English, the list of translations is in cell 1, + ## whitout English it is in cell 3. Without English, there is no + ## distinction on grammatical type. + if [ "$(echo "$input" | jshon -e 1 -t)" = "string" ]; then + ## No English + echo "$input" | jshon -e 3 -e 0 -e 2 -a -e 0 -u | tr '\n' ',' | sed 's/,$/\n/' + else + count=0 + ## Fetch grammatical type in 'type'. + while read -r type; do + echo -n $type: - ## Fetch translation alternative from count-th entry - echo "$input" | jshon -e 1 -e $count -e 1 -a -u | tr '\n' ',' | sed 's/,$/\n/' - count=$(($count+1)) + ## Fetch translation alternative from count-th entry + echo "$input" | jshon -e 1 -e $count -e 1 -a -u | tr '\n' ',' | sed 's/,$/\n/' + count=$(($count+1)) - done</dev/null + fi 2>/dev/null - else - ## Use sed to fetch first entry only. - sed -e 's/\[\[\[[^[]*\[\[[^[]*\[\([^[]*\)\].*/\1/' -e 's/"//g' - echo - fi + else + ## Use sed to fetch first entry only. + sed -e 's/\[\[\[[^[]*\[\[[^[]*\[\([^[]*\)\].*/\1/' -e 's/"//g' + echo + fi } -_translate() -{ - TEXT="$(tr '\n' ' ' | sed 's/[\t ]\+/%20/g')" - ## If input is not a single word, disable alternative translations. We use a - ## point in the grep string to ignore any space at the end. - [ -n "$(echo $TEXT | grep '%20.')" ] && OPT_LONG=false +_translate () { + TEXT="$(tr '\n' ' ' | sed 's/[\t ]\+/%20/g')" + ## If input is not a single word, disable alternative translations. We use a + ## point in the grep string to ignore any space at the end. + [ -n "$(echo $TEXT | grep '%20.')" ] && OPT_LONG=false - if [ "$SL" = "" ]; then - curl -A "Mozilla/5.0" 'http://translate.google.com/translate_a/t?client=t&text='$TEXT'&tl='$TL'&ie=UTF-8&oe=UTF-8' - else - curl -A "Mozilla/5.0" 'http://translate.google.com/translate_a/t?client=t&text='$TEXT'&sl='$SL'&tl='$TL'&ie=UTF-8&oe=UTF-8' - fi 2>/dev/null | _filter + if [ "$SL" = "" ]; then + curl -A "Mozilla/5.0" 'http://translate.google.com/translate_a/t?client=t&text='$TEXT'&tl='$TL'&ie=UTF-8&oe=UTF-8' + else + curl -A "Mozilla/5.0" 'http://translate.google.com/translate_a/t?client=t&text='$TEXT'&sl='$SL'&tl='$TL'&ie=UTF-8&oe=UTF-8' + fi 2>/dev/null | _filter } if [ $# -ne 0 ]; then - echo "$@" | _translate + echo "$@" | _translate else - _translate + _translate fi ## Original command: diff --git a/.scripts/trc b/.scripts/trc index 0b9adf86..d372e336 100755 --- a/.scripts/trc +++ b/.scripts/trc @@ -1,7 +1,7 @@ #!/bin/sh if [ "$1" = "-h" ]; then - cat</dev/null 2>&1; then - echo >&2 "'$i' not found in PATH. Exiting." - exit 1 - fi - done +check () { + for i ; do + if ! command -v $i >/dev/null 2>&1; then + echo >&2 "'$i' not found in PATH. Exiting." + exit 1 + fi + done } + check transmission-daemon transmission-remote-cli [ $(ps -U $USER | grep -c transmission-da) -eq 0 ] && transmission-daemon if [ $# -eq 0 ]; then - exec transmission-remote-cli + exec transmission-remote-cli else - ## The 'sleep' is needed here to give the daemon some time to start. 1 sec - ## should be enough on most system. - sleep 1 - transmission-remote "$@" + ## The 'sleep' is needed here to give the daemon some time to start. 1 sec + ## should be enough on most system. + sleep 1 + transmission-remote "$@" fi - diff --git a/.scripts/wget-batch b/.scripts/wget-batch index 71b13ab6..c473cdc1 100755 --- a/.scripts/wget-batch +++ b/.scripts/wget-batch @@ -1,12 +1,12 @@ #!/bin/sh if [ $# -ne 2 ]; then - cat</dev/null; then - echo "You need osd_cat." - exit + echo "You need osd_cat." + exit fi ## The unbuffered option is -u on GNU and OpenBSD, -l on others. OPT_UNBUF=-l if [ "$(uname)" = "Linux" ] || [ "$(uname)" = "OpenBSD" ]; then - OPT_UNBUF=-u + OPT_UNBUF=-u fi WINEDEBUG=fps wine "$@" 2>&1 | tee /dev/stderr | \ - sed $OPT_UNBUF -n '/^trace:fps:/{s/.* \([^ ]*\)fps/\1/;p}' | \ - osd_cat -l1 -f "-*-*-*-*-*-*-32-*-*-*-*-*-*-*" -O1 -c "yellow" - + sed $OPT_UNBUF -n '/^trace:fps:/{s/.* \([^ ]*\)fps/\1/;p}' | \ + osd_cat -l1 -f "-*-*-*-*-*-*-32-*-*-*-*-*-*-*" -O1 -c "yellow" diff --git a/.scripts/zshcd b/.scripts/zshcd index 329c8ff7..db11866b 100755 --- a/.scripts/zshcd +++ b/.scripts/zshcd @@ -3,8 +3,8 @@ ## browsers to start shell in pointed folder. if [ ! -d "$1" ]; then - zsh - exit + zsh + exit fi ## Default files. @@ -12,30 +12,30 @@ ZDIRS="$HOME/.cache/zsh/dirs" ## Fetch file location dynamically. if [ ! -f ~/.zshrc ]; then - echo '~/.zshrc not found. Exiting.' - exit 1 + echo '~/.zshrc not found. Exiting.' + exit 1 fi ## We need realpath to prevent us from adding duplicates to the zsh ## DIRSTACKFILE. if ! command -v realpath >/dev/null 2>&1; then - echo "'realpath' not found. Exiting." - exit 1 + echo "'realpath' not found. Exiting." + exit 1 fi SHELL_DIR_GREP="$(grep "SHELL_DIR=" ~/.zshrc | cut -f2 -d=)" [ -n "$SHELL_DIR_GREP" ] && SHELL_DIR="$(eval echo "$SHELL_DIR_GREP")" if [ ! -d "$SHELL_DIR" ]; then - echo 'SHELL_DIR not found. Could not search for DIRSTACKFILE. Exiting.' - exit 1 + echo 'SHELL_DIR not found. Could not search for DIRSTACKFILE. Exiting.' + exit 1 fi ZDIRS_GREP="$(grep -rm1 'DIRSTACKFILE=' "$SHELL_DIR" | cut -f2 -d=)" [ -n "$ZDIRS_GREP" ] && ZDIRS="$(eval echo "$ZDIRS_GREP")" if [ ! -f "$ZDIRS" ]; then - echo 'DIRSTACKFILE not found. Exiting.' - exit 1 + echo 'DIRSTACKFILE not found. Exiting.' + exit 1 fi ## Prepend argument to zsh dirstack.