scripts: Reformat with tabs and more consistent style

master
Pierre Neidhardt 2014-11-12 16:15:39 +01:00
parent a248dd1c19
commit 9857145fb1
74 changed files with 1592 additions and 1650 deletions

View File

@ -1,8 +1,7 @@
#!/bin/sh #!/bin/sh
_printhelp() _usage () {
{ cat <<EOF
cat <<EOF
Usage: ${1##*/} MODE Usage: ${1##*/} MODE
This script was generated with tc-video-custom. This script was generated with tc-video-custom.
@ -22,56 +21,50 @@ EOF
SAMPLE="" SAMPLE=""
OPT_PROCESS=false OPT_PROCESS=false
while getopts ":hef" opt; do while getopts ":hef" opt; do
case $opt in case $opt in
h) h)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
e) e)
SAMPLE="-ss 60 -t 60" SAMPLE="-ss 60 -t 60"
OPT_PROCESS=true ;; OPT_PROCESS=true ;;
f) f)
OPT_PROCESS=true ;; OPT_PROCESS=true ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
:)
echo "Missing argument."
_printhelp "$0"
exit 1 ;;
esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if ! $OPT_PROCESS; then if ! $OPT_PROCESS; then
_printhelp "$0" _usage "$0"
exit exit
fi fi
if ! command -v ffmpeg >/dev/null 2>&1; then if ! command -v ffmpeg >/dev/null 2>&1; then
echo >&2 "'ffmpeg' not found in PATH. Exiting." echo >&2 "'ffmpeg' not found in PATH. Exiting."
exit 1 exit 1
fi fi
_transcode () _transcode () {
{ ## You can choose here to process all files at the same time. Useful if you
## You can choose here to process all files at the same time. Useful if you ## need to remux streams or to concatenate.
## need to remux streams or to concatenate. # ffmpeg -i ###FILELIST \
# ffmpeg -i ###FILELIST \ ffmpeg -nostdin -i "$@" \
ffmpeg -nostdin -i "$@" \ -c:v libx264 -preset slow -crf 20 \
-c:v libx264 -preset slow -crf 20 \ -c:a libvorbis -b:a 192k -ac 2 \
-c:a libvorbis -b:a 192k -ac 2 \ -c:s copy \
-c:s copy \ -map 0 \
-map 0 \ $SAMPLE \
$SAMPLE \ "${1%.*}-$(date '+%F-%H%M%S').mkv"
"${1%.*}-$(date '+%F-%H%M%S').mkv"
} }
set -- ###FILENAMES set -- ###FILENAMES
## Choose to process all files one after another. ## Choose to process all files one after another.
for i ; do for i ; do
_transcode "$i" _transcode "$i"
done done
## Or all files at the same time. You have to change the ffmpeg input in the ## Or all files at the same time. You have to change the ffmpeg input in the

View File

