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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
#!/bin/sh
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
cat <<EOF
cat <<EOF
Usage: ${0##*/} [FILES]
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.
EOF
exit
exit
fi
unset OPT
if [ "$1" = "-i" ]; then
OPT=-i
shift
OPT=-i
shift
fi
## 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
## call. Besides, ex does not support multiple file editing.
sed $OPT \
-e 's/[áàâä]/a/g' \
-e 's/[éèêë]/e/g' \
-e 's/[íìîï]/i/g' \
-e 's/[óòôö]/o/g' \
-e 's/[úùûü]/u/g' \
-e 's/[ýỳŷÿ]/y/g' \
-e 's/[ÁÀÂÄ]/A/g' \
-e 's/[ÉÈÊË]/E/g' \
-e 's/[ÍÌÎÏ]/I/g' \
-e 's/[ÓÒÔÖ]/O/g' \
-e 's/[ÚÙÛÜ]/U/g' \
-e 's/[ÝỲŶŸ]/Y/g' \
-e 's/[ñ]/n/g' \
-e 's/[œ]/oe/g' \
-e 's/[Œ]/Oe/g' \
-e 's/[æ]/ae/g' \
-e 's/[Æ]/Ae/g' \
-e 's/[ç]/c/g' \
-e 's/[Ç]/C/g' \
-e 's/[ß]/ss/g' \
-e 's/[«»„“”‚‘’]/"/g' \
-e 's/[©]/(C)/g' \
-e 's/[®]/(R)/g' \
-e 's/[™]/(TM)/g' \
-e 's/[¥]/Y/g' \
-e 's/[Ð]/D/g' \
-e 's/[ŀ]/l/g' \
-e 's/[Ŀ]/L/g' \
-e 's/[€]/euro/g' \
-e 's/[¢]/cent/g' \
-e 's/[£]/pound/g' \
-e 's/[µ]/mu/g' \
-e 's/[²]/^2/g' \
-e 's/[³]/^3/g' \
-e 's/[¡]/!/g' \
-e 's/[¿]/?/g' \
-e 's/[]/-/g' \
-e 's/[…]/.../g' \
-e 's/[≤]/<=/g' \
-e 's/[≥]/>=/g' \
-e 's/[±]/+\/-/g' \
-e 's/[≠]/!=/g' \
-e 's/[⋅]/./g' \
-e 's/[×]/x/g' \
-e 's/[÷]/\//g' \
-e 's/[↓]/|/g' \
-e 's/[↑]/^/g' \
-e 's/[←]/<=/g' \
-e 's/[→]/=>/g' \
"$@"
-e 's/[áàâä]/a/g' \
-e 's/[éèêë]/e/g' \
-e 's/[íìîï]/i/g' \
-e 's/[óòôö]/o/g' \
-e 's/[úùûü]/u/g' \
-e 's/[ýỳŷÿ]/y/g' \
-e 's/[ÁÀÂÄ]/A/g' \
-e 's/[ÉÈÊË]/E/g' \
-e 's/[ÍÌÎÏ]/I/g' \
-e 's/[ÓÒÔÖ]/O/g' \
-e 's/[ÚÙÛÜ]/U/g' \
-e 's/[ÝỲŶŸ]/Y/g' \
-e 's/[ñ]/n/g' \
-e 's/[œ]/oe/g' \
-e 's/[Œ]/Oe/g' \
-e 's/[æ]/ae/g' \
-e 's/[Æ]/Ae/g' \
-e 's/[ç]/c/g' \
-e 's/[Ç]/C/g' \
-e 's/[ß]/ss/g' \
-e 's/[«»„“”‚‘’]/"/g' \
-e 's/[©]/(C)/g' \
-e 's/[®]/(R)/g' \
-e 's/[™]/(TM)/g' \
-e 's/[¥]/Y/g' \
-e 's/[Ð]/D/g' \
-e 's/[ŀ]/l/g' \
-e 's/[Ŀ]/L/g' \
-e 's/[€]/euro/g' \
-e 's/[¢]/cent/g' \
-e 's/[£]/pound/g' \
-e 's/[µ]/mu/g' \
-e 's/[²]/^2/g' \
-e 's/[³]/^3/g' \
-e 's/[¡]/!/g' \
-e 's/[¿]/?/g' \
-e 's/[]/-/g' \
-e 's/[…]/.../g' \
-e 's/[≤]/<=/g' \
-e 's/[≥]/>=/g' \
-e 's/[±]/+\/-/g' \
-e 's/[≠]/!=/g' \
-e 's/[⋅]/./g' \
-e 's/[×]/x/g' \
-e 's/[÷]/\//g' \
-e 's/[↓]/|/g' \
-e 's/[↑]/^/g' \
-e 's/[←]/<=/g' \
-e 's/[→]/=>/g' \
"$@"

View File

@ -1,7 +1,7 @@
#!/usr/bin/env zsh
if [ $# -gt 2 ] || [ $# -lt 1 ] || [ "$1" = "-h" ]; then
cat <<EOF
cat <<EOF
Usage: ${0##*/} FILE [STRING]
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.
EOF
exit
exit
fi
FILE="$1"
@ -23,7 +23,7 @@ STRING=""
DUMMY=""
if [ $# -eq 2 ]; then
STRING="$2"
STRING="$2"
fi
echo -n "Secret: "
@ -31,15 +31,15 @@ read -s DUMMY
echo ""
if [ ! -e "$FILE" ] || [ -z "$STRING" ]; then
echo "$DUMMY" >> "$FILE"
echo "Secret appended to ${FILE} at the end."
exit
echo "$DUMMY" >> "$FILE"
echo "Secret appended to ${FILE} at the end."
exit
fi
if [ $# -eq 1 ]; then
echo "$DUMMY" >> "$FILE"
echo "$DUMMY" >> "$FILE"
else
ex -sc "%s/${STRING}/${STRING}${DUMMY}/g|xit" "${FILE}"
ex -sc "%s/${STRING}/${STRING}${DUMMY}/g|xit" "${FILE}"
fi
echo "Secret appended to ${FILE}."

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,12 +1,12 @@
#!/bin/sh
if [ $# -lt 1 ]; then
cat<<EOF
cat<<EOF
Usage: ${0##*/} FILE [FLAGS]
Simulate a C interpreter by compiling, executing and removing file in one run.
EOF
exit
exit
fi
[ -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.
BEGIN {
FS=","
ind=1
FS=","
ind=1
}
## Some fields are surrounded by unwanted double quotes.
function remove_quotes(s)
{
gsub(/^"+|"+$/, "", s)
return s
function remove_quotes(s) {
gsub(/^"+|"+$/, "", s)
return s
}
function capitalize(s)
{
result = ""
while(match(s,/[ -]/))
{
word = substr(s,1,RSTART-1)
result = result toupper(substr(word,1,1)) tolower(substr(word,2))
if(index(s,"-"))
result = result "-"
else
result = result " "
s = substr(s,RSTART+1)
}
result = result toupper(substr(s,1,1)) tolower(substr(s,2))
return result
function capitalize(s) {
result = ""
while(match(s,/[ -]/))
{
word = substr(s,1,RSTART-1)
result = result toupper(substr(word,1,1)) tolower(substr(word,2))
if(index(s,"-"))
result = result "-"
else
result = result " "
s = substr(s,RSTART+1)
}
result = result toupper(substr(s,1,1)) tolower(substr(s,2))
return result
}
## Let's skip the first line which is supposed to contain the CSV header.
FNR==1 {
next
next
}
{
print "[" ind "]"
print "name=" capitalize(remove_quotes($2)) " " capitalize(remove_quotes($4))
printf "email=" tolower(remove_quotes($29))
if ($31 != "")
printf "," remove_quotes($31)
if ($33 != "")
printf "," remove_quotes($33)
printf "\n"
print "[" ind "]"
print "name=" capitalize(remove_quotes($2)) " " capitalize(remove_quotes($4))
printf "email=" tolower(remove_quotes($29))
if ($31 != "")
printf "," remove_quotes($31)
if ($33 != "")
printf "," remove_quotes($33)
printf "\n"
print "birthday=" remove_quotes($15)
print "mobile=" remove_quotes($35)
print "phone=" remove_quotes($37)
print "address=" remove_quotes($39)
print ""
ind++
print "birthday=" remove_quotes($15)
print "mobile=" remove_quotes($35)
print "phone=" remove_quotes($37)
print "address=" remove_quotes($39)
print ""
ind++
}

View File

@ -1,17 +1,15 @@
#!/bin/sh
if [ $# -ne 3 ] || [ "$1" = "-h" ]; then
cat <<EOF
cat <<EOF
Usage: ${0##*/} VALUE IN-CURRENCY OUT-CURRENCY
Convert VALUE from IN-CURRENCY to OUT-CURRENCY.
CURRENCY is a 3-letters code like EUR, SEK, USD, etc.
EOF
exit
exit
fi
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
_printhelp ()
{
cat<<EOF
_usage () {
cat<<EOF
Usage: ${1##*/} [OPTIONS] [FILES]
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_INPLACE=""
while getopts ":fhin:" opt; do
case $opt in
f)
OPT_CUTFIRST=true ;;
h)
_printhelp "$0"
exit 1 ;;
i)
OPT_INPLACE="-i" ;;
n)
OPT_LINES=$OPTARG ;;
?)
_printhelp "$0"
exit 1 ;;
esac
case $opt in
f)
OPT_CUTFIRST=true ;;
h)
_usage "$0"
exit 1 ;;
i)
OPT_INPLACE="-i" ;;
n)
OPT_LINES=$OPTARG ;;
\?)
_usage "$0"
exit 1 ;;
esac
done
shift $(($OPTIND - 1))
if $OPT_CUTFIRST; then
sed $OPT_INPLACE -n "1,${OPT_LINES}!p" "$@"
sed $OPT_INPLACE -n "1,${OPT_LINES}!p" "$@"
else
echo CUTLAST
sed $OPT_INPLACE -n ":begin ; 1,${OPT_LINES}!{P;N;D}; N; b begin" "$@"
echo CUTLAST
sed $OPT_INPLACE -n ":begin ; 1,${OPT_LINES}!{P;N;D}; N; b begin" "$@"
fi

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
#!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat<<EOF
cat<<EOF
Usage: ${0##*/} [OPTIONS] FILES
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.
EOF
exit
exit
fi
## 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}'
if [ "$1" = "-p" ]; then
PACKAGES="\usepackage{$2}"
shift 2
PACKAGES="\usepackage{$2}"
shift 2
fi
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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,9 +9,8 @@
# -dGraphicsAlphaBits=4
# -dMaxStripSize=8192
_printhelp ()
{
cat <<EOF
_usage () {
cat <<EOF
Usage: ${1##*/} [OPTIONS] PDFFILES
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"
while getopts ":cfhin" opt; do
case $opt in
c)
OPT_COMPRESSION="" ;;
f)
OPT_OVERWRITE=true ;;
h)
_printhelp "$0"
exit 1 ;;
i)
OPT_INPLACE=true ;;
n)
OPT_COMPRESSION="-dColorConversionStrategy=/LeaveColorUnchanged -dEncodeColorImages=false -dEncodeGrayImages=false -dEncodeMonoImages=false" ;;
?)
_printhelp "$0"
exit 1 ;;
esac
case $opt in
c)
OPT_COMPRESSION="" ;;
f)
OPT_OVERWRITE=true ;;
h)
_usage "$0"
exit 1 ;;
i)
OPT_INPLACE=true ;;
n)
OPT_COMPRESSION="-dColorConversionStrategy=/LeaveColorUnchanged -dEncodeColorImages=false -dEncodeGrayImages=false -dEncodeMonoImages=false" ;;
\?)
_usage "$0"
exit 1 ;;
esac
done
shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then
_printhelp "$0"
exit 1
_usage "$0"
exit 1
fi
for i ; do
if [ ! -f "$i" ]; then
echo "$i is not a valid file."
continue
fi
if [ ! -f "$i" ]; then
echo "$i is not a valid file."
continue
fi
case "$i" in
*/*) ;;
*) i="./$i" ;;
esac
DIRNAME="${i%/*}"
BASENAME="${i##*/}"
EXTNAME="${BASENAME##*.}"
BASENAME="${BASENAME%.*}"
OUTPUT="$DIRNAME/$BASENAME-compressed.pdf"
if [ -e "$OUTPUT" ] && ! $OPT_OVERWRITE; then
echo "$OUTPUT alredy present. Skipping."
continue
fi
case "$i" in
*/*) ;;
*) i="./$i" ;;
esac
DIRNAME="${i%/*}"
BASENAME="${i##*/}"
EXTNAME="${BASENAME##*.}"
BASENAME="${BASENAME%.*}"
OUTPUT="$DIRNAME/$BASENAME-compressed.pdf"
if [ -e "$OUTPUT" ] && ! $OPT_OVERWRITE; then
echo "$OUTPUT alredy present. Skipping."
continue
fi
echo "$i"
echo "$i"
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite $OPT_COMPRESSION -sOutputFile="$OUTPUT" "$i"
if $OPT_INPLACE; then
rm -f "$i"
mv "$OUTPUT" "$i"
fi
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite $OPT_COMPRESSION -sOutputFile="$OUTPUT" "$i"
if $OPT_INPLACE; then
rm -f "$i"
mv "$OUTPUT" "$i"
fi
done

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
#!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat <<EOF
cat <<EOF
Usage: ${0##*/} [OPTIONS] STRING [FILES]
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.
EOF
exit
exit
fi
unset OPT
if [ "$1" = "-i" ]; then
OPT=-i
shift
OPT=-i
shift
fi
VAR="$1"

View File

@ -1,7 +1,7 @@
#!/bin/sh
if [ "$#" -eq 0 ] || [ "$1" = "-h" ]; then
cat<<EOF
cat<<EOF
Usage: ${1##*/} 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.
EOF
exit
exit
fi
if [ $# -gt 1 ]; then
ffprobe -v quiet -print_format flat=s=_ -show_entries "$@"
ffprobe -v quiet -print_format flat=s=_ -show_entries "$@"
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

View File

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

View File

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

View File

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

View File

@ -1,14 +1,14 @@
#!/bin/sh
if [ $# -ne 2 ] || [ "$1" = "-h" ] ; then
cat<<EOF
cat<<EOF
Usage: ${1##*/} FILE1 FILE2
Swap 2 filenames around.
EOF
exit
exit
fi
## 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")"
case "$1" in
*/*) DIR1="${1%/*}" ;;
*) DIR1="." ;;
*/*) DIR1="${1%/*}" ;;
*) DIR1="." ;;
esac
case "$2" in
*/*) DIR2="${2%/*}" ;;
*) DIR2="." ;;
*/*) DIR2="${2%/*}" ;;
*) DIR2="." ;;
esac
if ! mv -n "$1" "$TEMPFILE"; then
echo >&2 "Race condition, exiting. Try again."
echo >&2 "Race condition, exiting. Try again."
fi
mv -n "$2" "$DIR2/${1##*/}"
mv -n "$TEMPFILE" "$DIR1/${2##*/}"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,9 +2,8 @@
OUTPUT_NAME="tc-video"
_printhelp()
{
cat <<EOF
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat <<EOF
Usage: ${1##*/} [FILES]
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.
EOF
}
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
_printhelp "$0"
exit
exit
fi
_escname () {
echo "$@" | sed 's|/|\\/|g'
echo "$@" | sed 's|/|\\/|g'
}
SCRIPT_PATH="${0%/*}"
SCRIPT_NAME="${0##*/}"
FILELIST=""
if [ -f "$SCRIPT_PATH/.$SCRIPT_NAME.in" ]; then
cp -i "$SCRIPT_PATH/.$SCRIPT_NAME.in" "$OUTPUT_NAME"
for i ; do
esci="$(_escname "$i")"
FILELIST="${FILELIST:+$FILELIST -i }'$esci'"
ex -sc "%s/###FILENAMES/'$esci' ###FILENAMES/ | xit" "$OUTPUT_NAME"
done
ex -sc '%s/###FILELIST/'"$FILELIST"'/ | xit' "$OUTPUT_NAME"
chmod +x "$OUTPUT_NAME"
cp -i "$SCRIPT_PATH/.$SCRIPT_NAME.in" "$OUTPUT_NAME"
for i ; do
esci="$(_escname "$i")"
FILELIST="${FILELIST:+$FILELIST -i }'$esci'"
ex -sc "%s/###FILENAMES/'$esci' ###FILENAMES/ | xit" "$OUTPUT_NAME"
done
ex -sc '%s/###FILELIST/'"$FILELIST"'/ | xit' "$OUTPUT_NAME"
chmod +x "$OUTPUT_NAME"
else
echo ".$SCRIPT_NAME.in not found!"
echo ".$SCRIPT_NAME.in not found!"
fi

View File

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

View File

@ -1,7 +1,7 @@
#!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat <<EOF
cat <<EOF
Usage: ${0##*/} FOLDERS
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.
EOF
exit
exit
fi
for i ; do
while read -r FILE; do
case FILE in
*/*) ;;
*)
FILE="./$FILE" ;;
esac
DIRNAME="${FILE%/*}"
BASENAME="${FILE##*/}"
BASENAME="${BASENAME%.*}"
rm -v $(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
echo "$DIRNAME/$BASENAME.$j"
done) 2>/dev/null
done <<EOF
while read -r FILE; do
case FILE in
*/*) ;;
*)
FILE="./$FILE" ;;
esac
DIRNAME="${FILE%/*}"
BASENAME="${FILE##*/}"
BASENAME="${BASENAME%.*}"
rm -v $(
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
echo "$DIRNAME/$BASENAME.$j"
done) 2>/dev/null
done <<EOF
$(find "$i" -type f \( -name "*.tex" -o -name "*.texi" \) )
EOF
done

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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