@ -4,9 +4,8 @@
UPSTREAM_SOURCE="srcdir" UPSTREAM_SOURCE="srcdir"
## End of user config ## End of user config
_printhelp () _usage () {
{ cat <<EOF
cat <<EOF
Usage: ${1##*/} [OPTIONS] PACKAGES Usage: ${1##*/} [OPTIONS] PACKAGES
WARNING: development version. Not reliable for AUR-dependency resolution. WARNING: development version. Not reliable for AUR-dependency resolution.
@ -39,15 +38,15 @@ Options:
Example: Example:
${1##*/} -icf \$(pacman -Qmq) ${1##*/} -icf \$(pacman -Qmq)
For all foreign installed packages, force fetch PKGBUILD, fetch source code For all foreign installed packages, force fetch PKGBUILD, fetch source code
if not available, build if not already build, force installing and clean if not available, build if not already build, force installing and clean
build folder. build folder.
${1##*/} -sbicf nawk ncdu ${1##*/} -sbicf nawk ncdu
For all foreign installed packages, fetch PKGBUILD and source code if not For all foreign installed packages, fetch PKGBUILD and source code if not
available, force build if not already build, force installing and clean available, force build if not already build, force installing and clean
build folder. build folder.
EOF EOF
} }
@ -63,46 +62,60 @@ OPT_INSTALL=false
OPT_SOURCE=false OPT_SOURCE=false
while getopts ":bcCfhis" opt; do while getopts ":bcCfhis" opt; do
case $opt in case $opt in
b) b)
OPT_BUILD=true ;; OPT_BUILD=true ;;
c) c)
MAKEPKG_OPT="$MAKEPKG_OPT -c" MAKEPKG_OPT="$MAKEPKG_OPT -c"
OPT_CLEAN=true ;; OPT_CLEAN=true ;;
C) C)
OPT_MRPROPER=true ;; OPT_MRPROPER=true ;;
f) f)
MAKEPKG_OPT="$MAKEPKG_OPT -f" MAKEPKG_OPT="$MAKEPKG_OPT -f"
PACMAN_OPT="" PACMAN_OPT=""
OPT_FORCE=true ;; OPT_FORCE=true ;;
h) h)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
i) i)
OPT_INSTALL=true ;; OPT_INSTALL=true ;;
s) s)
OPT_SOURCE=true ;; OPT_SOURCE=true ;;
?) \?)
_printhelp "$0" echo 'HO'
exit 1 ;; _usage "$0"
:) exit 1 ;;
echo "Missing argument." esac
_printhelp "$0"
exit 1 ;;
esac
done done
usage () {
cat<<EOF
Usage: ${1##*/} [OPTIONS] FILES
Options:
-h: Show this help.
EOF
}
shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then
usage "$0"
exit 1
fi
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
echo "Missing argument." echo "Missing argument."
_printhelp "$0" _usage "$0"
exit 1 exit 1
fi fi
if ! command -v makepkg >/dev/null; then if ! command -v makepkg >/dev/null; then
echo "You need makepkg to run this script." echo "You need makepkg to run this script."
exit 1 exit 1
fi fi
HAS_ABS=false HAS_ABS=false
@ -111,123 +124,115 @@ command -v abs >/dev/null && HAS_ABS=true
command -v yaourt >/dev/null && HAS_YAOURT=true command -v yaourt >/dev/null && HAS_YAOURT=true
if ! $HAS_ABS && ! $HAS_YAOURT; then if ! $HAS_ABS && ! $HAS_YAOURT; then
echo "Please install either an ABS-tree or yaourt." echo "Please install either an ABS-tree or yaourt."
exit 1 exit 1
fi fi
if $HAS_ABS && [ -f "/etc/abs.conf" ]; then if $HAS_ABS && [ -f "/etc/abs.conf" ]; then
. "/etc/abs.conf" . "/etc/abs.conf"
[ "$ABSROOT" = "" ] && ABSROOT="/var/abs/" [ "$ABSROOT" = "" ] && ABSROOT="/var/abs/"
fi fi
################################################################################ ################################################################################
abs_pkgbuild () abs_pkgbuild () {
{ pacman -Si $1 >/dev/null 2>&1
pacman -Si $1 >/dev/null 2>&1 if [ $? -eq 0 ] && $HAS_ABS && [ -d "$ABSROOT" ]; then
if [ $? -eq 0 ] && $HAS_ABS && [ -d "$ABSROOT" ]; then cp -r /var/abs/*/$1 .
cp -r /var/abs/*/$1 . else
else yaourt -G "$1" --noconfirm
yaourt -G "$1" --noconfirm fi
fi
} }
abs_source () abs_source () {
{ (cd "$1" && \
(cd "$1" && \ mkdir -p "$UPSTREAM_SOURCE" && \
mkdir -p "$UPSTREAM_SOURCE" && \ SRCDEST="$UPSTREAM_SOURCE" makepkg -o)
SRCDEST="$UPSTREAM_SOURCE" makepkg -o)
} }
## TODO: unused function. Add 'build all deps from source' parameter? ## TODO: unused function. Add 'build all deps from source' parameter?
abs_builddeps () abs_builddeps () {
{ DEPLIST=$(awk -F"'" '/^(make)?depends *= *\(/,/\)/ {for (n=2 ; n<NF; n++) res=res $n " "} END {gsub(/ +/, " ", res); print res}' PKGBUILD)
DEPLIST=$(awk -F"'" '/^(make)?depends *= *\(/,/\)/ {for (n=2 ; n<NF; n++) res=res $n " "} END {gsub(/ +/, " ", res); print res}' PKGBUILD) (cd .. && abs-wrapper $DEPLIST)
(cd .. && abs-wrapper $DEPLIST)
} }
abs_buildmissing () abs_buildmissing () {
{ DEPLIST="$(makepkg -s 2>&1 | awk -F: '/target not found/ {print $3}')"
DEPLIST="$(makepkg -s 2>&1 | awk -F: '/target not found/ {print $3}')" cd ..
cd .. while IFS= read -r p; do
while IFS= read -r p; do abs_pkgbuild $p
abs_pkgbuild $p abs_build $p
abs_build $p abs_install $p
abs_install $p done <<EOF
done <<EOF ${DEPLIST}
${DEPLIST}
EOF EOF
cd $1 cd $1
} }
abs_build () abs_build () {
{ (cd "$1" && \
(cd "$1" && \ mkdir -p "$UPSTREAM_SOURCE" && \
mkdir -p "$UPSTREAM_SOURCE" && \ (makepkg -s || \
(makepkg -s || \ if [ $? -ne 0 ]; then abs_buildmissing $1; fi ) && \
if [ $? -ne 0 ]; then abs_buildmissing $1; fi ) && \ SRCDEST="$UPSTREAM_SOURCE" makepkg -r $MAKEPKG_OPT --nocheck --noconfirm)
SRCDEST="$UPSTREAM_SOURCE" makepkg -r $MAKEPKG_OPT --nocheck --noconfirm)
} }
abs_clean () abs_clean () {
{ (cd "$1" && \
(cd "$1" && \ echo "Removing src/ and pkg/ folders." && \
echo "Removing src/ and pkg/ folders." && \ rm -rf "src" "pkg")
rm -rf "src" "pkg")
} }
abs_mrproper () abs_mrproper () {
{ (cd "$1" && \
(cd "$1" && \ echo "Removing archives." && \
echo "Removing archives." && \ rm -v *.tar.gz *.tar.xz *.tar.bz *.tar.bz2 *.tgz *.txz *.tbz *.tbz2 2>/dev/null)
rm -v *.tar.gz *.tar.xz *.tar.bz *.tar.bz2 *.tgz *.txz *.tbz *.tbz2 2>/dev/null)
} }
abs_install () abs_install () {
{ sudo sh -c '
sudo sh -c ' (cd "$0" && pacman '$PACMAN_OPT' --noconfirm -U *.pkg.tar.xz)
(cd "$0" && pacman '$PACMAN_OPT' --noconfirm -U *.pkg.tar.xz) for i; do
for i; do (cd "$i" && pacman '$PACMAN_OPT' --noconfirm -U *.pkg.tar.xz)
(cd "$i" && pacman '$PACMAN_OPT' --noconfirm -U *.pkg.tar.xz) done
done
' "$@" ' "$@"
} }
for i ; do for i ; do
echo "==> Processing $i." echo "==> Processing $i."
## Fetch PKGBUILD. ## Fetch PKGBUILD.
if [ ! -f "$i/PKGBUILD" ] || $OPT_FORCE; then if [ ! -f "$i/PKGBUILD" ] || $OPT_FORCE; then
abs_pkgbuild "$i" abs_pkgbuild "$i"
fi fi
## Skip because $i does not exist. ## Skip because $i does not exist.
[ ! -d "$i" ] && continue [ ! -d "$i" ] && continue
## Fetch source code. ## Fetch source code.
if $OPT_SOURCE; then if $OPT_SOURCE; then
abs_source "$i" abs_source "$i"
fi fi
## Build. ## Build.
if $OPT_BUILD || ($OPT_INSTALL && [ ! -f $i/*.pkg.tar.xz ]); then if $OPT_BUILD || ($OPT_INSTALL && [ ! -f $i/*.pkg.tar.xz ]); then
abs_build "$i" abs_build "$i"
fi fi
## Clean build folder. ## Clean build folder.
if $OPT_CLEAN; then if $OPT_CLEAN; then
abs_clean "$i" abs_clean "$i"
fi fi
## Remove archives. ## Remove archives.
if $OPT_MRPROPER; then if $OPT_MRPROPER; then
abs_mrproper "$i" abs_mrproper "$i"
fi fi
done done
## Install packages. We put the install part outside the loop so that we prompt ## Install packages. We put the install part outside the loop so that we prompt
## for password one time only. ## for password one time only.
if $OPT_INSTALL; then if $OPT_INSTALL; then
abs_install "$@" abs_install "$@"
fi fi

View File

@ -1,8 +1,7 @@
#!/bin/sh #!/bin/sh
_printhelp() _usage () {
{ cat <<EOF
cat <<EOF
Usage: ${1##*/} [-m METHOD] [-v] FILES|FOLDERS Usage: ${1##*/} [-m METHOD] [-v] FILES|FOLDERS
Create an archive in current folder from a single or multiples Create an archive in current folder from a single or multiples
@ -27,84 +26,83 @@ ARCOPT="z"
OPTIONS="" OPTIONS=""
OPT_SPLIT=false OPT_SPLIT=false
while getopts ":him:sv" opt; do while getopts ":him:sv" opt; do
case $opt in case $opt in
h) h)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
i) i)
OPTIONS="$OPTIONS --owner=root --group=root --numeric-owner" ;; OPTIONS="$OPTIONS --owner=root --group=root --numeric-owner" ;;
m) m)
[ "$OPTARG" = "gz" ] && ARCEXT=".gz" && ARCOPT="z" [ "$OPTARG" = "gz" ] && ARCEXT=".gz" && ARCOPT="z"
[ "$OPTARG" = "xz" ] && ARCEXT=".xz" && ARCOPT="J" [ "$OPTARG" = "xz" ] && ARCEXT=".xz" && ARCOPT="J"
[ "$OPTARG" = "none" ] && ARCEXT="" && ARCOPT="" [ "$OPTARG" = "none" ] && ARCEXT="" && ARCOPT=""
;; ;;
s) s)
OPT_SPLIT=true ;; OPT_SPLIT=true ;;
v) v)
OPTIONS="$OPTIONS --exclude-vcs" ;; OPTIONS="$OPTIONS --exclude-vcs" ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_printhelp "$0" _usage "$0"
exit 1 exit 1
fi fi
## We need 'realpath' since we need to work on the real path for the input ## We need 'realpath' since we need to work on the real path for the input
## files/folders and the archive location. Otherwise we could have troubles with ## files/folders and the archive location. Otherwise we could have troubles with
## circular symlinks and so on. ## circular symlinks and so on.
if ! command -v realpath >/dev/null 2>&1; then if ! command -v realpath >/dev/null 2>&1; then
echo >&2 "'realpath' not found in PATH. Exiting." echo >&2 "'realpath' not found in PATH. Exiting."
exit 1 exit 1
fi fi
_archive() _archive () {
{ ## Only one input entry: use it as base name for the archive.
## Only one input entry: use it as base name for the archive. if [ $# -eq 1 ]; then
if [ $# -eq 1 ]; then REALPATH="$(realpath "$1")"
REALPATH="$(realpath "$1")" OUTFILE="${REALPATH##*/}-$(date +%F-%H%M%S).tar${ARCEXT}"
OUTFILE="${REALPATH##*/}-$(date +%F-%H%M%S).tar${ARCEXT}" else
else OUTFILE="${PWD##*/}-$(date +%F-%H%M%S).tar${ARCEXT}"
OUTFILE="${PWD##*/}-$(date +%F-%H%M%S).tar${ARCEXT}" fi
fi
REALPWD="$(realpath "$PWD")" REALPWD="$(realpath "$PWD")"
for i; do for i; do
REALPATH="$(realpath "$i")" REALPATH="$(realpath "$i")"
## Check if one of the arguments is current folder. We need to make sure the ## 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 ## archive is not created in an input folder, otherwise it will include
## itself. ## itself.
if [ "$REALPATH" = "$REALPWD" ]; then if [ "$REALPATH" = "$REALPWD" ]; then
OUTPATH="$(realpath "$REALPWD/..")" OUTPATH="$(realpath "$REALPWD/..")"
break break
fi fi
done done
if [ ! -w "$OUTPATH" ]; then if [ ! -w "$OUTPATH" ]; then
echo "[$OUTPATH] is not writable. Exiting." echo "[$OUTPATH] is not writable. Exiting."
return return
fi fi
echo "==> [$OUTPATH/$OUTFILE]" echo "==> [$OUTPATH/$OUTFILE]"
for i; do for i; do
REALPATH="$(realpath "$i")" REALPATH="$(realpath "$i")"
echo "${REALPATH}" >&2 echo "${REALPATH}" >&2
echo "-C '${REALPATH%/*}'" echo "-C '${REALPATH%/*}'"
echo "${REALPATH##*/}" echo "${REALPATH##*/}"
done | tar $OPTIONS -${ARCOPT}cf "$OUTPATH/$OUTFILE" -T - done | tar $OPTIONS -${ARCOPT}cf "$OUTPATH/$OUTFILE" -T -
} }
if $OPT_SPLIT; then if $OPT_SPLIT; then
for j ; do for j ; do
_archive "$j" _archive "$j"
done done
else else
_archive "$@" _archive "$@"
fi fi

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
cat <<EOF cat <<EOF
Usage: ${0##*/} [FILES] Usage: ${0##*/} [FILES]
Convert non-ASCII characters to their ASCII equivalent. If no files are Convert non-ASCII characters to their ASCII equivalent. If no files are
@ -12,66 +12,66 @@ Options:
-i: If files are provided, convert them in-place. -i: If files are provided, convert them in-place.
EOF EOF
exit exit
fi fi
unset OPT unset OPT
if [ "$1" = "-i" ]; then if [ "$1" = "-i" ]; then
OPT=-i OPT=-i
shift shift
fi fi
## Note that we also use 'sed -i' to edit files instead of 'ex'. Otherwise the ## Note that we also use 'sed -i' to edit files instead of 'ex'. Otherwise the
## code looks ugly if we try to handle both stdin and files with only one ## code looks ugly if we try to handle both stdin and files with only one
## call. Besides, ex does not support multiple file editing. ## call. Besides, ex does not support multiple file editing.
sed $OPT \ sed $OPT \
-e 's/[áàâä]/a/g' \ -e 's/[áàâä]/a/g' \
-e 's/[éèêë]/e/g' \ -e 's/[éèêë]/e/g' \
-e 's/[íìîï]/i/g' \ -e 's/[íìîï]/i/g' \
-e 's/[óòôö]/o/g' \ -e 's/[óòôö]/o/g' \
-e 's/[úùûü]/u/g' \ -e 's/[úùûü]/u/g' \
-e 's/[ýỳŷÿ]/y/g' \ -e 's/[ýỳŷÿ]/y/g' \
-e 's/[ÁÀÂÄ]/A/g' \ -e 's/[ÁÀÂÄ]/A/g' \
-e 's/[ÉÈÊË]/E/g' \ -e 's/[ÉÈÊË]/E/g' \
-e 's/[ÍÌÎÏ]/I/g' \ -e 's/[ÍÌÎÏ]/I/g' \
-e 's/[ÓÒÔÖ]/O/g' \ -e 's/[ÓÒÔÖ]/O/g' \
-e 's/[ÚÙÛÜ]/U/g' \ -e 's/[ÚÙÛÜ]/U/g' \
-e 's/[ÝỲŶŸ]/Y/g' \ -e 's/[ÝỲŶŸ]/Y/g' \
-e 's/[ñ]/n/g' \ -e 's/[ñ]/n/g' \
-e 's/[œ]/oe/g' \ -e 's/[œ]/oe/g' \
-e 's/[Œ]/Oe/g' \ -e 's/[Œ]/Oe/g' \
-e 's/[æ]/ae/g' \ -e 's/[æ]/ae/g' \
-e 's/[Æ]/Ae/g' \ -e 's/[Æ]/Ae/g' \
-e 's/[ç]/c/g' \ -e 's/[ç]/c/g' \
-e 's/[Ç]/C/g' \ -e 's/[Ç]/C/g' \
-e 's/[ß]/ss/g' \ -e 's/[ß]/ss/g' \
-e 's/[«»„“”‚‘’]/"/g' \ -e 's/[«»„“”‚‘’]/"/g' \
-e 's/[©]/(C)/g' \ -e 's/[©]/(C)/g' \
-e 's/[®]/(R)/g' \ -e 's/[®]/(R)/g' \
-e 's/[™]/(TM)/g' \ -e 's/[™]/(TM)/g' \
-e 's/[¥]/Y/g' \ -e 's/[¥]/Y/g' \
-e 's/[Ð]/D/g' \ -e 's/[Ð]/D/g' \
-e 's/[ŀ]/l/g' \ -e 's/[ŀ]/l/g' \
-e 's/[Ŀ]/L/g' \ -e 's/[Ŀ]/L/g' \
-e 's/[€]/euro/g' \ -e 's/[€]/euro/g' \
-e 's/[¢]/cent/g' \ -e 's/[¢]/cent/g' \
-e 's/[£]/pound/g' \ -e 's/[£]/pound/g' \
-e 's/[µ]/mu/g' \ -e 's/[µ]/mu/g' \
-e 's/[²]/^2/g' \ -e 's/[²]/^2/g' \
-e 's/[³]/^3/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/[≤]/<=/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/[×]/x/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/[→]/=>/g' \
"$@" "$@"

View File

@ -1,7 +1,7 @@
#!/usr/bin/env zsh #!/usr/bin/env zsh
if [ $# -gt 2 ] || [ $# -lt 1 ] || [ "$1" = "-h" ]; then if [ $# -gt 2 ] || [ $# -lt 1 ] || [ "$1" = "-h" ]; then
cat <<EOF cat <<EOF
Usage: ${0##*/} FILE [STRING] Usage: ${0##*/} FILE [STRING]
Append to all STRING found in FILE a secret phrase being prompted. If STRING is Append to all STRING found in FILE a secret phrase being prompted. If STRING is
@ -15,7 +15,7 @@ POSIX-compliant shells.
This is a stupid program, don't use it. This is a stupid program, don't use it.
EOF EOF
exit exit
fi fi
FILE="$1" FILE="$1"
@ -23,7 +23,7 @@ STRING=""
DUMMY="" DUMMY=""
if [ $# -eq 2 ]; then if [ $# -eq 2 ]; then
STRING="$2" STRING="$2"
fi fi
echo -n "Secret: " echo -n "Secret: "
@ -31,15 +31,15 @@ read -s DUMMY
echo "" echo ""
if [ ! -e "$FILE" ] || [ -z "$STRING" ]; then if [ ! -e "$FILE" ] || [ -z "$STRING" ]; then
echo "$DUMMY" >> "$FILE" echo "$DUMMY" >> "$FILE"
echo "Secret appended to ${FILE} at the end." echo "Secret appended to ${FILE} at the end."
exit exit
fi fi
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
echo "$DUMMY" >> "$FILE" echo "$DUMMY" >> "$FILE"
else else
ex -sc "%s/${STRING}/${STRING}${DUMMY}/g|xit" "${FILE}" ex -sc "%s/${STRING}/${STRING}${DUMMY}/g|xit" "${FILE}"
fi fi
echo "Secret appended to ${FILE}." echo "Secret appended to ${FILE}."

View File

@ -5,8 +5,8 @@
## then exit to shell, without closing the terminal. ## then exit to shell, without closing the terminal.
if [ -z "$TERMCMD" ]; then if [ -z "$TERMCMD" ]; then
echo 'TERMCMD not set. Exiting.' echo 'TERMCMD not set. Exiting.'
exit exit
fi fi
export BROWSER_AUTOSTART=true export BROWSER_AUTOSTART=true

View File

@ -1,37 +1,36 @@
#!/bin/sh #!/bin/sh
if [ "${0##*/}" = "obsdman" ]; then if [ "${0##*/}" = "obsdman" ]; then
OS=OpenBSD OS=OpenBSD
DOMAIN="http://www.openbsd.org/cgi-bin" DOMAIN="http://www.openbsd.org/cgi-bin"
MANPATH="OpenBSD+Current" MANPATH="OpenBSD+Current"
else else
OS=FreeBSD OS=FreeBSD
DOMAIN="http://www.freebsd.org/cgi" DOMAIN="http://www.freebsd.org/cgi"
MANPATH="FreeBSD+10-current" MANPATH="FreeBSD+10-current"
fi fi
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} [SECTION] PAGE Usage: ${0##*/} [SECTION] PAGE
Fetch $OS man page PAGE from the official website and display it. Fetch $OS man page PAGE from the official website and display it.
EOF EOF
exit exit
fi fi
SECTION=0 SECTION=0
PAGE=$1 PAGE=$1
if [ $# -eq 2 ]; then if [ $# -eq 2 ]; then
SECTION="$1" SECTION="$1"
PAGE="$2" PAGE="$2"
fi fi
AGENT="curl -s" AGENT="curl -s"
if ! command -v curl >/dev/null 2>&1; then if ! command -v curl >/dev/null 2>&1; then
AGENT="wget -q -O - " AGENT="wget -q -O - "
fi fi
$AGENT "$DOMAIN/man.cgi?query=$PAGE&apropos=0&sektion=$SECTION&manpath=$MANPATH&arch=default&format=ascii" | less $AGENT "$DOMAIN/man.cgi?query=$PAGE&apropos=0&sektion=$SECTION&manpath=$MANPATH&arch=default&format=ascii" | less

View File

@ -1,8 +1,7 @@
#!/bin/sh #!/bin/sh
_printhelp () _usage () {
{ cat<<EOF
cat<<EOF
Usage: ${1##*/} [OPTIONS] ISOFILE Usage: ${1##*/} [OPTIONS] ISOFILE
Dump optical disc to ISOFILE (without extension). Dump optical disc to ISOFILE (without extension).
@ -17,28 +16,28 @@ EOF
DRIVE=/dev/sr0 DRIVE=/dev/sr0
while getopts ":hd:" opt; do while getopts ":hd:" opt; do
case $opt in case $opt in
h) h)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
d) d)
DRIVE=/dev/$OPTARG ;; DRIVE=/dev/$OPTARG ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_printhelp "$0" _usage "$0"
exit 1 exit 1
fi fi
if ! command -v readcd >/dev/null 2>&1; then if ! command -v readcd >/dev/null 2>&1; then
echo >&2 "'readcd' not found in PATH. Exiting." echo >&2 "'readcd' not found in PATH. Exiting."
exit 1 exit 1
fi fi
## Fast? ## Fast?

View File

@ -4,14 +4,14 @@ COLUMN="1"
FORMAT="TOTAL: %s\n" FORMAT="TOTAL: %s\n"
if [ "$1" = "-h" ]; then if [ "$1" = "-h" ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} [COLUMN] [FORMAT] Usage: ${0##*/} [COLUMN] [FORMAT]
Sum COLUMN (default to column $COLUMN) and output result with format FORMAT Sum COLUMN (default to column $COLUMN) and output result with format FORMAT
(default to $FORMAT). (default to $FORMAT).
EOF EOF
exit exit
fi fi
[ $# -ge 1 ] && COLUMN="$1" && shift [ $# -ge 1 ] && COLUMN="$1" && shift

View File

@ -1,19 +1,19 @@
#!/bin/sh #!/bin/sh
if [ "$1" = "-h" ]; then if [ "$1" = "-h" ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} Usage: ${0##*/}
Return the CPU usage. Linux only. Return the CPU usage. Linux only.
EOF EOF
exit exit
fi fi
if [ ! "$(uname)" = "Linux" ]; then if [ ! "$(uname)" = "Linux" ]; then
echo "Linux only." echo "Linux only."
exit exit
fi fi
@ -58,7 +58,7 @@ idleB=$f4
totaldiff=$((${totalB:-0}-${totalA:-0})) totaldiff=$((${totalB:-0}-${totalA:-0}))
if [ $totaldiff -eq 0 ]; then if [ $totaldiff -eq 0 ]; then
echo 0 echo 0
else else
echo "$((100 - 100 * ($idleB-$idleA) / $totaldiff ))" echo "$((100 - 100 * ($idleB-$idleA) / $totaldiff ))"
fi fi

View File

@ -3,8 +3,8 @@
rawname=${0##*/} rawname=${0##*/}
rawname=${rawname#c} rawname=${rawname#c}
usage() { usage () {
cat <<EOF cat <<EOF
Usage: ${1##*/} Usage: ${1##*/}
Run `sessionclean' if available and $rawname the system. Run `sessionclean' if available and $rawname the system.
@ -14,26 +14,26 @@ EOF
if [ "$1" = "-h" ]; then if [ "$1" = "-h" ]; then
usage "$0" usage "$0"
exit exit
fi fi
## Check values. ## Check values.
case $rawname in case $rawname in
poweroff) ;; poweroff) ;;
reboot) ;; reboot) ;;
halt) ;; halt) ;;
*) *)
usage "$0" usage "$0"
exit ;; exit ;;
esac esac
command -v sessionclean >/dev/null 2>&1 && sessionclean command -v sessionclean >/dev/null 2>&1 && sessionclean
if command -v systemctl >/dev/null 2>&1; then if command -v systemctl >/dev/null 2>&1; then
$rawname $rawname
then then
## If you do not want to get prompted for your password, configure sudo ## If you do not want to get prompted for your password, configure sudo
## properly. ## properly.
sudo $rawname sudo $rawname
fi fi

View File

@ -1,12 +1,12 @@
#!/bin/sh #!/bin/sh
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} FILE [FLAGS] Usage: ${0##*/} FILE [FLAGS]
Simulate a C interpreter by compiling, executing and removing file in one run. Simulate a C interpreter by compiling, executing and removing file in one run.
EOF EOF
exit exit
fi fi
[ -z "$CC" ] && CC=gcc [ -z "$CC" ] && CC=gcc

View File

@ -3,54 +3,51 @@
## WARNING: this script will NOT work for entries that have a comma between double quotes. ## WARNING: this script will NOT work for entries that have a comma between double quotes.
BEGIN { BEGIN {
FS="," FS=","
ind=1 ind=1
} }
## Some fields are surrounded by unwanted double quotes. ## Some fields are surrounded by unwanted double quotes.
function remove_quotes(s) function remove_quotes(s) {
{ gsub(/^"+|"+$/, "", s)
gsub(/^"+|"+$/, "", s) return s
return s
} }
function capitalize(s) function capitalize(s) {
{ result = ""
result = "" while(match(s,/[ -]/))
while(match(s,/[ -]/)) {
{ word = substr(s,1,RSTART-1)
word = substr(s,1,RSTART-1) result = result toupper(substr(word,1,1)) tolower(substr(word,2))
result = result toupper(substr(word,1,1)) tolower(substr(word,2)) if(index(s,"-"))
if(index(s,"-")) result = result "-"
result = result "-" else
else result = result " "
result = result " " s = substr(s,RSTART+1)
s = substr(s,RSTART+1) }
} result = result toupper(substr(s,1,1)) tolower(substr(s,2))
result = result toupper(substr(s,1,1)) tolower(substr(s,2)) return result
return result
} }
## Let's skip the first line which is supposed to contain the CSV header. ## Let's skip the first line which is supposed to contain the CSV header.
FNR==1 { FNR==1 {
next next
} }
{ {
print "[" ind "]" print "[" ind "]"
print "name=" capitalize(remove_quotes($2)) " " capitalize(remove_quotes($4)) print "name=" capitalize(remove_quotes($2)) " " capitalize(remove_quotes($4))
printf "email=" tolower(remove_quotes($29)) printf "email=" tolower(remove_quotes($29))
if ($31 != "") if ($31 != "")
printf "," remove_quotes($31) printf "," remove_quotes($31)
if ($33 != "") if ($33 != "")
printf "," remove_quotes($33) printf "," remove_quotes($33)
printf "\n" printf "\n"
print "birthday=" remove_quotes($15) print "birthday=" remove_quotes($15)
print "mobile=" remove_quotes($35) print "mobile=" remove_quotes($35)
print "phone=" remove_quotes($37) print "phone=" remove_quotes($37)
print "address=" remove_quotes($39) print "address=" remove_quotes($39)
print "" print ""
ind++ ind++
} }

View File

@ -1,17 +1,15 @@
#!/bin/sh #!/bin/sh
if [ $# -ne 3 ] || [ "$1" = "-h" ]; then if [ $# -ne 3 ] || [ "$1" = "-h" ]; then
cat <<EOF cat <<EOF
Usage: ${0##*/} VALUE IN-CURRENCY OUT-CURRENCY Usage: ${0##*/} VALUE IN-CURRENCY OUT-CURRENCY
Convert VALUE from IN-CURRENCY to OUT-CURRENCY. Convert VALUE from IN-CURRENCY to OUT-CURRENCY.
CURRENCY is a 3-letters code like EUR, SEK, USD, etc. CURRENCY is a 3-letters code like EUR, SEK, USD, etc.
EOF EOF
exit exit
fi fi
curl -sA "Mozilla/5.0" "http://www.google.com/finance?q=$2$3" | \ curl -sA "Mozilla/5.0" "http://www.google.com/finance?q=$2$3" | \
awk -v value=$1 -F '<|>' '/^1 / {print value * substr($3, 1, index($3," "))}' awk -v value=$1 -F '<|>' '/^1 / {print value * substr($3, 1, index($3," "))}'

View File

@ -1,8 +1,7 @@
#!/bin/sh #!/bin/sh
_printhelp () _usage () {
{ cat<<EOF
cat<<EOF
Usage: ${1##*/} [OPTIONS] [FILES] Usage: ${1##*/} [OPTIONS] [FILES]
Cut out last 10 lines from stdin. If FILES are provided, cut files instead of Cut out last 10 lines from stdin. If FILES are provided, cut files instead of
@ -26,27 +25,27 @@ OPT_CUTFIRST=false
OPT_LINES=10 OPT_LINES=10
OPT_INPLACE="" OPT_INPLACE=""
while getopts ":fhin:" opt; do while getopts ":fhin:" opt; do
case $opt in case $opt in
f) f)
OPT_CUTFIRST=true ;; OPT_CUTFIRST=true ;;
h) h)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
i) i)
OPT_INPLACE="-i" ;; OPT_INPLACE="-i" ;;
n) n)
OPT_LINES=$OPTARG ;; OPT_LINES=$OPTARG ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if $OPT_CUTFIRST; then if $OPT_CUTFIRST; then
sed $OPT_INPLACE -n "1,${OPT_LINES}!p" "$@" sed $OPT_INPLACE -n "1,${OPT_LINES}!p" "$@"
else else
echo CUTLAST echo CUTLAST
sed $OPT_INPLACE -n ":begin ; 1,${OPT_LINES}!{P;N;D}; N; b begin" "$@" sed $OPT_INPLACE -n ":begin ; 1,${OPT_LINES}!{P;N;D}; N; b begin" "$@"
fi fi

View File

@ -1,18 +1,18 @@
#!/bin/sh #!/bin/sh
xev | awk '/KeyPress|KeyRelease/ { xev | awk '/KeyPress|KeyRelease/ {
if ($1 == "KeyPress") if ($1 == "KeyPress")
event="pressed"; event="pressed";
else else
event="released"; event="released";
getline; getline; getline; getline;
state = substr($2,1,length($2)-2); state = substr($2,1,length($2)-2);
keycode = $4; keycode = $4;
keysym = substr($7, 1, length($7)-2); keysym = substr($7, 1, length($7)-2);
getline; getline;
string=$6; string=$6;
printf "%-10s: code=%-3s state=%s event=%-8s string=%s\n", keysym, keycode, state, event, string printf "%-10s: code=%-3s state=%s event=%-8s string=%s\n", keysym, keycode, state, event, string
}' }'

View File

@ -1,8 +1,7 @@
#!/bin/sh #!/bin/sh
_printhelp () _usage () {
{ cat<<EOF
cat<<EOF
Usage: ${1##*/} [OPTIONS] FOLDERS Usage: ${1##*/} [OPTIONS] FOLDERS
Output index of folder hierarchies to stdout. This is used as a small "backup" Output index of folder hierarchies to stdout. This is used as a small "backup"
@ -20,54 +19,53 @@ EOF
opt_noclobber=true opt_noclobber=true
opt_file=false opt_file=false
while getopts ":fhw" opt; do while getopts ":fhw" opt; do
case $opt in case $opt in
f) f)
opt_noclobber=false ;; opt_noclobber=false ;;
h) h)
_printhelp "$0" _usage "$0"
exit 0 ;; exit 0 ;;
w) w)
opt_file=true ;; opt_file=true ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_printhelp "$0" _usage "$0"
exit 1 exit 1
fi fi
## 'realpath' is required in case argument is ending with '.' or '..'. ## 'realpath' is required in case argument is ending with '.' or '..'.
if ! command -v realpath >/dev/null 2>&1; then if ! command -v realpath >/dev/null 2>&1; then
echo "'realpath' not found in PATH. Exiting." >&2 echo "'realpath' not found in PATH. Exiting." >&2
exit 1 exit 1
fi fi
for i ; do for i ; do
## Find over '.*' and '*', is bad practice since if will fail on ## Find over '.*' and '*', is bad practice since if will fail on
## non-existing files or for files beginning with a dash. The 'printf' ## non-existing files or for files beginning with a dash. The 'printf'
## command in find is for GNU find only. ## command in find is for GNU find only.
## The two following lines do the same for the same time cost. The former is shorter. ## 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" # 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 ## 'LC_ALL=C sort' is required to make sure to output is consistent across
## different systems. ## different systems.
(cd -- "$i" && find . -type f) | sed 's/^.\///' | LC_ALL=C sort | \ (cd -- "$i" && find . -type f) | sed 's/^.\///' | LC_ALL=C sort | \
if $opt_file; then if $opt_file; then
i="$(realpath -- "$i")" i="$(realpath -- "$i")"
base="${i##*/}" base="${i##*/}"
[ ! -d "$i" ] && continue [ ! -d "$i" ] && continue
output="$base.index" output="$base.index"
[ -e "$OUTPUT" ] && $opt_noclobber && output="$base-$(date +%F-%T).index" [ -e "$OUTPUT" ] && $opt_noclobber && output="$base-$(date +%F-%T).index"
echo "$output" echo "$output"
cat > "$output" cat > "$output"
else else
cat cat
fi fi
done done

View File

@ -1,29 +1,29 @@
#!/bin/sh #!/bin/sh
if [ "$1" = "-h" ]; then if [ "$1" = "-h" ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} PATH Usage: ${0##*/} PATH
Display PATH one entry per line. If PATH is not provided, use \$PATH by default. Display PATH one entry per line. If PATH is not provided, use \$PATH by default.
EOF EOF
exit exit
fi fi
if [ $# -ne 0 ]; then if [ $# -ne 0 ]; then
ARG="$1" ARG="$1"
else else
ARG="$PATH" ARG="$PATH"
fi fi
case "$ARG" in case "$ARG" in
*:*) SEP=':';; *:*) SEP=':';;
*\;*) SEP=';';; *\;*) SEP=';';;
*/*) SEP='/';; */*) SEP='/';;
*,*) SEP=',';; *,*) SEP=',';;
*\|*) SEP='|';; *\|*) SEP='|';;
*) SEP=':';; *) SEP=':';;
esac esac
echo "$ARG" | awk -v RS=$SEP '1' echo "$ARG" | awk -v RS=$SEP '1'

View File

@ -1,14 +1,14 @@
#!/bin/sh #!/bin/sh
check() check() {
{ for i ; do
for i ; do if ! command -v $i >/dev/null 2>&1; then
if ! command -v $i >/dev/null 2>&1; then echo "'$i' not found in PATH. Exiting." >&2
echo "'$i' not found in PATH. Exiting." >&2 exit 1
exit 1 fi
fi done
done
} }
check emacs realpath check emacs realpath
[ -f "$1" ] && node="$(realpath "$1")" || node="$1" [ -f "$1" ] && node="$(realpath "$1")" || node="$1"

View File

@ -1,8 +1,7 @@
#!/bin/sh #!/bin/sh
_printhelp () _usage () {
{ cat<<EOF
cat<<EOF
Usage: ${1##*/} [OPTIONS] SCRIPT [ARGS...] Usage: ${1##*/} [OPTIONS] SCRIPT [ARGS...]
Run Emacs Lisp SCRIPT. Run Emacs Lisp SCRIPT.
@ -17,32 +16,32 @@ EOF
OPT_BYTE=false OPT_BYTE=false
OPT_CLEAN=false OPT_CLEAN=false
while getopts :bc OPT; do while getopts :bc OPT; do
case $OPT in case $OPT in
b) b)
OPT_BYTE=true ;; OPT_BYTE=true ;;
c) c)
OPT_CLEAN=true ;; OPT_CLEAN=true ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_printhelp "$0" _usage "$0"
exit 1 exit 1
fi fi
if ! command -v emacs >/dev/null 2>&1; then if ! command -v emacs >/dev/null 2>&1; then
echo 'emacs not found in PATH. Exiting.' >&2 echo 'emacs not found in PATH. Exiting.' >&2
exit 1 exit 1
fi fi
script="$1" script="$1"
if $OPT_BYTE && [ "${1##*.}" = "el" ]; then if $OPT_BYTE && [ "${1##*.}" = "el" ]; then
script="${1%.*}.elc" script="${1%.*}.elc"
emacs -Q --batch -f batch-byte-compile "$1" 2>/dev/null emacs -Q --batch -f batch-byte-compile "$1" 2>/dev/null
fi fi
shift shift

View File

@ -3,7 +3,7 @@
## daemon since we want to pass additional parameters to emacs. ## daemon since we want to pass additional parameters to emacs.
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
cat <<EOF cat <<EOF
Usage: ${0##*/} [FILES] Usage: ${0##*/} [FILES]
Start emacsclient in terminal or in X window if possible. If server is not Start emacsclient in terminal or in X window if possible. If server is not
@ -18,18 +18,18 @@ All emacsclient(1) options are supported.
$(emacsclient --help) $(emacsclient --help)
EOF EOF
exit exit
fi fi
if [ "${0##*/}" = "emc" ] || [ -z "$DISPLAY" ] || \ if [ "${0##*/}" = "emc" ] || [ -z "$DISPLAY" ] || \
[ "$(emacs --batch -Q --eval='(if (fboundp '"'"'tool-bar-mode) (message "X") (message "TTY"))' 2>&1)" = TTY ]; then [ "$(emacs --batch -Q --eval='(if (fboundp '"'"'tool-bar-mode) (message "X") (message "TTY"))' 2>&1)" = TTY ]; then
param="-t" param="-t"
else else
if [ "${0##*/}" = "emw" ]; then if [ "${0##*/}" = "emw" ]; then
param="-c" param="-c"
else else
param="-nc" param="-nc"
fi fi
fi fi
[ ! -e /tmp/emacs$(id -u)/server ] && emacs --daemon --no-site-file [ ! -e /tmp/emacs$(id -u)/server ] && emacs --daemon --no-site-file

View File

@ -1,9 +1,8 @@
#!/usr/bin/env zsh #!/usr/bin/env zsh
## zsh is needed for the password. ## zsh is needed for the password.
_printhelp () _usage () {
{ cat<<EOF
cat<<EOF
Usage: ${1##*/} [OPTIONS] FILES|FOLDERS Usage: ${1##*/} [OPTIONS] FILES|FOLDERS
Wrapper around various archive extraction tools. The archives are recognized Wrapper around various archive extraction tools. The archives are recognized
@ -31,56 +30,55 @@ OPT_DELAFTER=false
PASS='' PASS=''
while getopts ":hfp" opt; do while getopts ":hfp" opt; do
case $opt in case $opt in
h) h)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
f) f)
OPT_DELAFTER=true ;; OPT_DELAFTER=true ;;
p) p)
echo -n "Password: " echo -n "Password: "
read -s PASS read -s PASS
PASS="-p$PASS" ;; PASS="-p$PASS" ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_printhelp "$0" _usage "$0"
exit 1 exit 1
fi fi
command -v atool >/dev/null 2>&1 && echo "You should use atool instead." && echo command -v atool >/dev/null 2>&1 && echo "You should use atool instead." && echo
_extract() _extract () {
{ echo "[$1]"
echo "[$1]" case "$1" in
case "$1" in */*) FOLDER="${1%/*}";;
*/*) FOLDER="${1%/*}";; *) FOLDER="." ;;
*) FOLDER="." ;; esac
esac
case "$1" in case "$1" in
*.tar*|*.tbz2|*.tbz|*.tgz|*.txz) tar xf "$1" -C "$FOLDER" ;; *.tar*|*.tbz2|*.tbz|*.tgz|*.txz) tar xf "$1" -C "$FOLDER" ;;
*.7z) 7z x "$PASS" -o"$FOLDER" "$1";; *.7z) 7z x "$PASS" -o"$FOLDER" "$1";;
*.bz2) bunzip2 "$1" ;; *.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;; *.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;; *.gz) gunzip "$1" ;;
*.zip) unzip "$1" ;; *.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;; *.Z) uncompress "$1" ;;
*.xz) unxz "$1" ;; *.xz) unxz "$1" ;;
*.exe) cabextract "$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 echo "[$1]: unrecognized archive format." ;;
*7-zip*) 7z x "$PASS" -o"$FOLDER" "$1" ;; esac
*gzip*|*bzip2*|*XZ*) tar xf "$1" -C "$FOLDER" ;;
*)
echo "[$1]: unrecognized archive format." ;;
esac
esac esac
$OPT_DELAFTER && rm -v "$1" $OPT_DELAFTER && rm -v "$1"
@ -88,13 +86,13 @@ _extract()
for i ; do for i ; do
if [ -d "$i" ]; then if [ -d "$i" ]; then
while IFS= read -r FILE; do while IFS= read -r FILE; do
_extract "$FILE" _extract "$FILE"
done <<EOF done <<EOF
$(find "$i" -type f) $(find "$i" -type f)
EOF EOF
else else
_extract "$i" _extract "$i"
fi fi
done done

View File

@ -1,8 +1,7 @@
#!/bin/sh #!/bin/sh
_printhelp() _usage() {
{ cat<<EOF
cat<<EOF
Usage: ${0##*/} FOLDERS Usage: ${0##*/} FOLDERS
Chack all git repos found in FOLDERS for non-commited file. Chack all git repos found in FOLDERS for non-commited file.
@ -10,16 +9,16 @@ EOF
} }
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
_printhelp _usage
exit exit
fi fi
for i; do for i; do
while IFS= read -r FOLDER; do while IFS= read -r FOLDER; do
if [ -z "$(cd -- "${FOLDER%/*}" && LC_ALL=C git status -uno | grep "nothing to commit")" ]; then if [ -z "$(cd -- "${FOLDER%/*}" && LC_ALL=C git status -uno | grep "nothing to commit")" ]; then
echo "${FOLDER%/*}" echo "${FOLDER%/*}"
fi fi
done <<EOF done <<EOF
$(find "$i" -type d -name ".git") $(find "$i" -type d -name ".git")
EOF EOF
done done

View File

@ -1,12 +1,12 @@
#!/bin/sh #!/bin/sh
if [ $# -ne 1 ]; then if [ $# -ne 1 ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} FOLDER Usage: ${0##*/} FOLDER
Compare current git repo with FOLDER. Compare current git repo with FOLDER.
EOF EOF
exit exit
fi fi
REPO="$(mktemp)" REPO="$(mktemp)"

View File

@ -1,8 +1,7 @@
#!/bin/sh #!/bin/sh
_printhelp () _usage () {
{ cat<<EOF
cat<<EOF
Usage: ${1##*/} [OPTIONS] REPOS Usage: ${1##*/} [OPTIONS] REPOS
Clone multiple git repos from \$DOMAIN:\$USER. Clone multiple git repos from \$DOMAIN:\$USER.
@ -19,32 +18,32 @@ EOF
DOMAIN=bitbucket.org DOMAIN=bitbucket.org
USER=ambrevar USER=ambrevar
while getopts ":hd:u:" opt; do while getopts ":hd:u:" opt; do
case $opt in case $opt in
h) h)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
d) d)
DOMAIN=$OPTARG ;; DOMAIN=$OPTARG ;;
u) u)
USER=$OPTARG ;; USER=$OPTARG ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_printhelp "$0" _usage "$0"
exit 1 exit 1
fi fi
if ! command -v git >/dev/null 2>&1; then if ! command -v git >/dev/null 2>&1; then
echo >&2 "'git' not found in PATH. Exiting." echo >&2 "'git' not found in PATH. Exiting."
exit 1 exit 1
fi fi
for i; do for i; do
git clone git@$DOMAIN:/$USER/$i git clone git@$DOMAIN:/$USER/$i
done done

View File

@ -1,30 +1,25 @@
#!/bin/sh #!/bin/sh
_printhelp() if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
{ cat<<EOF
cat<<EOF
Usage: ${0##*/} FOLDERS Usage: ${0##*/} FOLDERS
Sync all git repos found in FOLDERS. Sync all git repos found in FOLDERS.
EOF EOF
} exit
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
_printhelp
exit
fi fi
for i; do for i; do
while IFS= read -r FOLDER; do while IFS= read -r FOLDER; do
ROOT="${FOLDER%/*}" ROOT="${FOLDER%/*}"
STATUS="$(cd -- "$ROOT" && git status -uno | grep "Your branch is ahead of")" STATUS="$(cd -- "$ROOT" && git status -uno | grep "Your branch is ahead of")"
if [ -n "$STATUS" ]; then if [ -n "$STATUS" ]; then
echo "$ROOT" echo "$ROOT"
echo "$STATUS" echo "$STATUS"
(cd -- "$ROOT" && git push) (cd -- "$ROOT" && git push)
echo echo
fi fi
done <<EOF done <<EOF
$(find "$i" -type d -name ".git") $(find "$i" -type d -name ".git")
EOF EOF
done done

View File

@ -1,13 +1,13 @@
#!/bin/sh #!/bin/sh
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
cat <<EOF cat <<EOF
Usage: ${0##*/} [FILES] Usage: ${0##*/} [FILES]
Grep non-ascii characters. If no files are provided, use stdin. Grep non-ascii characters. If no files are provided, use stdin.
EOF EOF
exit exit
fi fi
perl -ne 'chomp; print $_, "\n" if /[[:^ascii:]]/' "$@" perl -ne 'chomp; print $_, "\n" if /[[:^ascii:]]/' "$@"

View File

@ -6,13 +6,13 @@
BEGIN { FS=":" } BEGIN { FS=":" }
/^ "title" :/ { /^ "title" :/ {
title=$2 title=$2
gsub(/ "|",/,"",title) gsub(/ "|",/,"",title)
} }
/^ "href" :/ { /^ "href" :/ {
link=$2 ":" $3 link=$2 ":" $3
gsub(/ "|",/,"",link) gsub(/ "|",/,"",link)
} }
/\}, \{/ { print link " " title } /\}, \{/ { print link " " title }

View File

@ -14,8 +14,8 @@
## radeon.audio=1 ## radeon.audio=1
if [ $(id -u) -ne 0 ]; then if [ $(id -u) -ne 0 ]; then
echo "You must be root to run this script." echo "You must be root to run this script."
exit exit
fi fi
ALSACONF="/etc/asound.conf" ALSACONF="/etc/asound.conf"
@ -24,7 +24,7 @@ HDMI_STATUS="$(cat /sys/class/drm/card0-HDMI-A-1/status)"
BUF="$(aplay -l | grep HDMI)" BUF="$(aplay -l | grep HDMI)"
_getprop() { _getprop() {
echo "$BUF" | awk -v prop="$1" '{for(i=1; i<NF; i++) if ($i == prop) { print substr($(i+1), 1,1); exit}}' echo "$BUF" | awk -v prop="$1" '{for(i=1; i<NF; i++) if ($i == prop) { print substr($(i+1), 1,1); exit}}'
} }
CARD="$(_getprop card)" CARD="$(_getprop card)"
@ -34,22 +34,21 @@ udevadm settle --quiet --timeout=2
## Video ## Video
for i in $(xrandr | awk '/^[[:alnum:]-]+ connected/ {print $1}'); do for i in $(xrandr | awk '/^[[:alnum:]-]+ connected/ {print $1}'); do
xrandr --output "$i" --auto xrandr --output "$i" --auto
done done
## Sound ## Sound
if [ "$HDMI_STATUS" = "connected" ]; then if [ "$HDMI_STATUS" = "connected" ]; then
cat<<EOF > "$ALSACONF" cat<<EOF > "$ALSACONF"
pcm.!default { pcm.!default {
type hw type hw
card $CARD card $CARD
device $DEVICE device $DEVICE
} }
EOF EOF
chmod 644 "${ALSACONF}" chmod 644 "${ALSACONF}"
echo "HDMI sound enabled" echo "HDMI sound enabled"
else else
rm -f "$ALSACONF" rm -f "$ALSACONF"
echo "HDMI sound disabled" echo "HDMI sound disabled"
fi fi

View File

@ -1,45 +1,45 @@
#!/bin/sh #!/bin/sh
set -- "$HOME/.cache/dwb" \ set -- "$HOME/.cache/dwb" \
"$HOME/.cache/emacs" \ "$HOME/.cache/emacs" \
"$HOME/.cache/mutt" \ "$HOME/.cache/mutt" \
"$HOME/.cache/rtorrent" \ "$HOME/.cache/rtorrent" \
"$HOME/.cache/zsh" \ "$HOME/.cache/zsh" \
"$HOME/.cmus/autosave" \ "$HOME/.cmus/autosave" \
"$HOME/.cmus/cache" \ "$HOME/.cmus/cache" \
"$HOME/.cmus/lib.pl" \ "$HOME/.cmus/lib.pl" \
"$HOME/.cmus/playlist.pl" \ "$HOME/.cmus/playlist.pl" \
"$HOME/.cmus/queue.pl" \ "$HOME/.cmus/queue.pl" \
"$HOME/.cmus/resume" \ "$HOME/.cmus/resume" \
"$HOME/.cmus/search-history" \ "$HOME/.cmus/search-history" \
"$HOME/.config/dwb/default/commands.history" \ "$HOME/.config/dwb/default/commands.history" \
"$HOME/.config/dwb/default/cookies" \ "$HOME/.config/dwb/default/cookies" \
"$HOME/.config/dwb/default/cookies_session.allow" \ "$HOME/.config/dwb/default/cookies_session.allow" \
"$HOME/.config/dwb/default/dwb-uni.fifo" \ "$HOME/.config/dwb/default/dwb-uni.fifo" \
"$HOME/.config/dwb/default/history" \ "$HOME/.config/dwb/default/history" \
"$HOME/.config/dwb/default/hsts" \ "$HOME/.config/dwb/default/hsts" \
"$HOME/.config/dwb/default/navigate.history" \ "$HOME/.config/dwb/default/navigate.history" \
"$HOME/.config/dwb/default/plugindb" \ "$HOME/.config/dwb/default/plugindb" \
"$HOME/.config/dwb/default/plugins.allow" \ "$HOME/.config/dwb/default/plugins.allow" \
"$HOME/.config/dwb/default/scripts.allow" \ "$HOME/.config/dwb/default/scripts.allow" \
"$HOME/.config/dwb/default/search.history" \ "$HOME/.config/dwb/default/search.history" \
"$HOME/.config/dwb/default/session" \ "$HOME/.config/dwb/default/session" \
"$HOME/.config/gtk-2.0" \ "$HOME/.config/gtk-2.0" \
"$HOME/.config/gtk-3.0" \ "$HOME/.config/gtk-3.0" \
"$HOME/.config/ranger/bookmarks" \ "$HOME/.config/ranger/bookmarks" \
"$HOME/.config/ranger/history" \ "$HOME/.config/ranger/history" \
"$HOME/.config/ranger/tagged" \ "$HOME/.config/ranger/tagged" \
"$HOME/.fehbg" \ "$HOME/.fehbg" \
"$HOME/.gtk-bookmarks" \ "$HOME/.gtk-bookmarks" \
"$HOME/.lesshst" \ "$HOME/.lesshst" \
"$HOME/.local/share/newsbeuter" \ "$HOME/.local/share/newsbeuter" \
"$HOME/.local/share/webkit" \ "$HOME/.local/share/webkit" \
"$HOME/.mpv/watch_later" \ "$HOME/.mpv/watch_later" \
"$HOME/.mtap.fuseiso" \ "$HOME/.mtap.fuseiso" \
"$HOME/.pulse-cookie" \ "$HOME/.pulse-cookie" \
"$HOME/.viminfo" \ "$HOME/.viminfo" \
"$HOME/.w3m" \ "$HOME/.w3m" \
"$HOME/.zcompdump" "$HOME/.zcompdump"
## POSIX can store only one list at a time. Here we rely on the fact there is no ## POSIX can store only one list at a time. Here we rely on the fact there is no
## space in the file names. ## space in the file names.
@ -58,18 +58,18 @@ echo "==> Clean home? [y/N]"
read CHOICE read CHOICE
CHOICE="$(echo $CHOICE | tr [:lower:] [:upper:])" CHOICE="$(echo $CHOICE | tr [:lower:] [:upper:])"
if [ "$CHOICE" != "Y" ]; then if [ "$CHOICE" != "Y" ]; then
echo "Nothing done." echo "Nothing done."
exit exit
fi fi
## Clean trash if possible. ## Clean trash if possible.
echo echo
echo "==> Emptying trash." echo "==> Emptying trash."
if ! command -v trash-empty >/dev/null 2>&1; then if ! command -v trash-empty >/dev/null 2>&1; then
echo ":: 'trash-empty' not installed, you have to clean other drives manually." echo ":: 'trash-empty' not installed, you have to clean other drives manually."
rm -rvf "$HOME/.local/share/Trash" rm -rvf "$HOME/.local/share/Trash"
else else
trash-empty trash-empty
fi fi
## Remove data. ## Remove data.
@ -81,10 +81,10 @@ rm -rvf "$@"
echo echo
echo "==> Remove critical data." echo "==> Remove critical data."
if [ "$(echo "$HOME" | grep -c ' ')" -ne 0 ]; then if [ "$(echo "$HOME" | grep -c ' ')" -ne 0 ]; then
echo 'WARNING: $HOME contains spaces, skipping.' echo 'WARNING: $HOME contains spaces, skipping.'
else else
shred -zuv $RMLIST_CRITICAL shred -zuv $RMLIST_CRITICAL
# wipe -rdzp2 $RMLIST_CRITICAL # wipe -rdzp2 $RMLIST_CRITICAL
fi fi
echo echo

View File

@ -1,8 +1,6 @@
#!/bin/sh #!/bin/sh
################################################################################
## Home session initialization. ## Home session initialization.
## 2013-06-14
################################################################################
SOURCEDIR="$HOME/personal/dataperso" SOURCEDIR="$HOME/personal/dataperso"
[ -z "$XDG_CONFIG_HOME" ] && XDG_CONFIG_HOME="$HOME/.config" [ -z "$XDG_CONFIG_HOME" ] && XDG_CONFIG_HOME="$HOME/.config"
[ -z "$XDG_DATA_HOME" ] && XDG_DATA_HOME="$HOME/.local/share" [ -z "$XDG_DATA_HOME" ] && XDG_DATA_HOME="$HOME/.local/share"
@ -14,97 +12,97 @@ mkdir -p "$HOME/temp"
echo echo
if [ -d "$SOURCEDIR/contacts" ]; then if [ -d "$SOURCEDIR/contacts" ]; then
echo "==> Abook" echo "==> Abook"
ln -snf "$SOURCEDIR/contacts" "$HOME/.abook" ln -snf "$SOURCEDIR/contacts" "$HOME/.abook"
echo echo
fi fi
if command -v mutt >/dev/null 2>&1; then if command -v mutt >/dev/null 2>&1; then
echo "==> Mutt" echo "==> Mutt"
[ -d "$SOURCEDIR" ] && ln -snf "$SOURCEDIR/mails" "$HOME/.mutt.d" [ -d "$SOURCEDIR" ] && ln -snf "$SOURCEDIR/mails" "$HOME/.mutt.d"
mkdir -p "$HOME/.cache/mutt/hcache" mkdir -p "$HOME/.cache/mutt/hcache"
echo echo
fi fi
if [ -d "$SOURCEDIR/todo" ]; then if [ -d "$SOURCEDIR/todo" ]; then
echo "==> To-Do" echo "==> To-Do"
ln -snf "$SOURCEDIR/todo/todo.org" "$HOME/todo.org" ln -snf "$SOURCEDIR/todo/todo.org" "$HOME/todo.org"
echo echo
fi fi
if command -v rtorrent >/dev/null 2>&1; then if command -v rtorrent >/dev/null 2>&1; then
echo "==> rtorrent" echo "==> rtorrent"
## We need the evaluation of the result, otherwise the variables will not ## We need the evaluation of the result, otherwise the variables will not
## get expanded, should it be '~' or "$HOME". ## get expanded, should it be '~' or "$HOME".
mkdir -p "$(eval echo $(awk -F'=' '/^session *= */{gsub(/^ +| +$/,"",$2); res=$2} END {printf res}' ~/.rtorrent.rc))" mkdir -p "$(eval echo $(awk -F'=' '/^session *= */{gsub(/^ +| +$/,"",$2); res=$2} END {printf res}' ~/.rtorrent.rc))"
echo echo
fi fi
## Luakit -- Install the adblock modules ## Luakit -- Install the adblock modules
if command -v luakit >/dev/null 2>&1; then if command -v luakit >/dev/null 2>&1; then
echo "==> Luakit" echo "==> Luakit"
git clone https://github.com/Plaque-fcc/luakit-adblock/ "$HOME/luakit-adblock" git clone https://github.com/Plaque-fcc/luakit-adblock/ "$HOME/luakit-adblock"
cp -fv ~/luakit-adblock/*.lua "$XDG_CONFIG_HOME/luakit" cp -fv ~/luakit-adblock/*.lua "$XDG_CONFIG_HOME/luakit"
rm -rvf "$HOME/luakit-adblock" rm -rvf "$HOME/luakit-adblock"
## Update the adblock lists ## Update the adblock lists
mkdir -p "$XDG_DATA_HOME/luakit/adblock" mkdir -p "$XDG_DATA_HOME/luakit/adblock"
wget https://easylist-downloads.adblockplus.org/easylist.txt \ wget https://easylist-downloads.adblockplus.org/easylist.txt \
https://easylist-downloads.adblockplus.org/easyprivacy.txt \ https://easylist-downloads.adblockplus.org/easyprivacy.txt \
https://easylist-downloads.adblockplus.org/easylistgermany.txt \ https://easylist-downloads.adblockplus.org/easylistgermany.txt \
http://lian.info.tm/liste_fr.txt \ http://lian.info.tm/liste_fr.txt \
-P "$XDG_DATA_HOME/luakit/adblock" -P "$XDG_DATA_HOME/luakit/adblock"
echo echo
fi fi
## dwb -- Install extensions. ## dwb -- Install extensions.
if command -v dwbem >/dev/null 2>&1; then 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 "adblock_subscriptions") -eq 0 ] && dwbem -Ni adblock_subscriptions
[ $(dwbem -l | grep -c "navtools") -eq 0 ] && dwbem -Ni navtools [ $(dwbem -l | grep -c "navtools") -eq 0 ] && dwbem -Ni navtools
[ $(dwbem -l | grep -c "contenthandler") -eq 0 ] && dwbem -Ni contenthandler [ $(dwbem -l | grep -c "contenthandler") -eq 0 ] && dwbem -Ni contenthandler
# dwbem -Ni youtube_html5 # dwbem -Ni youtube_html5
(cd ~/.config/dwb/userscripts/ && git checkout extension_loader.js) (cd ~/.config/dwb/userscripts/ && git checkout extension_loader.js)
echo echo
fi fi
## Bookmarks ## Bookmarks
if [ -d "$SOURCEDIR" ]; then if [ -d "$SOURCEDIR" ]; then
echo "==> Bookmarks" echo "==> Bookmarks"
if [ -z "$BROWSER" ]; then if [ -z "$BROWSER" ]; then
echo "Variable BROWSER is not set." echo "Variable BROWSER is not set."
else else
BROWSER_DATA_DIR="$XDG_DATA_HOME/$BROWSER/" BROWSER_DATA_DIR="$XDG_DATA_HOME/$BROWSER/"
[ "$BROWSER" = "dwb" ] && BROWSER_DATA_DIR="$XDG_CONFIG_HOME/$BROWSER/default/" [ "$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/bookmarks" "$BROWSER_DATA_DIR"
[ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/bookmarks/quickmarks" "$BROWSER_DATA_DIR" [ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/bookmarks/quickmarks" "$BROWSER_DATA_DIR"
[ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/bookmarks/cookies.allow" "$BROWSER_DATA_DIR" [ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/bookmarks/cookies.allow" "$BROWSER_DATA_DIR"
fi fi
echo echo
fi fi
## News ## News
if command -v newsbeuter >/dev/null 2>&1; then if command -v newsbeuter >/dev/null 2>&1; then
echo "==> Newsbeuter" echo "==> Newsbeuter"
mkdir -p "$XDG_DATA_HOME/newsbeuter" mkdir -p "$XDG_DATA_HOME/newsbeuter"
[ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/news/urls" "$XDG_CONFIG_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/" [ -d "$SOURCEDIR" ] && ln -sf "$SOURCEDIR/news/news_starred" "$XDG_CONFIG_HOME/newsbeuter/"
echo echo
fi fi
## Launchers ## Launchers
if [ -d "$SOURCEDIR" ]; then if [ -d "$SOURCEDIR" ]; then
echo "==> Launchers" echo "==> Launchers"
ln -snf "$SOURCEDIR/launchers" "$HOME/.launchers" ln -snf "$SOURCEDIR/launchers" "$HOME/.launchers"
echo echo
fi fi
## Temp scripts ## Temp scripts
if [ -d "$SOURCEDIR" ]; then if [ -d "$SOURCEDIR" ]; then
echo "==> Hackpool" echo "==> Hackpool"
ln -snf "$SOURCEDIR/hackpool" "$HOME/.hackpool" ln -snf "$SOURCEDIR/hackpool" "$HOME/.hackpool"
echo echo
fi fi

View File

@ -30,7 +30,7 @@
## we go for the first algorithm. ## we go for the first algorithm.
function _printhelp() { function _printhelp() {
print "Filesystem hierarchy synchronizer\n\ print "Filesystem hierarchy synchronizer\n\
\n\ \n\
Usage: hsync SOURCE TARGET\n\ Usage: hsync SOURCE TARGET\n\
\n\ \n\
@ -48,78 +48,78 @@ evaluation:\n\
} }
function _info(s) { function _info(s) {
print "\n==> " s | "cat >&2" print "\n==> " s | "cat >&2"
close("cat >&2") close("cat >&2")
} }
function _msg(s) { function _msg(s) {
print ":: " s | "cat >&2" print ":: " s | "cat >&2"
close("cat >&2") close("cat >&2")
} }
BEGIN { BEGIN {
## Both parameters must be existing folders. ## Both parameters must be existing folders.
if (ARGC != 3 || if (ARGC != 3 ||
("test -d " ARGV[1] " && test -d " ARGV[2] " || echo KO" | getline) > 0 ) ("test -d " ARGV[1] " && test -d " ARGV[2] " || echo KO" | getline) > 0 )
{ {
_printhelp() _printhelp()
exit exit
} }
_info("Scanning " ARGV[1] "...") _info("Scanning " ARGV[1] "...")
while ( ("cd -- " ARGV[1] " && find . -type f -exec md5sum {} +" | getline ) > 0) while ( ("cd -- " ARGV[1] " && find . -type f -exec md5sum {} +" | getline ) > 0)
{ {
sum = $1 sum = $1
## We need to remove sum from line since filename may contain ## We need to remove sum from line since filename may contain
## spaces. substr is faster than sub. ## spaces. substr is faster than sub.
name = substr($0, 35) name = substr($0, 35)
if (sum in source || sum in source_dup) if (sum in source || sum in source_dup)
{ {
_msg("Skipping duplicate: " name) _msg("Skipping duplicate: " name)
## Note: it is not necessary to delete source[sum] since it will not ## Note: it is not necessary to delete source[sum] since it will not
## be used anyway if source_dup[sum] is set to 1. ## be used anyway if source_dup[sum] is set to 1.
source_dup[sum] = 1 source_dup[sum] = 1
continue continue
} }
source[sum] = name source[sum] = name
} }
_info("Scanning " ARGV[2] "...") _info("Scanning " ARGV[2] "...")
while ( ("cd -- " ARGV[2] " && find . -type f -exec md5sum {} +" | getline ) > 0) while ( ("cd -- " ARGV[2] " && find . -type f -exec md5sum {} +" | getline ) > 0)
{ {
sum = $1 sum = $1
name = substr($0, 35) name = substr($0, 35)
## Skip if duplicate, not existant in source, or identical. ## Skip if duplicate, not existant in source, or identical.
if (sum in source_dup || ! (sum in source) || source[sum] == name) if (sum in source_dup || ! (sum in source) || source[sum] == name)
continue continue
if (sum in target || sum in target_dup) if (sum in target || sum in target_dup)
{ {
_msg("Skipping duplicate: " name) _msg("Skipping duplicate: " name)
delete target[sum] delete target[sum]
target_dup[sum] = 1 target_dup[sum] = 1
continue continue
} }
target[sum] = name target[sum] = name
} }
_info("Hierarchy syncing preview of " ARGV[2] " based on " ARGV[1]) _info("Hierarchy syncing preview of " ARGV[2] " based on " ARGV[1])
for (i in target) for (i in target)
{ {
dirname = source[i] dirname = source[i]
sub(/[^/]+$/, "", dirname) sub(/[^/]+$/, "", dirname)
## Target -> Source ## Target -> Source
cmd = "'" ARGV[2] "/" target[i] "' '" ARGV[2] "/" source[i] "'" cmd = "'" ARGV[2] "/" target[i] "' '" ARGV[2] "/" source[i] "'"
## We only create a new folder if necessary. ## We only create a new folder if necessary.
cmd = "[ ! -d '" dirname "' ] && mkdir -p \"" ARGV[2] "/" dirname "\" ; mv -nv " cmd cmd = "[ ! -d '" dirname "' ] && mkdir -p \"" ARGV[2] "/" dirname "\" ; mv -nv " cmd
## We can sort preview by uncommenting the following pipe. This is ## We can sort preview by uncommenting the following pipe. This is
## not very useful however, and it costs some n*log(n) more ## not very useful however, and it costs some n*log(n) more
## operations. ## operations.
print cmd #|"sort" print cmd #|"sort"
} }
} }

View File

@ -6,86 +6,83 @@
FUSEROOT="$HOME/fuse" FUSEROOT="$HOME/fuse"
################################################################################ ################################################################################
_mount () _mount () {
{ [ ! -f "$1" ] && return
[ ! -f "$1" ] && return
DEVICE="$(cdemu status | awk 'NR>2 && $2==0 {print $1; found=1; exit} END {if(! found)print NR-2}')" DEVICE="$(cdemu status | awk 'NR>2 && $2==0 {print $1; found=1; exit} END {if(! found)print NR-2}')"
DEV_COUNT="$(cdemu device-mapping | awk 'END {print NR-3}')" DEV_COUNT="$(cdemu device-mapping | awk 'END {print NR-3}')"
if [ $(cdemu status | grep -c "$1") -gt 0 ]; then if [ $(cdemu status | grep -c "$1") -gt 0 ]; then
echo "Image alredy mounted." echo "Image alredy mounted."
return return
fi fi
if [ $DEVICE -gt $DEV_COUNT ]; then if [ $DEVICE -gt $DEV_COUNT ]; then
while [ $DEVICE -gt $DEV_COUNT ]; do while [ $DEVICE -gt $DEV_COUNT ]; do
cdemu add-device cdemu add-device
DEV_COUNT="$(cdemu device-mapping | awk 'END {print NR-3}')" DEV_COUNT="$(cdemu device-mapping | awk 'END {print NR-3}')"
done done
## WARNING: adding a new device takes some time. If we want to avoid errors, ## WARNING: adding a new device takes some time. If we want to avoid errors,
## we need to sleep until it is ready. ## we need to sleep until it is ready.
echo "Waiting until ready..." echo "Waiting until ready..."
while [ -z "$(cdemu device-mapping | awk -v devnum=$DEV_COUNT 'NR>2 && $1==devnum {print $2}')" ]; do while [ -z "$(cdemu device-mapping | awk -v devnum=$DEV_COUNT 'NR>2 && $1==devnum {print $2}')" ]; do
sleep 1 sleep 1
done done
fi fi
cdemu load $DEVICE "$1" cdemu load $DEVICE "$1"
if [ $? -ne 0 ] && command -v fuseiso >/dev/null 2>&1; then if [ $? -ne 0 ] && command -v fuseiso >/dev/null 2>&1; then
echo "Falling back to fuseiso." echo "Falling back to fuseiso."
# LIST="$(mount | awk -v root="$FUSEROOT" '$1 == "fuseiso" && $3 ~ root {print $3}')" # 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}') 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")" ALREADY="$(lsof -c fuseiso -F n | grep "$1")"
if [ -n "$ALREADY" ]; then if [ -n "$ALREADY" ]; then
echo "Image alredy mounted." echo "Image alredy mounted."
return return
fi fi
COUNT=0 COUNT=0
while [ -n "$(echo "$LIST" | grep "$FUSEROOT/drive-$COUNT" )" ]; do while [ -n "$(echo "$LIST" | grep "$FUSEROOT/drive-$COUNT" )" ]; do
COUNT=$(($COUNT+1)) COUNT=$(($COUNT+1))
done done
mkdir -p "$FUSEROOT/drive-$COUNT" mkdir -p "$FUSEROOT/drive-$COUNT"
fuseiso -p "$1" "$FUSEROOT/drive-$COUNT" fuseiso -p "$1" "$FUSEROOT/drive-$COUNT"
else else
NODE="$(cdemu device-mapping | awk -v devnum=$DEVICE 'NR>2 && $1==devnum {print $2}')" NODE="$(cdemu device-mapping | awk -v devnum=$DEVICE 'NR>2 && $1==devnum {print $2}')"
## TODO: This is terrible, but checking cdemu status does not work. Maybe ## TODO: This is terrible, but checking cdemu status does not work. Maybe
## a kernel limitation. ## a kernel limitation.
echo "Mounting..." echo "Mounting..."
sleep 2 sleep 2
udiskie-mount "$NODE" udiskie-mount "$NODE"
fi fi
} }
_umount () _umount () {
{ [ ! -d "$1" ] && return
[ ! -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 if [ -n "$NODE" ]; then
udiskie-umount "$1" udiskie-umount "$1"
DEVICE=$(cdemu device-mapping | awk -v node="$NODE" '$2 == node {print $1; exit}') DEVICE=$(cdemu device-mapping | awk -v node="$NODE" '$2 == node {print $1; exit}')
cdemu unload $DEVICE cdemu unload $DEVICE
elif command -v fuseiso >/dev/null; then elif command -v fuseiso >/dev/null; then
fusermount -u "$1" fusermount -u "$1"
rmdir "$1" >/dev/null 2>&1 rmdir "$1" >/dev/null 2>&1
fi fi
} }
_printhelp () _usage () {
{ cat<<EOF
cat<<EOF
Usage: ${1##*/} FILES Usage: ${1##*/} FILES
${1##*/} -u FOLDERS ${1##*/} -u FOLDERS
@ -102,43 +99,42 @@ EOF
OPT_UNMOUNT=false OPT_UNMOUNT=false
while getopts ":hu" opt; do while getopts ":hu" opt; do
case $opt in case $opt in
h) h)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
u) u)
OPT_UNMOUNT=true ;; OPT_UNMOUNT=true ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_printhelp "$0" _usage "$0"
exit 1 exit 1
fi fi
check() check () {
{ for i ; do
for i ; do if ! command -v $i >/dev/null 2>&1; then
if ! command -v $i >/dev/null 2>&1; then echo >&2 "'$i' not found in PATH. Exiting."
echo >&2 "'$i' not found in PATH. Exiting." exit 1
exit 1 fi
fi done
done
} }
## realpath is needed to check if image was already mounted or not. ## realpath is needed to check if image was already mounted or not.
check udiskie cdemu realpath check udiskie cdemu realpath
if $OPT_UNMOUNT; then if $OPT_UNMOUNT; then
for i ; do for i ; do
_umount "$(realpath "$i")" _umount "$(realpath "$i")"
done done
else else
for i ; do for i ; do
_mount "$(realpath "$i")" _mount "$(realpath "$i")"
done done
fi fi

View File

@ -1,21 +1,21 @@
#!/bin/sh #!/bin/sh
if [ "$1" = "-h" ]; then if [ "$1" = "-h" ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} Usage: ${0##*/}
Print number of open files per process. Print number of open files per process.
EOF EOF
exit exit
fi fi
LSOFOUT="$(lsof|awk '{print $1}')" LSOFOUT="$(lsof|awk '{print $1}')"
while IFS= read -r i; do while IFS= read -r i; do
echo -n "$i " echo -n "$i "
echo "$LSOFOUT" | grep -c "^$i" echo "$LSOFOUT" | grep -c "^$i"
done<<EOF done<<EOF
$(echo "$LSOFOUT" | sort -u) $(echo "$LSOFOUT" | sort -u)
EOF EOF

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} [OPTIONS] FILES Usage: ${0##*/} [OPTIONS] FILES
LaTeX quick compiler. It adds the preambule and the "\end{document}" LaTeX quick compiler. It adds the preambule and the "\end{document}"
@ -12,17 +12,17 @@ Options:
-p PACKAGES: Use the comma separated list of packages. -p PACKAGES: Use the comma separated list of packages.
EOF EOF
exit exit
fi fi
## One line is mandatory. ## One line is mandatory.
PREAMBLE='\documentclass[10pt,a4paper]{article}\usepackage[utf8]{inputenc}\usepackage[T1]{fontenc}\usepackage{amsmath,amssymb,amsfonts}\usepackage{geometry}\usepackage{lmodern}\usepackage{marvosym}\usepackage{textcomp}\DeclareUnicodeCharacter{20AC}{\EUR{}}\DeclareUnicodeCharacter{2264}{\leqslant}\DeclareUnicodeCharacter{2265}{\geqslant}' PREAMBLE='\documentclass[10pt,a4paper]{article}\usepackage[utf8]{inputenc}\usepackage[T1]{fontenc}\usepackage{amsmath,amssymb,amsfonts}\usepackage{geometry}\usepackage{lmodern}\usepackage{marvosym}\usepackage{textcomp}\DeclareUnicodeCharacter{20AC}{\EUR{}}\DeclareUnicodeCharacter{2264}{\leqslant}\DeclareUnicodeCharacter{2265}{\geqslant}'
if [ "$1" = "-p" ]; then if [ "$1" = "-p" ]; then
PACKAGES="\usepackage{$2}" PACKAGES="\usepackage{$2}"
shift 2 shift 2
fi fi
for i ; do for i ; do
pdflatex -file-line-error-style -interaction nonstopmode -jobname="${i%.tex}" "$PREAMBLE" "$PACKAGES" "\begin{document}\input" "$i" "\end{document}" pdflatex -file-line-error-style -interaction nonstopmode -jobname="${i%.tex}" "$PREAMBLE" "$PACKAGES" "\begin{document}\input" "$i" "\end{document}"
done done

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
if [ "$1" = "-h" ] || [ $# -lt 2 ]; then _usage () {
cat <<EOF cat <<EOF
${0##*/} FOLDERS DEST ${0##*/} FOLDERS DEST
Merge FOLDERS content into DEST. Existing files and folders will remain. It does Merge FOLDERS content into DEST. Existing files and folders will remain. It does
@ -15,31 +15,30 @@ Options:
-f: Overwrite destination. -f: Overwrite destination.
-r: Remove empty folders. -r: Remove empty folders.
EOF EOF
exit }
fi
OPT_OVERWRITE=false OPT_OVERWRITE=false
OPT_DELEMPTY=false OPT_DELEMPTY=false
while getopts ":fhr" opt; do while getopts ":fhr" opt; do
case $opt in case $opt in
h) h)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
f) f)
OPT_OVERWRITE=true ;; OPT_OVERWRITE=true ;;
r) r)
OPT_DELEMPTY=true ;; OPT_DELEMPTY=true ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_printhelp "$0" _usage "$0"
exit 1 exit 1
fi fi
## We the counter we offer the interesting feature of processing all arguments ## We the counter we offer the interesting feature of processing all arguments
@ -49,24 +48,24 @@ DEST="$(eval "echo \$$#")"
count=0 count=0
for i ; do for i ; do
count=$(($count+1)) count=$(($count+1))
[ $count -eq $# ] && break [ $count -eq $# ] && break
while IFS= read -r FILE; do while IFS= read -r FILE; do
DESTFILE="$DEST/$FILE" DESTFILE="$DEST/$FILE"
if [ ! -e "$DESTFILE" ] || $OPT_OVERWRITE; then if [ ! -e "$DESTFILE" ] || $OPT_OVERWRITE; then
mkdir -p "$(dirname "$DESTFILE")" mkdir -p "$(dirname "$DESTFILE")"
mv -v "$i/../$FILE" "$DESTFILE" mv -v "$i/../$FILE" "$DESTFILE"
if $OPT_DELEMPTY; then if $OPT_DELEMPTY; then
PARENT="$FOLDER/../$FILE" PARENT="$FOLDER/../$FILE"
PARENT="${PARENT%/*}" PARENT="${PARENT%/*}"
rmdir "$PARENT" 2>/dev/null rmdir "$PARENT" 2>/dev/null
fi fi
fi fi
## We switch to $i so that 'find' strips the parent dirs from the path. ## We switch to $i so that 'find' strips the parent dirs from the path.
done <<EOF done <<EOF
$(cd -- "$i/.." && find "$(basename ${i})" \( -type f -o -type l \) ) $(cd -- "$i/.." && find "$(basename ${i})" \( -type f -o -type l \) )
EOF EOF
done done

View File

@ -3,29 +3,29 @@
rate=64000 rate=64000
awk -v rate="$rate" 'function wl() { awk -v rate="$rate" 'function wl() {
return (rate/160)*(0.87055^(int(rand()*10)))}; return (rate/160)*(0.87055^(int(rand()*10)))};
BEGIN { BEGIN {
srand(); srand();
wla=wl(); wla=wl();
while(1) { while(1) {
wlb=wla; wlb=wla;
wla=wl(); wla=wl();
if (wla==wlb) if (wla==wlb)
{wla*=2;}; {wla*=2;};
d=(rand()*10+5)*rate/4; d=(rand()*10+5)*rate/4;
a=b=0; c=128; a=b=0; c=128;
ca=40/wla; cb=20/wlb; ca=40/wla; cb=20/wlb;
de=rate/10; di=0; de=rate/10; di=0;
for (i=0;i<d;i++) { for (i=0;i<d;i++) {
a++; b++; di++; c+=ca+cb; a++; b++; di++; c+=ca+cb;
if (a>wla) if (a>wla)
{a=0; ca*=-1}; {a=0; ca*=-1};
if (b>wlb) if (b>wlb)
{b=0; cb*=-1}; {b=0; cb*=-1};
if (di>de) if (di>de)
{di=0; ca*=0.9; cb*=0.9}; {di=0; ca*=0.9; cb*=0.9};
printf("%c",c)}; printf("%c",c)};
c=int(c); c=int(c);
while(c!=128) { while(c!=128) {
c<128?c++:c--; c<128?c++:c--;
printf("%c",c)};};}' | aplay -r $rate printf("%c",c)};};}' | aplay -r $rate

View File

@ -4,19 +4,19 @@
## better off running the dhcpcd daemon with ## better off running the dhcpcd daemon with
## /etc/wpa_supplicant/wpa_supplicant.conf configured if needed. See ## /etc/wpa_supplicant/wpa_supplicant.conf configured if needed. See
## dhcpcd-run-hooks(8). ## dhcpcd-run-hooks(8).
##
## Deps: wpa_supplicant, ccrypt (optional) ## Deps: wpa_supplicant, ccrypt (optional)
##
## We need to use wpa_supplicant's unencrypted config file. We store it in a ## 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 ## 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 ## 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 ## 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. ## <(...) 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 ## 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 ## variable containing the password. You can set PW securely by using a shell
## built-in like 'read -s PW'. ## built-in like 'read -s PW'.
##
## There is an Emacs plugin for editing crypted files directly. See 'man ## There is an Emacs plugin for editing crypted files directly. See 'man
## ccrypt'. ## ccrypt'.
@ -25,9 +25,8 @@ TIMEOUT_LIMIT=500
USE_DHCP=0 USE_DHCP=0
USE_CRYPT=0 USE_CRYPT=0
_printhelp () _usage () {
{ cat<<EOF
cat<<EOF
Usage: ${1##*/} [OPTIONS] Usage: ${1##*/} [OPTIONS]
Connect to a wireless network. Connect to a wireless network.
@ -42,48 +41,48 @@ EOF
} }
while getopts ":cdht:w:" opt; do while getopts ":cdht:w:" opt; do
case $opt in case $opt in
h) h)
_printhelp "$0" _usage "$0"
return 1 ;; return 1 ;;
c) c)
USE_CRYPT=1 ;; USE_CRYPT=1 ;;
d) d)
USE_DHCP=1 ;; USE_DHCP=1 ;;
t) t)
TIMEOUT_LIMIT=$OPTARG ;; TIMEOUT_LIMIT=$OPTARG ;;
w) w)
WSFILE="$OPTARG" ;; WSFILE="$OPTARG" ;;
?) \?)
_printhelp "$0" _usage "$0"
return 1 ;; return 1 ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $(id -u) -ne 0 ]; then if [ $(id -u) -ne 0 ]; then
echo "You must be root to run this script." echo "You must be root to run this script."
exit exit
fi fi
if [ $USE_CRYPT -eq 1 ]; then if [ $USE_CRYPT -eq 1 ]; then
if ! command -v ccat >/dev/null 2>&1; then if ! command -v ccat >/dev/null 2>&1; then
echo >&2 "'ccat' not found in PATH. Exiting." echo >&2 "'ccat' not found in PATH. Exiting."
exit 1 exit 1
fi fi
WPA_SUPPLICANT_CONF="$(ccat "$WSFILE")" WPA_SUPPLICANT_CONF="$(ccat "$WSFILE")"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to decrypt wpa_supplicant config from $WSFILE." echo "Failed to decrypt wpa_supplicant config from $WSFILE."
exit exit
fi fi
else else
WPA_SUPPLICANT_CONF="$(cat "$WSFILE")" WPA_SUPPLICANT_CONF="$(cat "$WSFILE")"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to get wpa_supplicant config from $WSFILE." echo "Failed to get wpa_supplicant config from $WSFILE."
exit exit
fi fi
fi fi
## Note: systemd-197 introduced Predictable Network Interface Names, so we need ## 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 pkill wpa_supplicant
if [ "$OSTYPE" = "linux-gnu" ] ; then if [ "$OSTYPE" = "linux-gnu" ] ; then
## Clean running processes if any. ## Clean running processes if any.
pkill dhcpcd pkill dhcpcd
## In case network inteface is not up. ## In case network inteface is not up.
ip link set ${NET_INTERFACE} up ip link set ${NET_INTERFACE} up
# Associate if needed. # Associate if needed.
if [ "$1" = "-f" ] || [ -z "$(iw dev ${NET_INTERFACE} link | grep SSID)" ]; then 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}") wpa_supplicant -B -i ${NET_INTERFACE} -D wext -c <(echo "${WPA_SUPPLICANT_CONF}")
fi fi
## Wait until wpa_supplicant has finished association. ## Wait until wpa_supplicant has finished association.
i=0 i=0
while [ -z "$(iw dev ${NET_INTERFACE} link | grep SSID)" ] && [ $i -lt $TIMEOUT_LIMIT ] ; do while [ -z "$(iw dev ${NET_INTERFACE} link | grep SSID)" ] && [ $i -lt $TIMEOUT_LIMIT ] ; do
i=$(($i+1)) i=$(($i+1))
done done
## Get IP. ## Get IP.
[ $USE_DHCP -eq 1 ] && dhcpcd ${NET_INTERFACE} [ $USE_DHCP -eq 1 ] && dhcpcd ${NET_INTERFACE}
else else
## BSD ## BSD
## Same comments as for Linux. ## Same comments as for Linux.
pkill dhclient pkill dhclient
ifconfig wlan0 up ifconfig wlan0 up
if [ -n "$(ifconfig ${NET_INTERFACE} | grep 'ssid ""')" ]; then if [ -n "$(ifconfig ${NET_INTERFACE} | grep 'ssid ""')" ]; then
wpa_supplicant -B -i ${NET_INTERFACE} -c <(echo "${WPA_SUPPLICANT_CONF}") wpa_supplicant -B -i ${NET_INTERFACE} -c <(echo "${WPA_SUPPLICANT_CONF}")
fi fi
i=0 i=0
while [ -n "$(ifconfig ${NET_INTERFACE} | grep 'ssid ""')" ] && [ $i -lt $TIMEOUT_LIMIT ] ; do while [ -n "$(ifconfig ${NET_INTERFACE} | grep 'ssid ""')" ] && [ $i -lt $TIMEOUT_LIMIT ] ; do
i=$(($i+1)) i=$(($i+1))
done done
[ $USE_DHCP -eq 1 ] && dhclient ${NET_INTERFACE} [ $USE_DHCP -eq 1 ] && dhclient ${NET_INTERFACE}
fi fi

View File

@ -1,22 +1,22 @@
#!/bin/sh #!/bin/sh
if [ $# -ne 1 ] || [ "$1" = "-h" ] ; then if [ $# -ne 1 ] || [ "$1" = "-h" ] ; then
cat<<EOF cat<<EOF
Usage: ${1##*/} IP Usage: ${1##*/} IP
Print the map of the network associated to the provided IP. Print the map of the network associated to the provided IP.
EOF EOF
exit exit
fi fi
## Network operations ## Network operations
if ! command -v nmap >/dev/null 2>&1; then if ! command -v nmap >/dev/null 2>&1; then
echo >&2 "'nmap' not found in PATH. Exiting." echo >&2 "'nmap' not found in PATH. Exiting."
exit 1 exit 1
fi fi
echo "$1" echo "$1"
for SCANIP in $( nmap -sL "$1" | grep -i "\([[:digit:]]\+\.\)\{3,\}[[:digit:]]\+" | awk '{print $5}' ); do 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" sudo nmap -oX - -n -sT -T Normal -O -sR -I -F -P0 "$SCANIP"
echo echo
done done

View File

@ -1,8 +1,8 @@
#!/bin/sh #!/bin/sh
if ! command -v nmap >/dev/null 2>&1; then if ! command -v nmap >/dev/null 2>&1; then
echo >&2 "'nmap' not found in PATH. Exiting." echo >&2 "'nmap' not found in PATH. Exiting."
exit 1 exit 1
fi fi
SUBNET="$(ifconfig | awk '/inet/ && $0 !~ "127.0.0.1" {gsub(/\.[0-9]+$/, ".*", $2) ; print $2}')" SUBNET="$(ifconfig | awk '/inet/ && $0 !~ "127.0.0.1" {gsub(/\.[0-9]+$/, ".*", $2) ; print $2}')"

View File

@ -1,19 +1,19 @@
#!/bin/sh #!/bin/sh
if [ "$1" = "-h" ] || [ $# -gt 1 ]; then if [ "$1" = "-h" ] || [ $# -gt 1 ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} [INTERFACE] Usage: ${0##*/} [INTERFACE]
Return up and down transmission speed on given interface. If not given, use the Return up and down transmission speed on given interface. If not given, use the
first online interface returned by ifconfig (lo is ignored). first online interface returned by ifconfig (lo is ignored).
EOF EOF
exit exit
fi fi
if [ $# -ne 0 ]; then if [ $# -ne 0 ]; then
ARG="$1" ARG="$1"
else else
ARG="$PATH" ARG="$PATH"
fi fi
@ -23,8 +23,8 @@ INTERFACE="$(ifconfig | grep -vm1 '^lo\|^ \|^$' | cut -f1 -d':')"
[ -n "$1" ] && INTERFACE="$1" [ -n "$1" ] && INTERFACE="$1"
if [ ! -d "/sys/class/net/${INTERFACE}" ]; then if [ ! -d "/sys/class/net/${INTERFACE}" ]; then
echo "Error: no such interface (${INTERFACE})." echo "Error: no such interface (${INTERFACE})."
exit exit
fi fi
echo "$INTERFACE" echo "$INTERFACE"

View File

@ -1,8 +1,7 @@
#!/bin/sh #!/bin/sh
_printhelp() _usage () {
{ cat <<EOF
cat <<EOF
Usage: ${1##*/} [OPTIONS] PACKAGES Usage: ${1##*/} [OPTIONS] PACKAGES
Display size of files in PACKAGES. Display size of files in PACKAGES.
@ -16,30 +15,30 @@ EOF
OPTION_SORT="cat" OPTION_SORT="cat"
while getopts ":hn" opt; do while getopts ":hn" opt; do
case $opt in case $opt in
h) h)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
n) n)
OPTION_SORT="sort -h" ;; OPTION_SORT="sort -h" ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
echo "Missing argument." echo "Missing argument."
_printhelp "$0" _usage "$0"
exit 1 exit 1
fi fi
! command -v pacman >/dev/null && echo "You need pacman to run this script." && exit 1 ! command -v pacman >/dev/null && echo "You need pacman to run this script." && exit 1
if [ $(pacman -Qq "$@" 2>/dev/null | wc -l) -eq 0 ]; then if [ $(pacman -Qq "$@" 2>/dev/null | wc -l) -eq 0 ]; then
echo "No valid package given." >&2 echo "No valid package given." >&2
exit exit
fi fi
## We use "eval" to be compatible with non-POSIX wordsplitting (e.g. zsh). ## We use "eval" to be compatible with non-POSIX wordsplitting (e.g. zsh).

View File

@ -1,8 +1,7 @@
#!/bin/sh #!/bin/sh
_printhelp() _usage () {
{ cat <<EOF
cat <<EOF
Usage: ${1##*/} [-m|-e] [-q] FILE Usage: ${1##*/} [-m|-e] [-q] FILE
Display packages listed in FILE but not installed. Display packages listed in FILE but not installed.
@ -19,33 +18,33 @@ OPTION_FOREIGN=""
OPTION_LOCAL="-1" OPTION_LOCAL="-1"
while getopts ":hmqe" opt; do while getopts ":hmqe" opt; do
case $opt in case $opt in
e) e)
OPTION_EXPLICIT="e" ;; OPTION_EXPLICIT="e" ;;
h) h)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
m) m)
OPTION_FOREIGN="m" ;; OPTION_FOREIGN="m" ;;
q) q)
OPTION_LOCAL="-2" ;; OPTION_LOCAL="-2" ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
echo "Missing argument." echo "Missing argument."
_printhelp "$0" _usage "$0"
exit 1 exit 1
fi fi
if ! command -v pacman >/dev/null 2>&1; then if ! command -v pacman >/dev/null 2>&1; then
echo >&2 "'pacman' not found in PATH. Exiting." echo >&2 "'pacman' not found in PATH. Exiting."
exit 1 exit 1
fi fi
PKGLIST="$(mktemp)" PKGLIST="$(mktemp)"
@ -57,4 +56,3 @@ rm -f "$PKGLIST" "$FILE"
## Zsh version. ## Zsh version.
# comm -3 ${OPTION_LOCAL} <(pacman -Qq${OPTION_FOREIGN}${OPTION_EXPLICIT} | sort) <(sort "$*") # comm -3 ${OPTION_LOCAL} <(pacman -Qq${OPTION_FOREIGN}${OPTION_EXPLICIT} | sort) <(sort "$*")

View File

@ -51,7 +51,7 @@ remove_duplicates () {
} }
usage () { usage () {
cat <<EOF cat <<EOF
Usage: ${1##*/} [OPTIONS] PACKAGES Usage: ${1##*/} [OPTIONS] PACKAGES
${1##*/} -a [OPTIONS] ${1##*/} -a [OPTIONS]
@ -92,23 +92,23 @@ opt_total=false
while getopts ":ahnstV" opt; do while getopts ":ahnstV" opt; do
case $opt in case $opt in
a) a)
opt_all=true ;; opt_all=true ;;
h) h)
usage "$0" usage "$0"
exit ;; exit ;;
n) n)
opt_sort="sort -k3" ;; opt_sort="sort -k3" ;;
s) s)
opt_sort="sort -h" ;; opt_sort="sort -h" ;;
t) t)
opt_total="calc_total" ;; opt_total="calc_total" ;;
V) V)
version "$0" version "$0"
exit ;; exit ;;
?) \?)
usage "$0" usage "$0"
exit 1 ;; exit 1 ;;
esac esac
done done

View File

@ -9,9 +9,8 @@
# -dGraphicsAlphaBits=4 # -dGraphicsAlphaBits=4
# -dMaxStripSize=8192 # -dMaxStripSize=8192
_printhelp () _usage () {
{ cat <<EOF
cat <<EOF
Usage: ${1##*/} [OPTIONS] PDFFILES Usage: ${1##*/} [OPTIONS] PDFFILES
All PDF files will be compressed to a PDF file with "-compressed" appended in its name. All PDF files will be compressed to a PDF file with "-compressed" appended in its name.
@ -39,57 +38,57 @@ OPT_OVERWRITE=false
OPT_COMPRESSION="-dColorConversionStrategy=/LeaveColorUnchanged -dDownsampleMonoImages=false -dDownsampleGrayImages=false -dDownsampleColorImages=false -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode" OPT_COMPRESSION="-dColorConversionStrategy=/LeaveColorUnchanged -dDownsampleMonoImages=false -dDownsampleGrayImages=false -dDownsampleColorImages=false -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode"
while getopts ":cfhin" opt; do while getopts ":cfhin" opt; do
case $opt in case $opt in
c) c)
OPT_COMPRESSION="" ;; OPT_COMPRESSION="" ;;
f) f)
OPT_OVERWRITE=true ;; OPT_OVERWRITE=true ;;
h) h)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
i) i)
OPT_INPLACE=true ;; OPT_INPLACE=true ;;
n) n)
OPT_COMPRESSION="-dColorConversionStrategy=/LeaveColorUnchanged -dEncodeColorImages=false -dEncodeGrayImages=false -dEncodeMonoImages=false" ;; OPT_COMPRESSION="-dColorConversionStrategy=/LeaveColorUnchanged -dEncodeColorImages=false -dEncodeGrayImages=false -dEncodeMonoImages=false" ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_printhelp "$0" _usage "$0"
exit 1 exit 1
fi fi
for i ; do for i ; do
if [ ! -f "$i" ]; then if [ ! -f "$i" ]; then
echo "$i is not a valid file." echo "$i is not a valid file."
continue continue
fi fi
case "$i" in case "$i" in
*/*) ;; */*) ;;
*) i="./$i" ;; *) i="./$i" ;;
esac esac
DIRNAME="${i%/*}" DIRNAME="${i%/*}"
BASENAME="${i##*/}" BASENAME="${i##*/}"
EXTNAME="${BASENAME##*.}" EXTNAME="${BASENAME##*.}"
BASENAME="${BASENAME%.*}" BASENAME="${BASENAME%.*}"
OUTPUT="$DIRNAME/$BASENAME-compressed.pdf" OUTPUT="$DIRNAME/$BASENAME-compressed.pdf"
if [ -e "$OUTPUT" ] && ! $OPT_OVERWRITE; then if [ -e "$OUTPUT" ] && ! $OPT_OVERWRITE; then
echo "$OUTPUT alredy present. Skipping." echo "$OUTPUT alredy present. Skipping."
continue continue
fi fi
echo "$i" echo "$i"
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite $OPT_COMPRESSION -sOutputFile="$OUTPUT" "$i" gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite $OPT_COMPRESSION -sOutputFile="$OUTPUT" "$i"
if $OPT_INPLACE; then if $OPT_INPLACE; then
rm -f "$i" rm -f "$i"
mv "$OUTPUT" "$i" mv "$OUTPUT" "$i"
fi fi
done done

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
if [ $# -ne 4 ]; then if [ $# -ne 4 ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} PDFFILE FIRSTPAGE LASTPAGE DESTFILE Usage: ${0##*/} PDFFILE FIRSTPAGE LASTPAGE DESTFILE
Extract a range of pages from a PDF. Extract a range of pages from a PDF.

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
if [ $# -ne 2 ]; then if [ $# -ne 2 ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} INPUT OUTPUT Usage: ${0##*/} INPUT OUTPUT
Resize input PDF to an A4 output PDF. Resize input PDF to an A4 output PDF.
@ -14,4 +14,3 @@ if [ ! -f "$1" ]; then
fi fi
gs -q -o "$2" -sDEVICE=pdfwrite -sPAPERSIZE=a4 -dFIXEDMEDIA -dPDFFitPage -dCompatibilityLevel=1.4 "$1" gs -q -o "$2" -sDEVICE=pdfwrite -sPAPERSIZE=a4 -dFIXEDMEDIA -dPDFFitPage -dCompatibilityLevel=1.4 "$1"

View File

@ -1,18 +1,18 @@
#!/bin/sh #!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} PROCESS-EXP Usage: ${0##*/} PROCESS-EXP
Extended pgrep -a Extended pgrep -a
EOF EOF
exit exit
fi fi
for i ; do for i ; do
## We need to store the result of 'ps' first to prevent the filtering from ## We need to store the result of 'ps' first to prevent the filtering from
## appearing in the result. ## appearing in the result.
BUF="$(ps aux)" BUF="$(ps aux)"
echo "$BUF" | awk -v pid=$$ -v pattern="$i" '$2 != pid && $0 ~ pattern' echo "$BUF" | awk -v pid=$$ -v pattern="$i" '$2 != pid && $0 ~ pattern'
done done

View File

@ -9,29 +9,29 @@ mkdir -p "$PKG_ROOT"
## Arch Linux ## Arch Linux
if command -v pacman >/dev/null 2>&1; then if command -v pacman >/dev/null 2>&1; then
## Note: the "-n" option was added between 2012 and 2013. ## Note: the "-n" option was added between 2012 and 2013.
pacman -Qnq | sort >"$PKG_ROOT/arch-official-${HOST}" pacman -Qnq | sort >"$PKG_ROOT/arch-official-${HOST}"
pacman -Qmq | sort >"$PKG_ROOT/arch-aur-${HOST}" pacman -Qmq | sort >"$PKG_ROOT/arch-aur-${HOST}"
fi fi
## FreeBSD ## FreeBSD
if [ "$(uname)" = "FreeBSD" ]; then if [ "$(uname)" = "FreeBSD" ]; then
pkg_info | cut -f1 -d' ' >"$PKG_ROOT/freebsd-${HOST}" pkg_info | cut -f1 -d' ' >"$PKG_ROOT/freebsd-${HOST}"
fi fi
## TeXlive ## TeXlive
if command -v tlmgr >/dev/null 2>&1; then if command -v tlmgr >/dev/null 2>&1; then
## We use <TAB> in the sed expressions. ## We use <TAB> in the sed expressions.
TEXLIVE_BASIC="$(mktemp)" TEXLIVE_BASIC="$(mktemp)"
tlmgr info collection-basic --list | sed -n '/^ /{s/ //g;p;}' | sort >"$TEXLIVE_BASIC" tlmgr info collection-basic --list | sed -n '/^ /{s/ //g;p;}' | sort >"$TEXLIVE_BASIC"
TEXLIVE_ALL="$(mktemp)" TEXLIVE_ALL="$(mktemp)"
tlmgr info --only-installed | grep -v 'x86_64\|amd64' | cut -d' ' -f2 | cut -f1 -d':' | sort >"$TEXLIVE_ALL" 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' | \ 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}" 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 fi
## Zsh version ## Zsh version

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat <<EOF cat <<EOF
Usage: ${0##*/} [OPTIONS] STRING [FILES] Usage: ${0##*/} [OPTIONS] STRING [FILES]
Prepend STRING to FILES or stdin if unspecified. STRING may not contain pipes Prepend STRING to FILES or stdin if unspecified. STRING may not contain pipes
@ -12,13 +12,13 @@ Options:
-i: If files are provided, convert them in-place. -i: If files are provided, convert them in-place.
EOF EOF
exit exit
fi fi
unset OPT unset OPT
if [ "$1" = "-i" ]; then if [ "$1" = "-i" ]; then
OPT=-i OPT=-i
shift shift
fi fi
VAR="$1" VAR="$1"

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
if [ "$#" -eq 0 ] || [ "$1" = "-h" ]; then if [ "$#" -eq 0 ] || [ "$1" = "-h" ]; then
cat<<EOF cat<<EOF
Usage: ${1##*/} FILE Usage: ${1##*/} FILE
${1##*/} ENTRIES FILE ${1##*/} ENTRIES FILE
@ -9,12 +9,12 @@ Run ffprobe on FILE using shell print format. If no entry is specified, print
format and streams. format and streams.
EOF EOF
exit exit
fi fi
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
ffprobe -v quiet -print_format flat=s=_ -show_entries "$@" ffprobe -v quiet -print_format flat=s=_ -show_entries "$@"
else else
ffprobe -v quiet -print_format flat=s=_ -show_format -show_streams "$1" ffprobe -v quiet -print_format flat=s=_ -show_format -show_streams "$1"
fi fi

View File

@ -1,14 +1,14 @@
#!/bin/sh #!/bin/sh
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
cat <<EOF cat <<EOF
Usage: ${0##*/} [FILES] Usage: ${0##*/} [FILES]
Shuffle letters randomly and print result to stdout. If no file is provided, Shuffle letters randomly and print result to stdout. If no file is provided,
stdin is used. stdin is used.
EOF EOF
exit exit
fi fi
fold -w 1 "$@" | shuf | tr -d '\n' && echo fold -w 1 "$@" | shuf | tr -d '\n' && echo

View File

@ -1,25 +1,25 @@
#!/bin/sh #!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ] ; then if [ $# -eq 0 ] || [ "$1" = "-h" ] ; then
cat<<EOF cat<<EOF
Usage: ${1##*/} FILES Usage: ${1##*/} FILES
Rename FILES to lowercase if destination does not exist. Rename FILES to lowercase if destination does not exist.
EOF EOF
exit exit
fi fi
for f ; do for f ; do
filename=${f##*/} filename=${f##*/}
case "$f" in case "$f" in
*/*) dirname="${f%/*}" ;; */*) dirname="${f%/*}" ;;
*) dirname="." ;; *) dirname="." ;;
esac esac
nf="$(echo "$filename" | awk '{print tolower($0)}')" nf="$(echo "$filename" | awk '{print tolower($0)}')"
newname="${dirname}/${nf}" newname="${dirname}/${nf}"
mv -nv "$f" "$newname" 2>/dev/null mv -nv "$f" "$newname" 2>/dev/null
done done

View File

@ -1,23 +1,23 @@
#!/bin/sh #!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ] ; then if [ $# -eq 0 ] || [ "$1" = "-h" ] ; then
cat<<EOF cat<<EOF
Usage: ${1##*/} FOLDERS Usage: ${1##*/} FOLDERS
Rename to lowercase all files found in FOLDERS if destination does not exists. Rename to lowercase all files found in FOLDERS if destination does not exists.
EOF EOF
exit exit
fi fi
if ! command -v renamelower >/dev/null 2>&1; then if ! command -v renamelower >/dev/null 2>&1; then
echo "'renamelower' not found in PATH. Exiting." >&2 echo "'renamelower' not found in PATH. Exiting." >&2
exit 1 exit 1
fi fi
## Note: the -name check is not mandatory, but greatly improves the average ## Note: the -name check is not mandatory, but greatly improves the average
## performance. ## performance.
for i ; do for i ; do
find "$i" -depth -name '*[[:upper:]]*' -exec renamelower {} + find "$i" -depth -name '*[[:upper:]]*' -exec renamelower {} +
done done

View File

@ -1,14 +1,14 @@
#!/bin/sh #!/bin/sh
if [ $# -ne 2 ] || [ "$1" = "-h" ] ; then if [ $# -ne 2 ] || [ "$1" = "-h" ] ; then
cat<<EOF cat<<EOF
Usage: ${1##*/} FILE1 FILE2 Usage: ${1##*/} FILE1 FILE2
Swap 2 filenames around. Swap 2 filenames around.
EOF EOF
exit exit
fi fi
## We need a temp file is case both files are in the same folder. We use the ## We need a temp file is case both files are in the same folder. We use the
@ -19,16 +19,16 @@ fi
TEMPFILE="$(mktemp -u "$1.XXXXXX")" TEMPFILE="$(mktemp -u "$1.XXXXXX")"
case "$1" in case "$1" in
*/*) DIR1="${1%/*}" ;; */*) DIR1="${1%/*}" ;;
*) DIR1="." ;; *) DIR1="." ;;
esac esac
case "$2" in case "$2" in
*/*) DIR2="${2%/*}" ;; */*) DIR2="${2%/*}" ;;
*) DIR2="." ;; *) DIR2="." ;;
esac esac
if ! mv -n "$1" "$TEMPFILE"; then if ! mv -n "$1" "$TEMPFILE"; then
echo >&2 "Race condition, exiting. Try again." echo >&2 "Race condition, exiting. Try again."
fi fi
mv -n "$2" "$DIR2/${1##*/}" mv -n "$2" "$DIR2/${1##*/}"
mv -n "$TEMPFILE" "$DIR1/${2##*/}" mv -n "$TEMPFILE" "$DIR1/${2##*/}"

View File

@ -1,8 +1,7 @@
#!/bin/sh #!/bin/sh
_printhelp () _usage () {
{ cat<<EOF
cat<<EOF
Usage: ${1##*/} [OPTIONS] SEARCH REPLACE [FILES] Usage: ${1##*/} [OPTIONS] SEARCH REPLACE [FILES]
Replace SEARCH by REPLACE in FILES. If no file is provided, use stdin. Replace SEARCH by REPLACE in FILES. If no file is provided, use stdin.
@ -19,42 +18,41 @@ EOF
OPT_INPLACE="" OPT_INPLACE=""
while getopts ":ih" opt; do while getopts ":ih" opt; do
case $opt in case $opt in
i) i)
OPT_INPLACE=-i ;; OPT_INPLACE=-i ;;
h) h)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -lt 2 ]; then if [ $# -lt 2 ]; then
_printhelp "$0" _usage "$0"
exit 1 exit 1
fi fi
search="$1" search="$1"
replace="$2" replace="$2"
shift 2 shift 2
_replace() _replace () {
{ ## We cannot use gsub, otherwise regex substitutions could occur.
## We cannot use gsub, otherwise regex substitutions could occur. ## Source: http://mywiki.wooledge.org/BashFAQ/021
## Source: http://mywiki.wooledge.org/BashFAQ/021 awk -v s="$search" -v r="$replace" 'BEGIN {l=length(s)} {o="";while (i=index($0, s)) {o=o substr($0,1,i-1) r; $0=substr($0,i+l)} print o $0}' "$@"
awk -v s="$search" -v r="$replace" 'BEGIN {l=length(s)} {o="";while (i=index($0, s)) {o=o substr($0,1,i-1) r; $0=substr($0,i+l)} print o $0}' "$@"
} }
if [ $# -eq 0 ] || [ -z "$OPT_INPLACE" ]; then if [ $# -eq 0 ] || [ -z "$OPT_INPLACE" ]; then
_replace "$@" _replace "$@"
else else
for i ; do for i ; do
out="$(mktemp "$i.XXXXXX")" out="$(mktemp "$i.XXXXXX")"
_replace "$i" > "$out" _replace "$i" > "$out"
mv "$out" "$i" mv "$out" "$i"
done done
fi fi

View File

@ -1,14 +1,14 @@
#!/bin/sh #!/bin/sh
if [ "$1" = "-h" ] || [ $# -ne 2 ]; then if [ "$1" = "-h" ] || [ $# -ne 2 ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} FOLDER1 FOLDER2 Usage: ${0##*/} FOLDER1 FOLDER2
Dry-run of rsync over two folders. Dry-run of rsync over two folders.
EOF EOF
exit exit
fi fi
rsync -nivr --size-only --delete-excluded "$1"/ "$2" rsync -nivr --size-only --delete-excluded "$1"/ "$2"

View File

@ -1,13 +1,13 @@
#!/bin/sh #!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat <<EOF cat <<EOF
Usage: ${0##*/} FOLDERS Usage: ${0##*/} FOLDERS
Set file/directory owner and permissions according to current umask for current Set file/directory owner and permissions according to current umask for current
user. user.
EOF EOF
exit exit
fi fi
FMASK=$(umask -S | sed 's/x//g') FMASK=$(umask -S | sed 's/x//g')
@ -16,7 +16,7 @@ DMASK=$(umask -S)
[ -z "$GID" ] && GID=$(id -g) [ -z "$GID" ] && GID=$(id -g)
for i ; do for i ; do
find "$i" -exec chown -R ${UID}:${GID} {} \; find "$i" -exec chown -R ${UID}:${GID} {} \;
find "$i" -type d -exec chmod ${DMASK} {} \; find "$i" -type d -exec chmod ${DMASK} {} \;
find "$i" -type f -exec chmod ${FMASK} {} \; find "$i" -type f -exec chmod ${FMASK} {} \;
done done

View File

@ -1,21 +1,21 @@
#!/bin/sh #!/bin/sh
if [ "$1" = "-h" ]; then if [ "$1" = "-h" ]; then
cat <<EOF cat <<EOF
Usage: ${0##*/} Usage: ${0##*/}
Clean various running processes. Run it before exiting a session. Clean various running processes. Run it before exiting a session.
EOF EOF
exit exit
fi fi
if command -v emacsclient >/dev/null 2>&1; then if command -v emacsclient >/dev/null 2>&1; then
if emacsclient -e '(kill-emacs)' >/dev/null 2>&1; then if emacsclient -e '(kill-emacs)' >/dev/null 2>&1; then
echo "Emacs terminated." >&2 echo "Emacs terminated." >&2
fi fi
fi fi
if [ -S "$SSH_AUTH_SOCK" ]; then if [ -S "$SSH_AUTH_SOCK" ]; then
echo "SSH agent terminated." >&2 echo "SSH agent terminated." >&2
eval "$(ssh-agent -k)" eval "$(ssh-agent -k)"
fi fi

View File

@ -8,25 +8,24 @@
## to use shell comment delimiters. ## to use shell comment delimiters.
BEGIN { BEGIN {
## Since 'begin' and 'end' are regexes, we need to escape some sequences. ## Since 'begin' and 'end' are regexes, we need to escape some sequences.
if(begin == "") if(begin == "")
begin="/\\*" begin="/\\*"
if(end == "") if(end == "")
end="\\*/" end="\\*/"
} }
{ {
while (match ($0, begin)) while (match ($0, begin)) {
{ before = substr ($0, 1, RSTART-1)
before = substr ($0, 1, RSTART-1) $0 = substr($0, RSTART)
$0 = substr($0, RSTART) printf("%s", before)
printf("%s", before)
## Reach line where first 'end' is found. ## Reach line where first 'end' is found.
while (! match($0, end) ) while (! match($0, end) )
getline getline
$0 = substr($0, RSTART + length(end) -1) $0 = substr($0, RSTART + length(end) -1)
} }
print print
} }

View File

@ -1,45 +1,45 @@
#!/bin/sh #!/bin/sh
if [ -z "$(lspci|grep "VGA.*Radeon")" ]; then if [ -z "$(lspci|grep "VGA.*Radeon")" ]; then
echo "You must have a Radeon graphic adapter. Exit." echo "You must have a Radeon graphic adapter. Exit."
exit exit
fi fi
if [ $(id -u) -ne 0 ]; then if [ $(id -u) -ne 0 ]; then
echo "You must be root to run this script. Exit." echo "You must be root to run this script. Exit."
exit exit
fi fi
if [ $(pacman -Qi catalyst-utils 2>/dev/null |wc -l) -ge 2 ]; then if [ $(pacman -Qi catalyst-utils 2>/dev/null |wc -l) -ge 2 ]; then
pacman -Rdd --noconfirm catalyst catalyst-utils lib32-catalyst-utils pacman -Rdd --noconfirm catalyst catalyst-utils lib32-catalyst-utils
rm -f "/etc/X11/xorg.conf" rm -f "/etc/X11/xorg.conf"
pacman -S --noconfirm ati-dri lib32-ati-dri xf86-video-ati pacman -S --noconfirm ati-dri lib32-ati-dri xf86-video-ati
pacman -S --noconfirm mesa-libgl lib32-mesa-libgl pacman -S --noconfirm mesa-libgl lib32-mesa-libgl
pacman -S --noconfirm libcl lib32-libcl pacman -S --noconfirm libcl lib32-libcl
if [ -f "/boot/syslinux/syslinux.cfg" ]; then if [ -f "/boot/syslinux/syslinux.cfg" ]; then
ex -sc '/^LABEL arch$/+3 s/ nomodeset//|xit' '/boot/syslinux/syslinux.cfg' ex -sc '/^LABEL arch$/+3 s/ nomodeset//|xit' '/boot/syslinux/syslinux.cfg'
echo echo
echo "#### Syslinux entry:" echo "#### Syslinux entry:"
grep -A4 '^LABEL arch$' '/boot/syslinux/syslinux.cfg' grep -A4 '^LABEL arch$' '/boot/syslinux/syslinux.cfg'
else else
echo "You do not seem to use Syslinux. No configuration done." echo "You do not seem to use Syslinux. No configuration done."
echo "You have to remove 'nomodeset' kernel parameter manually." echo "You have to remove 'nomodeset' kernel parameter manually."
fi fi
else else
pacman -Rs --noconfirm ati-dri lib32-ati-dri xf86-video-ati pacman -Rs --noconfirm ati-dri lib32-ati-dri xf86-video-ati
pacman -Rdd --noconfirm mesa-libgl lib32-mesa-libgl pacman -Rdd --noconfirm mesa-libgl lib32-mesa-libgl
pacman -Rdd --noconfirm libcl lib32-libcl pacman -Rdd --noconfirm libcl lib32-libcl
pacman -S --noconfirm catalyst catalyst-utils lib32-catalyst-utils pacman -S --noconfirm catalyst catalyst-utils lib32-catalyst-utils
aticonfig --initial aticonfig --initial
if [ $? -eq 0 ] && [ -f '/boot/syslinux/syslinux.cfg' ]; then if [ $? -eq 0 ] && [ -f '/boot/syslinux/syslinux.cfg' ]; then
ex -sc '/^LABEL arch$/+3 s/$/ nomodeset/|xit' '/boot/syslinux/syslinux.cfg' ex -sc '/^LABEL arch$/+3 s/$/ nomodeset/|xit' '/boot/syslinux/syslinux.cfg'
echo echo
echo "#### Syslinux entry:" echo "#### Syslinux entry:"
grep -A4 "^LABEL arch$" "/boot/syslinux/syslinux.cfg" grep -A4 "^LABEL arch$" "/boot/syslinux/syslinux.cfg"
else else
echo "You do not seem to use Syslinux. No configuration done." echo "You do not seem to use Syslinux. No configuration done."
echo "You have to add 'nomodeset' kernel parameter manually." echo "You have to add 'nomodeset' kernel parameter manually."
fi fi
fi fi

View File

@ -4,73 +4,72 @@
## format. WARNING: unpolished work. Use at your own risk! ## format. WARNING: unpolished work. Use at your own risk!
BEGIN { BEGIN {
FS="\" " FS="\" "
tagsep=" " tagsep=" "
project_empty="<none>" project_empty="<none>"
prio_array["H"]="[#A]" prio_array["H"]="[#A]"
prio_array["M"]="[#B]" prio_array["M"]="[#B]"
prio_array["L"]="[#C]" prio_array["L"]="[#C]"
recur_array["yearly"]="+1y" recur_array["yearly"]="+1y"
recur_array["monthly"]="+1m" recur_array["monthly"]="+1m"
recur_array["weekly"]="+1w" recur_array["weekly"]="+1w"
recur_array["daily"]="+1d" recur_array["daily"]="+1d"
} }
{ {
gsub(/^\[|\]$/,"") gsub(/^\[|\]$/,"")
gsub(/:"/,":") gsub(/:"/,":")
description="" description=""
project=project_empty project=project_empty
annotation="" annotation=""
start="" start=""
priority="" priority=""
recur="" recur=""
due="" due=""
tags="" tags=""
for (i = 1; i <= NF; i++) for (i = 1; i <= NF; i++) {
{ split($i, a, ":")
split($i, a, ":")
if (a[1] ~ "^description$") if (a[1] ~ "^description$")
description=a[2] " " description=a[2] " "
else if (a[1] ~ "^project$") else if (a[1] ~ "^project$")
project=a[2] project=a[2]
else if (a[1] ~ "^annotation") else if (a[1] ~ "^annotation")
annotation=annotation "\n " a[2] annotation=annotation "\n " a[2]
else if (a[1] ~ "^priority$") else if (a[1] ~ "^priority$")
priority=prio_array[a[2]] " " priority=prio_array[a[2]] " "
else if (a[1] ~ "^tags$") else if (a[1] ~ "^tags$")
tags=tagsep ":" a[2] ": " tags=tagsep ":" a[2] ": "
else if (a[1] ~ "^start$") else if (a[1] ~ "^start$")
start="TODO " start="TODO "
if (a[1] ~ "^recur$") if (a[1] ~ "^recur$")
recur=" " recur_array[a[2]] recur=" " recur_array[a[2]]
if (a[1] ~ "^due$") if (a[1] ~ "^due$")
due="<" strftime("%F",a[2]) due="<" strftime("%F",a[2])
delete a delete a
} }
## Close 'due' after loop in case 'recur' was encountered after 'due'. ## Close 'due' after loop in case 'recur' was encountered after 'due'.
if (due != "") if (due != "")
due = due recur "> " 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) { function capitalize(s) {
return toupper(substr(s,1,1)) tolower(substr(s,2)) return toupper(substr(s,1,1)) tolower(substr(s,2))
} }
END { END {
for ( var in result) for ( var in result)
printf ("\n* %s%s\n", capitalize(var), result[var]) printf ("\n* %s%s\n", capitalize(var), result[var])
} }

View File

@ -1,26 +1,25 @@
#!/bin/sh #!/bin/sh
if ! command -v mediainfo >/dev/null 2>&1; then if ! command -v mediainfo >/dev/null 2>&1; then
echo "mediainfo required." echo "mediainfo required."
exit exit
fi fi
## This will check for badly encoded audio. ## This will check for badly encoded audio.
while IFS= read -r i; do while IFS= read -r i; do
BUFFER="$(mediainfo "$i")" BUFFER="$(mediainfo "$i")"
[ -n "$(echo "$BUFFER" | grep "Bit rate mode *: Constant")" ] && echo "$i : CBR" [ -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 <<EOF done <<EOF
$(find "." \( \ $(find "." \( \
-iname '*.mp3' -o \ -iname '*.mp3' -o \
-iname '*.flac' -o \ -iname '*.flac' -o \
-iname '*.wv' -o \ -iname '*.wv' -o \
-iname '*.aac' -o \ -iname '*.aac' -o \
-iname '*.wav' -o \ -iname '*.wav' -o \
-iname '*.ape' -o \ -iname '*.ape' -o \
-iname '*.mpc' \) ) -iname '*.mpc' \) )
EOF EOF

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat<<EOF cat<<EOF
Usage: ${1##*/} FOLDERS Usage: ${1##*/} FOLDERS
Convert all 'bad' encoding to UTF-8/LF. Convert all 'bad' encoding to UTF-8/LF.
@ -12,42 +12,42 @@ EOF
fi fi
if ! command -v recode >/dev/null 2>&1; then if ! command -v recode >/dev/null 2>&1; then
echo "recode needed." echo "recode needed."
exit exit
fi fi
for i ; do for i ; do
while IFS= read -r j; do while IFS= read -r j; do
CODING=$(file "$j") CODING=$(file "$j")
if [ -n "$(echo $CODING | grep 'ISO-8859')" ]; then if [ -n "$(echo $CODING | grep 'ISO-8859')" ]; then
echo "ISO-8859: [$j]" echo "ISO-8859: [$j]"
recode latin1..utf-8 "$j" recode latin1..utf-8 "$j"
elif [ -n "$(echo $CODING | grep 'Non-ISO extended-ASCII')" ]; then elif [ -n "$(echo $CODING | grep 'Non-ISO extended-ASCII')" ]; then
echo "cp1252: [$j]" echo "cp1252: [$j]"
recode cp1252..utf-8 "$j" recode cp1252..utf-8 "$j"
elif [ -n "$(echo $CODING | grep 'UTF-16 Unicode text')" ]; then elif [ -n "$(echo $CODING | grep 'UTF-16 Unicode text')" ]; then
echo "UTF-16: [$j]" echo "UTF-16: [$j]"
recode utf-16..utf-8 "$j" recode utf-16..utf-8 "$j"
elif [ -n "$(echo $CODING | grep 'UTF-8 Unicode (with BOM)')" ]; then elif [ -n "$(echo $CODING | grep 'UTF-8 Unicode (with BOM)')" ]; then
echo "UTF-8 BOM: [$j]" echo "UTF-8 BOM: [$j]"
ex -sc '1s/^.//|xit' "$j" ex -sc '1s/^.//|xit' "$j"
## The following commands are funny alternatives, but are completely ## The following commands are funny alternatives, but are completely
## overkill. ## overkill.
# dd iflag=skip_bytes skip=3 if=file.srt of=temp.srt # dd iflag=skip_bytes skip=3 if=file.srt of=temp.srt
# dd bs=1 skip=3 if=file.srt of=temp.srt # dd bs=1 skip=3 if=file.srt of=temp.srt
# tail -c +32 file.srt > temp.srt # tail -c +32 file.srt > temp.srt
fi fi
if [ -n "$(echo $CODING | grep 'CRLF')" ]; then if [ -n "$(echo $CODING | grep 'CRLF')" ]; then
echo "CRLF: [$j]" echo "CRLF: [$j]"
ex -sc '%s/ //g|xit' "$j" ex -sc '%s/ //g|xit' "$j"
fi fi
done <<EOF done <<EOF
$(find "$i" -type f -size -50M -print) $(find "$i" -type f -size -50M -print)
EOF EOF
done done

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat<<EOF cat<<EOF
Usage: ${1##*/} FOLDERS Usage: ${1##*/} FOLDERS
Check for files containing common mispelling, like "`" and "´" instead of "'", Check for files containing common mispelling, like "`" and "´" instead of "'",
@ -11,18 +11,18 @@ EOF
fi fi
if ! command -v recode >/dev/null 2>&1; then if ! command -v recode >/dev/null 2>&1; then
echo "recode needed." echo "recode needed."
exit exit
fi fi
for i ; do for i ; do
while IFS= read -r j; do while IFS= read -r j; do
echo -n "# " echo -n "# "
file "$j" file "$j"
grep -m1 "\`" "$j" grep -m1 "\`" "$j"
grep -m1 "´" "$j" grep -m1 "´" "$j"
grep -m1 "oe" "$j" grep -m1 "oe" "$j"
done <<EOF done <<EOF
$(find "$i" -type f -size -50M -print) $(find "$i" -type f -size -50M -print)
EOF EOF
done done

View File

@ -2,9 +2,8 @@
OUTPUT_NAME="tc-video" OUTPUT_NAME="tc-video"
_printhelp() if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
{ cat <<EOF
cat <<EOF
Usage: ${1##*/} [FILES] Usage: ${1##*/} [FILES]
Create a '$OUTPUT_NAME' script in current folder. The script provides a FFmpeg call Create a '$OUTPUT_NAME' script in current folder. The script provides a FFmpeg call
@ -13,29 +12,25 @@ to transcode FILES with some useful options and instructive help.
This script is meant to be easily editable to fit the user needs. This script is meant to be easily editable to fit the user needs.
EOF EOF
} exit
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
_printhelp "$0"
exit
fi fi
_escname () { _escname () {
echo "$@" | sed 's|/|\\/|g' echo "$@" | sed 's|/|\\/|g'
} }
SCRIPT_PATH="${0%/*}" SCRIPT_PATH="${0%/*}"
SCRIPT_NAME="${0##*/}" SCRIPT_NAME="${0##*/}"
FILELIST="" FILELIST=""
if [ -f "$SCRIPT_PATH/.$SCRIPT_NAME.in" ]; then if [ -f "$SCRIPT_PATH/.$SCRIPT_NAME.in" ]; then
cp -i "$SCRIPT_PATH/.$SCRIPT_NAME.in" "$OUTPUT_NAME" cp -i "$SCRIPT_PATH/.$SCRIPT_NAME.in" "$OUTPUT_NAME"
for i ; do for i ; do
esci="$(_escname "$i")" esci="$(_escname "$i")"
FILELIST="${FILELIST:+$FILELIST -i }'$esci'" FILELIST="${FILELIST:+$FILELIST -i }'$esci'"
ex -sc "%s/###FILENAMES/'$esci' ###FILENAMES/ | xit" "$OUTPUT_NAME" ex -sc "%s/###FILENAMES/'$esci' ###FILENAMES/ | xit" "$OUTPUT_NAME"
done done
ex -sc '%s/###FILELIST/'"$FILELIST"'/ | xit' "$OUTPUT_NAME" ex -sc '%s/###FILELIST/'"$FILELIST"'/ | xit' "$OUTPUT_NAME"
chmod +x "$OUTPUT_NAME" chmod +x "$OUTPUT_NAME"
else else
echo ".$SCRIPT_NAME.in not found!" echo ".$SCRIPT_NAME.in not found!"
fi fi

View File

@ -2,9 +2,8 @@
## TODO: handle srt encoding? ## TODO: handle srt encoding?
_printhelp() _usage () {
{ cat <<EOF
cat <<EOF
Usage: ${1##*/} [OPTIONS] FILES|FOLDERS Usage: ${1##*/} [OPTIONS] FILES|FOLDERS
Transcode FILES or files found in FOLDERS to desired format (default to .mkv Transcode FILES or files found in FOLDERS to desired format (default to .mkv
@ -89,71 +88,69 @@ OPT_PREVIEW=false
OPT_COPY=false OPT_COPY=false
while getopts ":a:b:cCe:fho:pPsS:tv:" opt; do while getopts ":a:b:cCe:fho:pPsS:tv:" opt; do
case $opt in case $opt in
a) a)
AUDIO_CODEC=$OPTARG ;; AUDIO_CODEC=$OPTARG ;;
b) b)
AUDIO_DEFAULT_RATE=$OPTARG ;; AUDIO_DEFAULT_RATE=$OPTARG ;;
c) c)
VIDEO_PARAM="-c:v copy" VIDEO_PARAM="-c:v copy"
AUDIO_PARAM="-c:a copy" AUDIO_PARAM="-c:a copy"
OPT_COPY=true;; OPT_COPY=true;;
C) C)
OPT_CROP=true;; OPT_CROP=true;;
e) e)
EXT=$OPTARG;; EXT=$OPTARG;;
f) f)
OVERWRITE="-y" OVERWRITE="-y"
OPT_OVERWRITE=true;; OPT_OVERWRITE=true;;
h) h)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
o) o)
TC_VIDEO_OPT="$OPTARG" ;; TC_VIDEO_OPT="$OPTARG" ;;
p) p)
OPT_PREVIEW=true ;; OPT_PREVIEW=true ;;
P) P)
OPT_CROP=true OPT_CROP=true
OPT_PREVIEW=true OPT_PREVIEW=true
OPT_CROPPREVIEW=true ;; OPT_CROPPREVIEW=true ;;
s) s)
SAMPLE="-ss 60 -t 360" ;; SAMPLE="-ss 60 -t 360" ;;
S) S)
SAMPLE="-ss 60 -t $((60*$OPTARG))" ;; SAMPLE="-ss 60 -t $((60*$OPTARG))" ;;
t) t)
OPT_REMOVE_TITLE=true ;; OPT_REMOVE_TITLE=true ;;
v) v)
VIDEO_PARAM="-c:v $OPTARG" ;; VIDEO_PARAM="-c:v $OPTARG" ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 ;; exit 1 ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_printhelp "$0" _usage "$0"
exit exit
fi fi
if ! command -v ffmpeg >/dev/null; then if ! command -v ffmpeg >/dev/null; then
echo "ffmpeg required." echo "ffmpeg required."
exit exit
fi fi
_highfreq() _highfreq() {
{ awk 'BEGIN{max=0} /crop=/ {t[$NF]++; if (t[$NF]>max) {max=t[$NF]; val=$NF}} END{print val}'
awk 'BEGIN{max=0} /crop=/ {t[$NF]++; if (t[$NF]>max) {max=t[$NF]; val=$NF}} END{print val}'
} }
## Usage: _cropvalue FILE STEP ## Usage: _cropvalue FILE STEP
## Return the crop values as ffmpeg output them. ## Return the crop values as ffmpeg output them.
_cropvalue() _cropvalue() {
{ local step=$2
local step=$2 for i in $(seq $step $step $((5*$step))); do
for i in $(seq $step $step $((5*$step))); do ffmpeg -nostdin -ss $i -i "$1" -t 10 -vf "cropdetect=24:2:0" -f null - 2>&1
ffmpeg -nostdin -ss $i -i "$1" -t 10 -vf "cropdetect=24:2:0" -f null - 2>&1 done | _highfreq
done | _highfreq
} }
## Return the audio encoding parameters. For instance ## 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 ## 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 ## or 0, we encode it to a default value. If default value is 0, then we copy
## stream. ## stream.
_audiobitrate() _audiobitrate() {
{ local bitrate
local bitrate
for i in $(seq 0 $(($format_nb_streams-1)) ); do for i in $(seq 0 $(($format_nb_streams-1)) ); do
## Skip non audio tracks. ## Skip non audio tracks.
[ "$(eval echo \$streams_stream_${i}_codec_type)" != "audio" ] && continue [ "$(eval echo \$streams_stream_${i}_codec_type)" != "audio" ] && continue
bitrate=$(eval echo \$streams_stream_${i}_bit_rate) bitrate=$(eval echo \$streams_stream_${i}_bit_rate)
if [ -n "$bitrate" ] && [ "$bitrate" -gt 0 ] 2>/dev/null; then if [ -n "$bitrate" ] && [ "$bitrate" -gt 0 ] 2>/dev/null; then
## If non-empty and a positive number. ## If non-empty and a positive number.
bitrate=$(( $bitrate / 1000)) bitrate=$(( $bitrate / 1000))
else else
bitrate="$AUDIO_DEFAULT_RATE" bitrate="$AUDIO_DEFAULT_RATE"
fi fi
if [ "$bitrate" -le 0 ] || \ if [ "$bitrate" -le 0 ] || \
[ "$AUDIO_CODEC" = "$(eval echo \$streams_stream_${i}_codec_name)" ] || \ [ "$AUDIO_CODEC" = "$(eval echo \$streams_stream_${i}_codec_name)" ] || \
[ "$AUDIO_CODEC" = "lib$(eval echo \$streams_stream_${i}_codec_name)" ]; then [ "$AUDIO_CODEC" = "lib$(eval echo \$streams_stream_${i}_codec_name)" ]; then
printf -- "-c:%s copy " $i printf -- "-c:%s copy " $i
else else
[ $bitrate -gt 500 ] && bitrate=500 [ $bitrate -gt 500 ] && bitrate=500
printf -- "-c:%s %s -b:%s %sk " $i "$AUDIO_CODEC" $i "$bitrate" printf -- "-c:%s %s -b:%s %sk " $i "$AUDIO_CODEC" $i "$bitrate"
fi fi
done done
} }
_transcode() _transcode() {
{ echo "==> [$1]"
echo "==> [$1]" OUTPUT="${1%.*}.$EXT"
OUTPUT="${1%.*}.$EXT" [ -e "$OUTPUT" ] && OUTPUT="${1%.*}-$(date '+%F-%H%M%S').$EXT"
[ -e "$OUTPUT" ] && OUTPUT="${1%.*}-$(date '+%F-%H%M%S').$EXT"
## Metadata (i.e. tags + technical data). ## Metadata (i.e. tags + technical data).
_buffer="$(ffprobe -v quiet -print_format flat=s=_ -show_streams -show_format "$1")" _buffer="$(ffprobe -v quiet -print_format flat=s=_ -show_streams -show_format "$1")"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
_error "File [$1] is unsupported by FFmpeg." _error "File [$1] is unsupported by FFmpeg."
return return
fi fi
eval "$_buffer" eval "$_buffer"
unset _buffer unset _buffer
STREAM_TITLE="" STREAM_TITLE=""
if $OPT_REMOVE_TITLE; then if $OPT_REMOVE_TITLE; then
for i in $(seq 0 $(($format_nb_streams-1)) ); do for i in $(seq 0 $(($format_nb_streams-1)) ); do
STREAM_TITLE="${STREAM_TITLE}-metadata:s:$i title= " STREAM_TITLE="${STREAM_TITLE}-metadata:s:$i title= "
done done
fi fi
if $OPT_CROP; then if $OPT_CROP; then
echo "Computing crop values... " echo "Computing crop values... "
## For 5 different timeslices of 1 second at every 1/6th of the video, ## 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 ## we sample the crop values. We keep the values with highest
## frequency. This is much faster than encoding in one pass with low ## frequency. This is much faster than encoding in one pass with low
## framerate. ## framerate.
STEP=${format_duration:-$streams_stream_0_duration} STEP=${format_duration:-$streams_stream_0_duration}
STEP="${STEP%%.*}" STEP="${STEP%%.*}"
STEP=$(($STEP/6)) STEP=$(($STEP/6))
VIDEO_FILTER="-vf $(_cropvalue "$1" "$STEP")" VIDEO_FILTER="-vf $(_cropvalue "$1" "$STEP")"
if $OPT_CROPPREVIEW; then if $OPT_CROPPREVIEW; then
echo "Generating preview... " echo "Generating preview... "
for i in $(seq $STEP $STEP $((5*$STEP))); do for i in $(seq $STEP $STEP $((5*$STEP))); do
ffmpeg -nostdin -v warning -y -ss $i -i "$1" \ ffmpeg -nostdin -v warning -y -ss $i -i "$1" \
-f image2 -vframes 1 $VIDEO_FILTER "${1%.*}-preview-$i-cropped.png" \ -f image2 -vframes 1 $VIDEO_FILTER "${1%.*}-preview-$i-cropped.png" \
-f image2 -vframes 1 "${1%.*}-preview-$i-uncropped.png" -f image2 -vframes 1 "${1%.*}-preview-$i-uncropped.png"
done done
fi fi
fi fi
## WARNING: we mix down audio to 2 channels with '-ac 2'. This greatly ## 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 ## 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 ## case when converting DTS to any other format because DTS has embedded
## channel description which is not available in these formats. ## channel description which is not available in these formats.
! $OPT_COPY && AUDIO_PARAM="$(_audiobitrate "$1") -ac 2" ! $OPT_COPY && AUDIO_PARAM="$(_audiobitrate "$1") -ac 2"
cat<<EOF cat<<EOF
================================================================================ ================================================================================
User options: ${TC_VIDEO_OPT:-none} User options: ${TC_VIDEO_OPT:-none}
Sample: ${SAMPLE:-no} Sample: ${SAMPLE:-no}
@ -249,47 +244,47 @@ Output file: $OUTPUT
================================================================================ ================================================================================
EOF EOF
$OPT_PREVIEW && return $OPT_PREVIEW && return
ffmpeg -nostdin $OVERWRITE -i "$1" \ ffmpeg -nostdin $OVERWRITE -i "$1" \
$VIDEO_PARAM $VIDEO_FILTER \ $VIDEO_PARAM $VIDEO_FILTER \
$AUDIO_PARAM \ $AUDIO_PARAM \
-c:s copy \ -c:s copy \
-map 0 $STREAM_TITLE \ -map 0 $STREAM_TITLE \
$SAMPLE $TC_VIDEO_OPT "$OUTPUT" $SAMPLE $TC_VIDEO_OPT "$OUTPUT"
if $OPT_OVERWRITE; then if $OPT_OVERWRITE; then
rm "$1" rm "$1"
mv -f "$OUTPUT" "${1%.*}.$EXT" mv -f "$OUTPUT" "${1%.*}.$EXT"
fi fi
echo echo
} }
for i in "$@"; do for i in "$@"; do
## Argument is a folder. We search for all video files in there. ## Argument is a folder. We search for all video files in there.
if [ -d "$i" ]; then if [ -d "$i" ]; then
## WARNING: ffmpeg continues to read stdin once it has started, so it should ## WARNING: ffmpeg continues to read stdin once it has started, so it should
## not be called from within a while<<EOF loop without disabling stdin. ## not be called from within a while<<EOF loop without disabling stdin.
while IFS= read -r j; do while IFS= read -r j; do
_transcode "$j" _transcode "$j"
done<<EOF done<<EOF
$(find "$i" \( \ $(find "$i" \( \
-iname '*.avi' -o \ -iname '*.avi' -o \
-iname '*.flv' -o \ -iname '*.flv' -o \
-iname '*.mkv' -o \ -iname '*.mkv' -o \
-iname '*.mov' -o \ -iname '*.mov' -o \
-iname '*.mp4' -o \ -iname '*.mp4' -o \
-iname '*.mpeg' -o \ -iname '*.mpeg' -o \
-iname '*.mpg' -o \ -iname '*.mpg' -o \
-iname '*.webm' -o \ -iname '*.webm' -o \
-iname '*.wmv' \) ) -iname '*.wmv' \) )
EOF EOF
else else
## Argument is a regular file. ## Argument is a regular file.
_transcode "$i" _transcode "$i"
fi fi
done done

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat <<EOF cat <<EOF
Usage: ${0##*/} FOLDERS Usage: ${0##*/} FOLDERS
Clean TeX/LaTeX/Texinfo project folders recursively. Clean TeX/LaTeX/Texinfo project folders recursively.
@ -12,25 +12,25 @@ remove files matching these extensions if they are not linked to a TeX file in
any manner. any manner.
EOF EOF
exit exit
fi fi
for i ; do for i ; do
while read -r FILE; do while read -r FILE; do
case FILE in case FILE in
*/*) ;; */*) ;;
*) *)
FILE="./$FILE" ;; FILE="./$FILE" ;;
esac esac
DIRNAME="${FILE%/*}" DIRNAME="${FILE%/*}"
BASENAME="${FILE##*/}" BASENAME="${FILE##*/}"
BASENAME="${BASENAME%.*}" BASENAME="${BASENAME%.*}"
rm -v $(for j in \ rm -v $(
aux bbl blg cp cps fn glg glo gls idx ilg ind ky lof log maf mt mtc nav out pg snm synctex.gz synctex tns toc tp vr vrs xdy for j in aux bbl blg cp cps fn glg glo gls idx ilg ind ky lof log maf mt mtc nav out pg snm synctex.gz synctex tns toc tp vr vrs xdy
do do
echo "$DIRNAME/$BASENAME.$j" echo "$DIRNAME/$BASENAME.$j"
done) 2>/dev/null done) 2>/dev/null
done <<EOF done <<EOF
$(find "$i" -type f \( -name "*.tex" -o -name "*.texi" \) ) $(find "$i" -type f \( -name "*.tex" -o -name "*.texi" \) )
EOF EOF
done done

View File

@ -4,17 +4,17 @@
## Note: '%s/@/\\/g' needs to be last. ## Note: '%s/@/\\/g' needs to be last.
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} FILES Usage: ${0##*/} FILES
Convert texinfo files to LaTeX. Convert texinfo files to LaTeX.
EOF EOF
exit exit
fi fi
for i; do for i; do
ex - "$i" <<'EOF' >/dev/null ex - "$i" <<'EOF' >/dev/null
g/^@node/d g/^@node/d
g/@tex/d g/@tex/d
g/@end tex/d g/@end tex/d

View File

@ -2,9 +2,8 @@
## TODO: support for long texts. ## TODO: support for long texts.
_printhelp () _usage () {
{ cat<<EOF
cat<<EOF
Usage: ${1##*/} [-i source-language] target-language [text] Usage: ${1##*/} [-i source-language] target-language [text]
Translate text from one language to another. The languages are specified using Translate text from one language to another. The languages are specified using
@ -45,97 +44,95 @@ EOF
unset SL unset SL
OPT_LONG=false OPT_LONG=false
while getopts ":hi:l" opt; do while getopts ":hi:l" opt; do
case $opt in case $opt in
h) h)
_printhelp "$0" _usage "$0"
exit 1 exit 1
;; ;;
i) i)
SL="$OPTARG" ;; SL="$OPTARG" ;;
l) l)
OPT_LONG=true ;; OPT_LONG=true ;;
?) \?)
_printhelp "$0" _usage "$0"
exit 1 exit 1
;; ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
_printhelp "$0" _usage "$0"
exit 1 exit 1
fi fi
TL=$1 TL=$1
shift shift
_filter() _filter () {
{ if ! $OPT_LONG; then
if ! $OPT_LONG; then sed -e 's/\[\[\["\([^"]*\).*/\1/' -e 's/"//g'
sed -e 's/\[\[\["\([^"]*\).*/\1/' -e 's/"//g' echo
echo return
return fi
fi
if command -v jshon >/dev/null 2>&1; then if command -v jshon >/dev/null 2>&1; then
## Input may have empty fields, which is not normally allowed in ## Input may have empty fields, which is not normally allowed in
## json. Let's fix this. ## json. Let's fix this.
input="$(sed -e 's/,\+/,/g' -e 's/\[,\+/\[/g' -e 's/,\+\]/\]/g')" input="$(sed -e 's/,\+/,/g' -e 's/\[,\+/\[/g' -e 's/,\+\]/\]/g')"
## The use of jshon without checking the array size is unsafe. If the ## 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 ## size is not as expected, it probably means that source and target
## languages are the same. Anyhow, we drop the error output. ## languages are the same. Anyhow, we drop the error output.
## Google Translate does not have the same structure when English is ## Google Translate does not have the same structure when English is
## involved. With English, the list of translations is in cell 1, ## involved. With English, the list of translations is in cell 1,
## whitout English it is in cell 3. Without English, there is no ## whitout English it is in cell 3. Without English, there is no
## distinction on grammatical type. ## distinction on grammatical type.
if [ "$(echo "$input" | jshon -e 1 -t)" = "string" ]; then if [ "$(echo "$input" | jshon -e 1 -t)" = "string" ]; then
## No English ## No English
echo "$input" | jshon -e 3 -e 0 -e 2 -a -e 0 -u | tr '\n' ',' | sed 's/,$/\n/' echo "$input" | jshon -e 3 -e 0 -e 2 -a -e 0 -u | tr '\n' ',' | sed 's/,$/\n/'
else else
count=0 count=0
## Fetch grammatical type in 'type'. ## Fetch grammatical type in 'type'.
while read -r type; do while read -r type; do
echo -n $type: echo -n $type:
## Fetch translation alternative from count-th entry ## Fetch translation alternative from count-th entry
echo "$input" | jshon -e 1 -e $count -e 1 -a -u | tr '\n' ',' | sed 's/,$/\n/' echo "$input" | jshon -e 1 -e $count -e 1 -a -u | tr '\n' ',' | sed 's/,$/\n/'
count=$(($count+1)) count=$(($count+1))
done<<EOF done<<EOF
$(echo "$input" | jshon -e 1 -a -e 0 -u) $(echo "$input" | jshon -e 1 -a -e 0 -u)
EOF EOF
fi 2>/dev/null fi 2>/dev/null
else else
## Use sed to fetch first entry only. ## Use sed to fetch first entry only.
sed -e 's/\[\[\[[^[]*\[\[[^[]*\[\([^[]*\)\].*/\1/' -e 's/"//g' sed -e 's/\[\[\[[^[]*\[\[[^[]*\[\([^[]*\)\].*/\1/' -e 's/"//g'
echo echo
fi fi
} }
_translate() _translate () {
{ TEXT="$(tr '\n' ' ' | sed 's/[\t ]\+/%20/g')"
TEXT="$(tr '\n' ' ' | sed 's/[\t ]\+/%20/g')" ## If input is not a single word, disable alternative translations. We use a
## 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.
## point in the grep string to ignore any space at the end. [ -n "$(echo $TEXT | grep '%20.')" ] && OPT_LONG=false
[ -n "$(echo $TEXT | grep '%20.')" ] && OPT_LONG=false
if [ "$SL" = "" ]; then 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' 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 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' 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 fi 2>/dev/null | _filter
} }
if [ $# -ne 0 ]; then if [ $# -ne 0 ]; then
echo "$@" | _translate echo "$@" | _translate
else else
_translate _translate
fi fi
## Original command: ## Original command:

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
if [ "$1" = "-h" ]; then if [ "$1" = "-h" ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} [OPTIONS] Usage: ${0##*/} [OPTIONS]
With no argument, start transmission-remote-cli. Otherwise, run With no argument, start transmission-remote-cli. Otherwise, run
@ -11,28 +11,27 @@ In both cases if transmission-daemon is not running it will be started
beforehand. beforehand.
EOF EOF
exit exit
fi fi
check() check () {
{ for i ; do
for i ; do if ! command -v $i >/dev/null 2>&1; then
if ! command -v $i >/dev/null 2>&1; then echo >&2 "'$i' not found in PATH. Exiting."
echo >&2 "'$i' not found in PATH. Exiting." exit 1
exit 1 fi
fi done
done
} }
check transmission-daemon transmission-remote-cli check transmission-daemon transmission-remote-cli
[ $(ps -U $USER | grep -c transmission-da) -eq 0 ] && transmission-daemon [ $(ps -U $USER | grep -c transmission-da) -eq 0 ] && transmission-daemon
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
exec transmission-remote-cli exec transmission-remote-cli
else else
## The 'sleep' is needed here to give the daemon some time to start. 1 sec ## The 'sleep' is needed here to give the daemon some time to start. 1 sec
## should be enough on most system. ## should be enough on most system.
sleep 1 sleep 1
transmission-remote "$@" transmission-remote "$@"
fi fi

View File

@ -1,12 +1,12 @@
#!/bin/sh #!/bin/sh
if [ $# -ne 2 ]; then if [ $# -ne 2 ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} EXT URI Usage: ${0##*/} EXT URI
Batch download recursively files with extension EXT located at URI. Batch download recursively files with extension EXT located at URI.
EOF EOF
exit exit
fi fi
wget -r -l1 --no-parent -A"$1" "$2" wget -r -l1 --no-parent -A"$1" "$2"

View File

@ -1,26 +1,25 @@
#!/bin/sh #!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} WIN32EXE PARAMS" Usage: ${0##*/} WIN32EXE PARAMS"
Run Wine application while displaying FPS onscreen. Run Wine application while displaying FPS onscreen.
EOF EOF
exit exit
fi fi
if ! command -v osd_cat >/dev/null; then if ! command -v osd_cat >/dev/null; then
echo "You need osd_cat." echo "You need osd_cat."
exit exit
fi fi
## The unbuffered option is -u on GNU and OpenBSD, -l on others. ## The unbuffered option is -u on GNU and OpenBSD, -l on others.
OPT_UNBUF=-l OPT_UNBUF=-l
if [ "$(uname)" = "Linux" ] || [ "$(uname)" = "OpenBSD" ]; then if [ "$(uname)" = "Linux" ] || [ "$(uname)" = "OpenBSD" ]; then
OPT_UNBUF=-u OPT_UNBUF=-u
fi fi
WINEDEBUG=fps wine "$@" 2>&1 | tee /dev/stderr | \ WINEDEBUG=fps wine "$@" 2>&1 | tee /dev/stderr | \
sed $OPT_UNBUF -n '/^trace:fps:/{s/.* \([^ ]*\)fps/\1/;p}' | \ sed $OPT_UNBUF -n '/^trace:fps:/{s/.* \([^ ]*\)fps/\1/;p}' | \
osd_cat -l1 -f "-*-*-*-*-*-*-32-*-*-*-*-*-*-*" -O1 -c "yellow" osd_cat -l1 -f "-*-*-*-*-*-*-32-*-*-*-*-*-*-*" -O1 -c "yellow"

View File

@ -3,8 +3,8 @@
## browsers to start shell in pointed folder. ## browsers to start shell in pointed folder.
if [ ! -d "$1" ]; then if [ ! -d "$1" ]; then
zsh zsh
exit exit
fi fi
## Default files. ## Default files.
@ -12,30 +12,30 @@ ZDIRS="$HOME/.cache/zsh/dirs"
## Fetch file location dynamically. ## Fetch file location dynamically.
if [ ! -f ~/.zshrc ]; then if [ ! -f ~/.zshrc ]; then
echo '~/.zshrc not found. Exiting.' echo '~/.zshrc not found. Exiting.'
exit 1 exit 1
fi fi
## We need realpath to prevent us from adding duplicates to the zsh ## We need realpath to prevent us from adding duplicates to the zsh
## DIRSTACKFILE. ## DIRSTACKFILE.
if ! command -v realpath >/dev/null 2>&1; then if ! command -v realpath >/dev/null 2>&1; then
echo "'realpath' not found. Exiting." echo "'realpath' not found. Exiting."
exit 1 exit 1
fi fi
SHELL_DIR_GREP="$(grep "SHELL_DIR=" ~/.zshrc | cut -f2 -d=)" SHELL_DIR_GREP="$(grep "SHELL_DIR=" ~/.zshrc | cut -f2 -d=)"
[ -n "$SHELL_DIR_GREP" ] && SHELL_DIR="$(eval echo "$SHELL_DIR_GREP")" [ -n "$SHELL_DIR_GREP" ] && SHELL_DIR="$(eval echo "$SHELL_DIR_GREP")"
if [ ! -d "$SHELL_DIR" ]; then if [ ! -d "$SHELL_DIR" ]; then
echo 'SHELL_DIR not found. Could not search for DIRSTACKFILE. Exiting.' echo 'SHELL_DIR not found. Could not search for DIRSTACKFILE. Exiting.'
exit 1 exit 1
fi fi
ZDIRS_GREP="$(grep -rm1 'DIRSTACKFILE=' "$SHELL_DIR" | cut -f2 -d=)" ZDIRS_GREP="$(grep -rm1 'DIRSTACKFILE=' "$SHELL_DIR" | cut -f2 -d=)"
[ -n "$ZDIRS_GREP" ] && ZDIRS="$(eval echo "$ZDIRS_GREP")" [ -n "$ZDIRS_GREP" ] && ZDIRS="$(eval echo "$ZDIRS_GREP")"
if [ ! -f "$ZDIRS" ]; then if [ ! -f "$ZDIRS" ]; then
echo 'DIRSTACKFILE not found. Exiting.' echo 'DIRSTACKFILE not found. Exiting.'
exit 1 exit 1
fi fi
## Prepend argument to zsh dirstack. ## Prepend argument to zsh dirstack.