# Written by Luca Saiu. I, Luca Saiu, hereby place this file into the
# public domain.
#echo "This is ~luca/.bashrc: BEGIN"
if ! ps -a -u "$USER" | grep -q gpg-agent; then
true
gpg-agent --daemon --enable-ssh-support --write-env-file "${HOME}/.gpg-agent-info" &> /dev/null
if test -e "${HOME}/.gpg-agent-info"; then
source "${HOME}/.gpg-agent-info"
fi
export GPG_TTY=$(tty)
fi
HOSTNAME="$(hostname)"
function add-prefix {
partial="no"
case "$#" in
1) prefix="$1";;
2) prefix="$1"
if [[ "$2" == "partial" ]]; then
partial="yes"
else
echo "$0: the second argument, if specified, must be \"partial\"."
return -1
fi;;
*) echo "$0: either one argument (the prefix path) or two: prefix path, \"partial\"."
return -1;;
esac
case "$HOSTNAME" in
sussman)
TRIPLET="mipsel-linux-gnu"
;;
abelson | moore)
TRIPLET="x86_64-linux-gnu"
;;
knuth)
TRIPLET="powerpc-linux-gnu"
;;
*)
# Let's hope this exactly matches the fucking multilib paths
TRIPLET="$(uname --machine)-linux-gnu"
;;
esac
# Let's hope $PATH is already defined...
export PATH="$prefix/sbin:$prefix/bin:$PATH"
# FIXME: is the order correct?
export PATH="$prefix/libexec:$PATH"
if [[ "$partial" != "yes" ]]; then
if [[ "$LIBRARY_PATH" == "" ]]; then
export LIBRARY_PATH="/lib/$TRIPLET:/lib:/usr/local/lib/$TRIPLET:/usr/local/lib:/usr/lib/$TRIPLET:/usr/lib:/usr/X11R6/lib:/lib64:/usr/local/lib64:/usr/lib64:/usr/X11R6/lib64"
fi
export LIBRARY_PATH="$prefix/lib/$TRIPLET:$prefix/lib:$prefix/lib64:$LIBRARY_PATH"
if [[ "$LD_LIBRARY_PATH" == "" ]]; then
export LD_LIBRARY_PATH="/lib/$TRIPLET:/lib:/usr/local/lib/$TRIPLET:/usr/local/lib:/usr/lib/$TRIPLET:/usr/lib:/usr/X11R6/lib:/lib64:/usr/local/lib64:/usr/lib64:/usr/X11R6/lib64"
#export LD_LIBRARY_PATH="/lib:/usr/local/lib:/usr/lib:/usr/X11R6/lib:/lib64:/usr/local/lib64:/usr/lib64:/usr/X11R6/lib64:/lib/mipsel-linux-gnu"
fi
export LD_LIBRARY_PATH="$prefix/lib/$TRIPLET:$prefix/lib:$prefix/lib64:$LD_LIBRARY_PATH"
fi
if [[ "$MANPATH" == "" ]]; then
export MANPATH="/usr/local/man:/usr/local/share/man:/usr/man:/usr/share/man:/usr/X11R6/man:/usr/X11R6/share/man"
fi
export MANPATH="$prefix/man:$prefix/share/man:$MANPATH"
if [[ "$INFOPATH" == "" ]]; then
export INFOPATH="/usr/local/info:/usr/local/share/info:/usr/info:/usr/share/info:/usr/X11R6/info:/usr/X11R6/share/info"
fi
export INFOPATH="$prefix/info:$prefix/share/info:$INFOPATH"
if [[ "$partial" != "yes" ]]; then
if [[ "$CPATH" == "" ]]; then
export CPATH="/usr/local/include/$TRIPLET:/usr/local/include:/usr/include/$TRIPLET:/usr/include:/usr/X11R6/include:/usr/include/X11"
#export CPATH="/usr/local/include:/usr/include:/usr/X11R6/include:/usr/include/X11"
fi
export CPATH="$prefix/include/$TRIPLET:$prefix/include:$CPATH"
if [[ "$C_INCLUDE_PATH" == "" ]]; then
export C_INCLUDE_PATH="/usr/local/include/$TRIPLET:/usr/local/include:/usr/include/$TRIPLET:/usr/include:/usr/X11R6/include:/usr/include/X11"
fi
export C_INCLUDE_PATH="$prefix/include/$TRIPLET:$prefix/include:$C_INCLUDE_PATH"
if [[ "$CPLUS_INCLUDE_PATH" == "" ]]; then
CPLUS_INCLUDE_PATH="/usr/local/include/$TRIPLET:/usr/local/include:/usr/include/$TRIPLET:/usr/include:/usr/X11R6/include:/usr/include/X11"
#export CPLUS_INCLUDE_PATH="/usr/local/include:/usr/include:/usr/X11R6/include:/usr/include/X11"
fi
export CPLUS_INCLUDE_PATH="$prefix/include/$TRIPLET:$prefix/include:$CPLUS_INCLUDE_PATH"
if [[ "$OBJC_INCLUDE_PATH" == "" ]]; then
export OBJC_INCLUDE_PATH="/usr/local/include/$TRIPLET:/usr/local/include:/usr/include/$TRIPLET:/usr/include:/usr/X11R6/include:/usr/include/X11"
#export OBJC_INCLUDE_PATH="/usr/local/include:/usr/include:/usr/X11R6/include:/usr/include/X11"
fi
export OBJC_INCLUDE_PATH="$prefix/include/$TRIPLET:$prefix/include:$OBJC_INCLUDE_PATH"
if [[ "$PKG_CONFIG_PATH" == "" ]]; then
export PKG_CONFIG_PATH=/usr/local/share/pkgconfig:/usr/share/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig
fi
export PKG_CONFIG_PATH="$prefix/share/pkgconfig:$prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
fi
# if [[ $ACLOCAL_FLAGS == "" ]]; then
# if [ -d /usr/share/aclocal ]; then
# export ACLOCAL_FLAGS="-I /usr/share/aclocal $ACLOCAL_FLAGS"
# fi
# if [ -d /usr/local/share/aclocal ]; then
# export ACLOCAL_FLAGS="-I /usr/local/share/aclocal $ACLOCAL_FLAGS"
# fi
# fi
mkdir "$prefix/share/aclocal" 2> /dev/null || true
# # FIXME: this was almost certainly a mistake. --2017-10-18
# # export ACLOCAL_FLAGS="-I $prefix/share/aclocal/ -I /usr/share/aclocal/"
# export ACLOCAL_FLAGS="-I $prefix/share/aclocal/ -I $ACLOCAL_FLAGS"
if [[ $ACLOCAL_PATH == "" ]]; then
if [ -d /usr/share/aclocal ]; then
export ACLOCAL_PATH="/usr/share/aclocal"
fi
if [ -d /usr/local/share/aclocal ]; then
export ACLOCAL_PATH="/usr/local/share/aclocal:$ACLOCAL_PATH"
fi
fi
export ACLOCAL_PATH="$prefix/share/aclocal:$ACLOCAL_PATH"
}
function my {
(add-prefix ~/usr-mplayer; mplayer "$(yturl $@)")
}
function myl {
mplayer "$(yturl -q low $@)"
}
function mym {
mplayer "$(yturl -q medium $@)"
}
function myh {
mplayer "$(yturl -q high $@)"
}
#[ -f /etc/profile ] && . /etc/profile
alias ls='ls -XFs --color'
function mkdircd {
if [[ $# != 1 ]]; then
echo "mkdircd: there must be exactly one parameter"
false
else
mkdir -p -- "$1"
cd -- "$1"
fi
}
# Define some useful sequences for ANSI terminals:
#export ESC=\\033
export ESC=$(echo -e '\033')
export BEL=$(echo -e '\007')
export BLACK=$ESC[0m$ESC[30m
export BLUE=$ESC[0m$ESC[34m
export GREEN=$ESC[0m$ESC[32m
export CYAN=$ESC[0m$ESC[36m
export RED=$ESC[0m$ESC[31m
export MAGENTA=$ESC[0m$ESC[35m
export BROWN=$ESC[0m$ESC[33m
export LIGHTGRAY=$ESC[0m$ESC[37m
export DARKGRAY=$ESC[1m$ESC[30m
export LIGHTBLUE=$ESC[1m$ESC[34m
export LIGHTGREEN=$ESC[1m$ESC[32m
export LIGHTCYAN=$ESC[1m$ESC[36m
export LIGHTRED=$ESC[1m$ESC[31m
export LIGHTMAGENTA=$ESC[1m$ESC[35m
export YELLOW=$ESC[1m$ESC[33m
export WHITE=$ESC[1m$ESC[37m
# For compatibility with my older scripts.
export LIGHTPURPLE=$LIGHTMAGENTA
export PURPLE=$MAGENTA
export NOATTR=$ESC[0m
export BOLD=$ESC[1m
export FAINT=$ESC[2m
export ITALIC=$ESC[3m
export CROSSOUT=$ESC[9m
export UNDERLINE=$ESC[4m
export REVERSE=$ESC[7m
# Depending on the terminal BLINK could brighten the background
export SLOWBLINK=$ESC[5m
# Unsupported on all the terminals I've tried:
export FASTBLINK=$ESC[6m
export FRAME=$ESC[51m
export ENCIRCLE=$ESC[52m
export OVERLINE=$ESC[53m
export CLEAR=$ESC[2J
export TOPLEFT=$ESC[1\;1H
# This is for setting the title of an Xterm window:
export BEGINTITLE="${ESC}]0;"
export ENDTITLE="${BEL}"
# Default prompt:
PROMPTCOLOR=$LIGHTPURPLE
NONPROMPTCOLOR=$GREEN
# Custom promts for important users, who must be easy to recognize:
case "$USER" in
root)
PROMPTCOLOR=$YELLOW
# NONPROMPTCOLOR=$LIGHTCYAN
##NONPROMPTCOLOR=$GREEN
NONPROMPTCOLOR=$LIGHTGRAY
;;
luca | saiu | positron )
# PROMPTCOLOR=$RED
# NONPROMPTCOLOR=$LIGHTGREEN
PROMPTCOLOR=$LIGHTCYAN
# PROMPTCOLOR=$CYAN
NONPROMPTCOLOR=$LIGHTGRAY
# NONPROMPTCOLOR=$BLACK
;;
nobody )
PROMPTCOLOR=$LIGHTCYAN
NONPROMPTCOLOR=$CYAN
;;
*)
PROMPTCOLOR=$LIGHTBLUE
NONPROMPTCOLOR=$PURPLE
;;
esac
MAINBZRUSERHOME=/home/luca
case "$HOSTNAME" in
moore )
HOSTCOLOR=$LIGHTRED$UNDERLINE
PREFIXCOLOR=$GREEN$REVERSE
;;
vm )
# HOSTCOLOR=$LIGHTGREEN
# HOSTCOLOR=$REVERSE$YELLOW
HOSTCOLOR=$REVERSE$LIGHTGREEN
PREFIXCOLOR=$RED$REVERSE
;;
sussman )
#HOSTCOLOR=$REVERSE$WHITE
if [ -e /old-sussman/this-is-the-old-lemote-loonux-installation ]; then
HOSTCOLOR=$LIGHTBLUE
else
HOSTCOLOR=$REVERSE$LIGHTBLUE
fi
PREFIXCOLOR=$GREEN$REVERSE
;;
knuth )
HOSTCOLOR=$YELLOW
PREFIXCOLOR=$BROWN$REVERSE
;;
dijkstra | futamura )
HOSTCOLOR=$GREEN
PREFIXCOLOR=$RED$REVERSE
;;
stallman )
HOSTCOLOR=$LIGHTGREEN
PREFIXCOLOR=$LIGHTRED$REVERSE
;;
chapters )
HOSTCOLOR=$WHITE
PREFIXCOLOR=$CYAN$REVERSE
MAINBZRUSERHOME=/home/positron
;;
fencepost )
HOSTCOLOR=$LIGHTGRAY
PREFIXCOLOR=$CYAN$REVERSE
MAINBZRUSERHOME=/home/p/positron
;;
abelson )
# HOSTCOLOR=$CYAN
HOSTCOLOR=$LIGHTGREEN
PREFIXCOLOR=$LIGHTRED$REVERSE
;;
*)
HOSTCOLOR=$WHITE
PREFIXCOLOR=$GREEN$REVERSE
;;
esac
#export PS1="\[$PROMPTCOLOR\][\u@\h \w]$PROMPTSYGIL \[$NONPROMPTCOLOR\]"
export PS1="\\[$NOATTR$PROMPTCOLOR\\]\\[$NOATTR$PREFIXCOLOR\\]\$PROMPTPREFIX\\[$NOATTR$PROMPTCOLOR\\][\\u@\\[$NOATTR$HOSTCOLOR\\]\\h\\[$NOATTR$PROMPTCOLOR\\] \\w]\\$\\[$NOATTR\\] \\[$NOATTR$NONPROMPTCOLOR\\]"
export LANGUAGE="POSIX"
export LC_ALL="POSIX"
#export EDITOR='emacs -nw'
export EDITOR='emacsclient'
#export MANPATH=/usr/local/man:/usr/local/share/man:/usr/man:/usr/share/man
#. $MAINBZRUSERHOME/repos/stuff/utilities/add-prefix ~/usr &> /dev/null
#export PATH=$HOME/bin:$PATH
# On some old installation I needed something like this, but I don't think that's the case any more. FIXME: check
if ! ( ( echo "$PATH" | grep "$HOME\\/bin:" - &> /dev/null ) || \
( echo "$PATH" | grep ":$HOME\\/bin" - &> /dev/null ) ); then
export PATH="$HOME/bin:$PATH"
fi
add-prefix $HOME/usr
if [[ "$USER" == "root" ]]; then
export HOME="/root"
export PATH="/sbin:/usr/local/libexec:/usr/local/sbin:/usr/sbin:$PATH"
fi
# Suggested by Ulrich Drepper:
alias egrep='egrep --color=tty -d skip'
alias egrpe='egrep --color=tty -d skip'
alias fgrep='fgrep --color=tty -d skip'
alias fgrpe='fgrep --color=tty -d skip'
alias grep='grep --color=tty -d skip'
alias grpe='grep --color=tty -d skip'
# My aliases:
#alias yt='youtube-dl --ignore-errors -tcf5 --restrict-filenames'
alias yt='youtube-dl --ignore-errors -tc --restrict-filenames --external-downloader=curl'
alias ytl='yt --ignore-errors --username=ASDSAD@gmail.com --password=ASDSAD --external-downloader=curl'
alias yu='yturl'
alias grepawaycrap="grep -v svn-base$ | grep -v orig$ | grep -v rej | grep -v \\.svn/ | grep -v testsuite/"
alias findfiles="find -type f | grepawaycrap"
# alias updatesidebar=/var/www/updated-ocaml-sidebar/utils/update-sidebar
# alias dgrep="find . -path '*/_darcs' -prune -o -print0 | xargs -0 egrep"
# alias ocamlgtk='ocaml -I +lablgtk2 lablgtk.cma gtkInit.cmo'
# alias cdk='cd /usr/src/linux-patched'
alias sur='sudo su'
alias dm='sudo dmesg'
alias rs='rsync --progress --inplace'
alias rss="rsync --progress --inplace -e \"ssh -i ${HOME}/.ssh/sussman_rsa\""
alias rsav="rsync --progress --inplace --perms --chmod=a+r -e \"ssh -i ${HOME}/.ssh/sussman_rsa\""
alias sshs="ssh -i ${HOME}/.ssh/sussman_rsa"
# Access Ksamak's machine on a non-standard ssh port.
alias rsk='rsync --progress --inplace -e "ssh -p 1042"'
# alias ocamldocrdf='ocamldoc -g ~/.odoc_rdf/odoc_rdf.cma'
alias tailfn='tail --follow=name --retry'
alias lessr='less -R'
function without_extension
{
echo "$@" | sed --regexp-extended 's/\.[a-zA-Z0-9]+$//'
}
function encode_to_ogg
{
if [[ $# < 2 ]]; then
echo "encode_to_ogg: there must be at least two parameters: options (one string), then file names"
false
else
options="$1"; shift
for filename in "$@"; do
oggfilename="$(without_extension $filename)_.ogg"
ffmpeg2theora \
-o "$oggfilename" \
--title "$oggfilename" \
--novideo --no-skeleton \
$options \
"$filename"
done
fi
}
function encode_low_quality_speech_to_ogg
{
encode_to_ogg "--channels 1 --audioquality -1 --samplerate 8000" "$@"
}
function encode_medium_quality_speech_to_ogg
{
encode_to_ogg "--channels 2 --audioquality -1 --samplerate 16000" "$@"
}
function encode_high_quality_speech_to_ogg
{
encode_to_ogg "--channels 1 --audioquality 0 --samplerate 22050" "$@"
}
function encode_low_quality_music_to_ogg
{
encode_to_ogg "--channels 2 --audioquality -1 --samplerate 16000" "$@"
}
function encode_medium_quality_music_to_ogg
{
encode_to_ogg "--channels 2 --audioquality 2 --samplerate 22050" "$@"
}
function encode_high_quality_music_to_ogg
{
encode_to_ogg "--channels 2 --audioquality 8" "$@"
}
# This works but needs generic arguments for quality options.
function encode_low_quality_speech_to_ogg_to_be_twaked
{
if [[ $# < 2 ]]; then
echo "encode_low_quality_speech_to_ogg_to_be_twaked: there must be exactly two parameters: input, output"
return -1
else
in="$1"
out="$2"
avconv -y -i "${in}" -threads 8 -c:a libvorbis -ac 1 -ar 22050 -b:a 16k -vn "${out}"
fi
}
function raise_volume
{
ffmpeg -y -i "" -vol 1000 ""
}
## I want UTF-8 support even in English, on fast machines:
case "$HOSTNAME" in
moore )
. $MAINBZRUSERHOME/repos/stuff/utilities/set-locale &> /dev/null
;;
esac
function grepsources
{
# I reproduce (yes, twice) *all* grep options rather than just the
# regexp, so that one can choose, for example, case-insensitivity.
grep -n "$@" `find -type f | grepawaycrap` | grep -v ^Binary | grep "$@" -
}
function cpufreq_set_governor
{
export governor="$@"
if sudo -s /bin/bash -c "set -e; for d in /sys/devices/system/cpu/cpu*/cpufreq/; do echo $governor > \$d/scaling_governor; done"; then
notify-send --urgency low --icon battery "cpufreq_set_governor" "The cpufreq scaling governor is now \"$governor\"."
else
notify-send --urgency normal --icon battery "cpufreq_set_governor failed" "Could NOT set the governor to \"$governor\"."
false
fi
}
function cpufreq_get_governor
{
governor="$@"
for d in /sys/devices/system/cpu/cpu*/cpufreq/; do
cat $d/scaling_governor
done
}
export CVS_RSH=ssh
function set_date
{
if `which sudo &> /dev/null`; then
sudo hwclock --set --date "$@"
sudo date --set "$@"
else
hwclock --set --date "$@"
date --set "$@"
fi
}
# Really, really horrible. FIXME: remove $directory if interrupted. Omit job status output
function crash_after_times
{
noncrash_timeout="$1"; shift
times="$1"; shift
command="$@"; shift
echo "command is \"$command\""
for (( i=1; $i <= $times; i++ )); do
echo "Iteration $i of $times:"
directory="$(mktemp -d)"
successfile="$directory/success"
sleep_pid=$!
(bash -c "$command" &> /dev/null && touch "$successfile") &
pid=$!
sleep "$noncrash_timeout"
if kill -0 "$pid" &> /dev/null; then
kill -KILL "$pid" &> /dev/null || true
echo "* iteration $i: still alive after $noncrash_timeout seconds."
rm -rf "$directory"
elif [ -f "$successfile" ]; then
echo "* iteration $i: succeeded before $noncrash_timeout seconds."
rm -rf "$directory"
else
echo "* iteration $i: failed before $noncrash_timeout seconds."
echo "FAILURE (after $i attempts)"
rmdir "$directory"
return 255
fi
# Kill processes named after the first part of the command
# line, up to the first space. Yes, I know, this sucks.
killall $(echo "$command" | awk -F ' ' '{print $1}') &> /dev/null || true
# kill -KILL "$pid" &> /dev/null || true
done
echo "SUCCESS: no crashes before $noncrash_timeout seconds after $times attempts."
return 0
}
function cut_bash_history {
filename=$(mktemp /tmp/tmp-XXXXXXXXXX)
head --lines=-10 ~/.bash_history > "$filename"
mv "$filename" ~/.bash_history
# Destroy the copy, even if some weird failure occurs.
rm -f "$filename" &> /dev/null
}
# Argument: line index, 0-based
function nth_line {
if [[ $# != 1 ]]; then
echo "nth_line: there must be one parameter: the line index, 0-based"
return -1
fi
index=$(("$1" + 1))
cat | head --lines="$index" | tail --lines=1
}
# FIXME: remove this, or redefine as an alias using the new functions below.
function x_first_display_resolution {
xrandr | head --lines=2 | tail --lines=1 | awk '{print $3}' | sed 's/+0+0$//'
}
function x_display_geometries {
xrandr | grep ' connected' | awk '{print $3}'
}
function x_display_resolutions {
x_display_geometries | sed 's/\+.*//g'
}
function x_display_offsets {
x_display_geometries | sed 's/^[^+]*//g'
}
# Argument: display index, 0-based
function x_display_resolution {
x_display_resolutions | nth_line "$@"
}
# Argument: display index, 0-based
function x_display_geometry {
x_display_geometries | nth_line "$@"
}
# Argument: display index, 0-based
function x_display_offset {
x_display_offsets | nth_line "$@"
}
# This works, capturing three streams (one video from the camera, one x11grab, one audio from mic).
# The two video streams can be combined later with the avconv "overlay" filter.
#
# R=15; avconv -y -f v4l2 -r $R -s 640x480 -i /dev/video0 -f x11grab -s `x_first_display_resolution` -r $R -i :0.0 -f alsa -thread_queue_size 512 -i default -ar 22050 -vsync 1 -async 1 -s:0 320x240 -map 0:0 -s:1 480x270 -map 1:0 -map 2:0 -threads 8 /tmp/foo.webm
function ffmpeg_moore_either_camera_options
{
# echo "-i ${videodevice}"
# 15 fps is probably the hardware limit, and I want to record at a slightly
# lower framerate just to allow for some delays; anyway, I probably *don't*
# want to specify -r , at least with ffmpeg -- not sure about avconv: -r
# will determine the value for the output file fps field, which is not
# necessarily the same as the input fps. Not specifying it defaults to a
# high value, which results in duplicate frames (not a problem, I guess)
# but no lag. CPU usage is low, aroung 10% on moore.
# This seems to works well with my logitech usb camera. Not with moore's
# internal camera, where the frame rate drops severly and (I think) the
# audio gets out of sync..
# echo "-s 1280x1024 -i ${videodevice}"
echo "-s 640x480 -i ${videodevice}"
}
function avconv_moore_internal_camera_options
{
# These all work [with avconv ?].
# echo '-r 10 -s 800x600 -i /dev/video0'
echo '-r 15 -s 640x480 -i /dev/video0'
}
function avconv_logitech_camera_options
{
# These all work.
# echo '-r 10 -s 1024x768 -i /dev/video2'
# echo '-r 10 -s 800x600 -i /dev/video2'
echo '-r 15 -s 640x480 -i /dev/video2'
}
function avconv_moore_audio_options
{
# Using the camera mic (-f alsa -i plughw:C920,0) seems to be a
# bad idea: it doesn't have sufficient bandwidth, or I haven't found the correct
# avconv options.
# This is very important for the audio not to overflow the default per-thread buffer.
echo '-thread_queue_size 2048'
# echo '-f alsa -i default -ar 22050'
echo '-f alsa -i default -ar 22050'
# echo '-f alsa -i default -ar 11025'
echo '-vsync 1 -async 1'
}
function avconv_camera_options
{
# avconv_logitech_camera_options
avconv_moore_internal_camera_options
}
if test "$videodevice" = ""; then
videodevice=/dev/video0
fi
videodevice ()
{
if test "$#" != "1"; then
echo "Usage: $0 INDEX"
return -1
fi
device="/dev/video$1"
if ! test -e "$device"; then
echo "$0: nonexisting device $device"
return -1
fi
videodevice="$device"
}
# This encodes on the fly into a format deduced from the output extension
function camera_avconv
{
outputfile="$1"; shift
# avconv -y -vsync 1 -async 1 -f v4l2 `avconv_logitech_camera_options` "$outputfile"
avconv -y -vsync 1 -async 1 -f v4l2 \
`avconv_camera_options` \
`avconv_moore_audio_options` \
"$outputfile"
}
# This seems to work very well, using ~/usr-ffmpeg .
function camera_ffmpeg
{
outputfile="$1"; shift
ffmpeg -nostdin \
-y -vsync 1 -async 1 -f v4l2 \
`ffmpeg_moore_either_camera_options` \
`avconv_moore_audio_options` \
"$@" \
"$outputfile" < /dev/null
}
function camera640_noaudio
{
# The option syntax here is correct:
# mplayer -tv driver=v4l2:input=1:width=768:height=576:device=/dev/video2:audiorate=48000 tv://
outputfile="$1"; shift
mencoder tv:// -tv noaudio:width=640:device=$videodevice -oac lavc -ovc lavc -o "$outputfile"
}
function camera640_audio
{
outputfile="$1"; shift
mencoder tv:// -tv width=640:alsa:forceaudio:device=$videodevice -oac pcm -ovc raw -o "$outputfile"
}
function camera_noaudio
{
outputfile="$1"; shift
# mencoder tv:// -tv fps=24:noaudio:device=$videodevice -oac lavc -ovc lavc -o "$outputfile"
mencoder tv:// -tv noaudio:device=$videodevice -oac lavc -ovc lavc -o "$outputfile"
}
function camera_audio
{
outputfile="$1"; shift
mencoder tv:// -tv alsa:forceaudio:device=$videodevice -oac pcm -ovc raw -o "$outputfile"
}
export mplayerflags
case "$HOSTNAME" in
sussman )
mplayerflags='-vo fbdev -really-quiet -hardframedrop'
;;
esac
export mplayerflagsx2="-vf scale -zoom -xy 2"
function mp
(
if echo $PATH | grep -q usr-mplayer; then
mplayer \
-softvol -softvol-max 6000 -framedrop -quiet \
$mplayerflags \
"$@"
elif [ "$HOSTNAME" = moore ]; then
add-prefix ~luca/usr-mplayer
# Don't use the mplayer from debian I installed in February 2018.
~luca/usr-mplayer/bin/mplayer \
-softvol -softvol-max 600 -quiet \
$mplayerflags \
"$@"
else
mplayer \
-softvol -softvol-max 600 -quiet --hr-seek=always \
$mplayerflags \
"$@"
fi
)
# Temporary crap:
case "$HOSTNAME" in
kronrod )
if [[ "$USER" == "luca" ]]; then
# Scala and the ridiculous Java and Eclipse shit:
export PATH="$HOME/scala/jdk1.7.0_17/bin:$HOME/scala/sbt/bin:$PATH"
# # OPAM:
# add-prefix ~luca/usr-opam
# eval $(opam config env)
# # Isabelle:
# export ISABELLE=/home/luca/projects-by-others/Isabelle2011-1/Isabelle
# export PATH="$PATH:/home/luca/projects-by-others/Isabelle2011-1/bin"
# # Isabelle seems to require a lot of stack space:
# ulimit -s unlimited
# # For crosstool-ng
# unset LIBRARY_PATH
# unset LD_LIBRARY_PATH
# For the VMKit tutorial:
# add-prefix $HOME/vmkit
export PATH=$PATH:"/home/luca/vmkit/vmkit-svn/Release+Asserts/bin/"
fi
;;
esac
# echo I have run your .bashrc
export I_HAVE_RUN_DOTBASHRC="1"
#echo -en $YELLOW
#fortune -a
#echo -en $NOATTR
if [[ "$HOSTNAME" == "sussman" ]]; then
CFLAGS="-g -O2 -march=loongson2f -mtune=loongson2f"
fi
#echo "This is ~luca/.bashrc: END"
# # FIXME: make it general enough
# function encode {
# nice -n 3 mencoder -oac lavc -ovc frameno -o frameno.avi dvd:// && nice -n 3 mencoder -sws 2 -oac copy -ovc lavc dvd:// -o "movie.avi"
# }
alias gpg-get="gpg --keyserver pgp.mit.edu --recv-key"
# I want core dumps
ulimit -c unlimited
# My fancy prompt confuses Trump. Let's simplify locales as well in that case:
if [ "${TERM}" == "dumb" ]; then
PS1='$ '
LANGUAGE=C
LC_ALL=C
unalias ls
fi
# if [[ "$HOSTNAME" == "minsky" ]] || [[ "$HOSTNAME" == "ritchie" ]]; then
# function show
# {
# showfilename=$(mktemp /tmp/tmp-XXXXXXXXXX.png)
# dot -T png "$@" -o "$showfilename"
# display "$showfilename"
# rm "$showfilename"
# }
# else
function show
{
showfilename=$(mktemp /tmp/tmp-XXXXXXXXXX.pdf)
dot -T pdf "$@" -o "$showfilename"
xpdf -z page "$showfilename";
rm "$showfilename"
}
# fi
# function converteverythingtoogg {
# # FIXME: at least some wmv files don't work with this scheme
# for ifile in `find -L -type f -regex '.*\.\(mp4\|mp3\|m4b\|flv\|m4a\|m4v\|wmv\|ogv\|ra\|ogg\)' | grep -v ^./_converted`; do
# ofile="_converted/"$(dirname "$ifile")/$(basename "$ifile" .mp3)"_.ogg"
# mkdir -p $(dirname "$ofile") &> /dev/null || true
# echo "Considering $ifile..."
# if ! [ -s "$ofile" ]; then
# # FIXME: really exit in case of failure
# avconv -y -i "$ifile" -f ogg -vn -acodec libvorbis -ac 1 "$ofile" || (rm "$ofile"; echo "FAILED!"; false)
# echo "Converted $ifile to $ofile"
# else
# echo "$ofile already exists."
# fi
# done
# echo "SUCCESS."
# }
function coreno {
if [[ "$#" != 0 ]]; then
echo "coreno has exactly zero parameters"
return -1
fi
echo $(( $(cat /proc/cpuinfo | grep ^processor | tail --lines=1 | awk '{print $3}') + 1))
}
function converttoogg {
if [[ "$#" != 1 ]]; then
echo "converttoogg should have exactly one parameter"
return -1
fi
ifile="$1"; shift
ofile="_converted/"$(dirname "$ifile")/$(basename "$ifile" .mp3)"_.ogg"
mkdir -p $(dirname "$ofile") &> /dev/null || true
echo "Considering $ifile..."
if ! [ -s "$ofile" ]; then
# FIXME: really exit in case of failure
avconv -y -i "$ifile" -f ogg -vn -acodec libvorbis -ac 1 "$ofile" || (rm "$ofile"; echo "FAILED!"; false)
echo "Converted $ifile to $ofile"
else
echo "$ofile already exists."
fi
}
function converteverythingtoogg {
# FIXME: at least some wmv files don't work with this scheme
for ifile in `find -L -type f -regex '.*\.\(mp4\|mp3\|m4b\|flv\|m4a\|m4v\|wmv\|ogv\|ra\|ogg\|mkv\)' | grep -v ^./_converted`; do
ofile="_converted/"$(dirname "$ifile")/$(basename "$ifile" .mp3)"_.ogg"
mkdir -p $(dirname "$ofile") &> /dev/null || true
echo "Considering $ifile..."
if ! [ -s "$ofile" ]; then
# FIXME: really exit in case of failure
#avconv -y -i "$ifile" -f ogg -vn -acodec libvorbis -ac 1 "$ofile" || (rm "$ofile"; echo "FAILED!"; false)
#avconv -y -i "$ifile" -threads 8 -vn "$ofile" || (rm "$ofile"; echo "FAILED!"; false)
(ffmpeg -y -i "$ifile" -threads 8 -vn "$ofile.wav"; ffmpeg -y -i "$ofile.wav" -threads 8 -vn -strict -2 -acodec vorbis -ac 2 "$ofile"; rm "$ofile.wav") || (rm -f "$ofile"{,.wav}; echo "FAILED!"; false)
echo "Converted $ifile to $ofile"
else
echo "$ofile already exists."
fi
done
echo "SUCCESS."
}
function showratexp {
if [[ $# != 1 ]]; then
echo '$# != 1'
false
else
ratexp="$1"; shift
echo -en "$BROWN"
echo -n "law: "
VCSN_PARENS=1 ./_build/48d/bin/vcsn-cat -C 'law_char(abcdefg)_z' -E -e "$ratexp"
echo -n "law: "
./_build/48d/bin/vcsn-cat -C 'law_char(abcdefg)_z' -E -e "$ratexp"
echo -en "$GREEN"
INPUTP=$(VCSN_PARENS=1 ./_build/48d/bin/vcsn-cat -C 'lal_char(abcdefg)_z' -E -e "$ratexp" 2> /dev/null)
OUTPUT=$(./_build/48d/bin/vcsn-cat -C 'lal_char(abcdefg)_z' -E -e "$ratexp" 2> /dev/null)
OUTPUT2=$(./_build/48d/bin/vcsn-cat -C 'lal_char(abcdefg)_z' -E -e "$OUTPUT" 2> /dev/null)
OUTPUTP=$(VCSN_PARENS=1 ./_build/48d/bin/vcsn-cat -C 'lal_char(abcdefg)_z' -E -e "$OUTPUT" 2> /dev/null)
echo "lal: $INPUTP"
echo "lal: $OUTPUT"
if [[ "$INPUTP" != "$OUTPUTP" ]]; then
echo -en "$RED"
echo WRONG [input parses differently from output]
echo " $ratexp"
echo " parses as"
echo " $INPUTP"
echo " while"
echo " $OUTPUT"
echo " parses as"
echo " $OUTPUTP"
elif [[ "$OUTPUT" != "$OUTPUT2" ]]; then
echo -en "$RED"
echo WRONG [idempotency]
echo " $ratexp"
echo " ==>"
echo " $OUTPUT"
echo " ==>"
echo " $OUTPUT2"
else
echo -en "$NOATTR"
echo "Idempotency is OK: $ratexp ==> $OUTPUT ==> $OUTPUT2"
fi
echo -en "$NOATTR"
fi
}
### Devlopment aliases, suggested by Akim:
alias 49d='make -C _build/49d'
alias 49s='make -C _build/49s'
alias m49d='make -C _build/m49d'
alias m49s='make -C _build/m49s'
alias 48d='make -C _build/48d'
alias 48s='make -C _build/48s'
alias 48scratch='make -C _build/48scratch'
alias cl35d='make -C _build/cl35d'
alias cl35s='make -C _build/cl35s'
alias 48dts='less -R _build/48d/tests/test-suite.log'
alias 48sts='less -R _build/48s/tests/test-suite.log'
alias 48scratchts='less -R _build/48scratch/tests/test-suite.log'
alias cl35dts='less -R _build/cl35d/tests/test-suite.log'
alias cl35sts='less -R _build/cl35s/tests/test-suite.log'
alias c64procedures="acme -v9 --format cbm -o /tmp/q /tmp/q.a 2>&1 | grep ' takes ' | awk '{print \$14, \$12}' | sort -n | uniq"
alias wg="wget --user-agent='Mozilla (5.0 compatible) Internet Explorer Windows Firefox 57 like Chrome .NET 7 foo, more or less'"
alias wg2="wget --user-agent='Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36'"
alias rw="rlwrap --always-readline --history-filename=$HOME/.rlwrap-history-generic"
alias rj="rlwrap --always-readline --history-filename=$HOME/jitterlisp-history"
function run-espeak {
if [[ "$#" != 1 ]]; then
echo "$0 has one parameter"
return -1
fi
espeak -v"$1" --stdin 2> /dev/null
}
function een {
run-espeak en
}
function efr {
run-espeak fr
}
function eit {
run-espeak it
}
#recordmydesktop --compress-cache --s_quality 3 --v_quality 35 --overwrite -o ~/q.ogv
#rsync --progress --inplace --copy-links positron@fencepost.gnu.org:gnu-advisory.mbox ~/gnus/
# Cut a video from 0:00 to 20:00 without reencoding. I think this
# requires the actual ffmpeg, not the avconv wrapper.
#ffmpeg -i gotr-converted.webm -vcodec copy -acodec copy -ss 00:00:00.000 -t 00:20:00.000 gotr-converted-cut.webm
# Transcode and cut away the first two seconds:
# avconv -i ../orig/screencast-ciaa--saiu.ogv -qscale 1 -ss 00:00:02 ciaa-2014--demaille-duretlutz-lombardy-saiu-sakarovitch--screencast--2.webm
# Convert and scale:
# ffmpeg -i Richard\ Stallman\ -\ How\ he\ started\ the\ GNU\ project-UK52v6bCPvg.webm -dstw 480 video-480p.webm
#for x in `seq 23 45`; do echo mv -vi S02E$x[-.]*flv s02e`printf '%02i' $(($x - 22))`.flv ; done
#wget --continue --convert-links --adjust-extension --recursive --relative http://...
# export GIT_SSL_NO_VERIFY=1
case "$-" in
*i*)
# # Interactive shell
# echo -en "$YELLOW"
# fortune -a
;;
*)
# # Non-interactive shell
;;
esac
# Convert a PDF file into black-white
# This also works (in practice better than the commented-out function below):
function pdf_bw1
{
if [ "$#" != 1 ]; then
echo "$0: there should be exactly one parameter"
exit -1
fi
source="$1"
target="$(basename $1 .pdf)-BW.pdf"
convert -density 300 -threshold 50% "$source" "$target"
}
function pdf_bw
{
for x in "$@"; do
pdf_bw1 "$x"
done
}
# convert -density 300 -threshold 50% td1-prof.pdf BWbrutal-td1-prof.pdf
# function pdf_bw
# {
# gs \
# -sOutputFile="BW_$1" \
# -sDEVICE=pdfwrite \
# -sColorConversionStrategy=Mono \
# -sColorConversionStrategyForImages=/Mono \
# -dProcessColorModel=/DeviceGray \
# -dCompatibilityLevel=1.3 \
# -dNOPAUSE -dBATCH \
# "$1"
# }
# function rmd
# {
# sudo killall -KILL pulseaudio; sudo rmmod snd-pcm-oss; sudo rmmod snd-mixer-oss; recordmydesktop --overwrite --on-the-fly-encoding --device default -o ~/foo.ogv
# }
function mytime
{
local format="$1"; shift
local name="$(basename -- $1)"
local filename="$(mktemp --tmpdir=/tmp utime.XXXXXXXXXX)"
printf "%-20s" "$name"
if ! \time --quiet --format="$format" --output="$filename" $@ &> /dev/null ; then
echo -n 'FAILED '
else
cat "$filename"
fi
#head --bytes=-1 "$filename"
rm "$filename"
}
function Qtime
{
mytime '%Us %PCPU %MKB %cisw' $@
}
function utime
{
mytime '%U' $@
}
function wtime
{
mytime '%e' $@
}
function uwtime
{
mytime 'User: %U Wall-clock: %e' $@
}
function wutime
{
mytime 'Wall-clock: %e User: %U' $@
}
alias Utime='\time --format="%U"'
alias Wtime='\time --format="%e"'
alias UWtime='\time --format="User: %Us Clock: %e"'
alias WUtime='\time --format="Clock: %es User: %U"'
# Convert to PCL when printing on my home laser printer, without passing thru a spooler.
# gs -sDEVICE=pcl3 -dNOPAUSE -dBATCH -sOutputFile=/dev/usb/lp1 BW_TD3_iptables-prof.pdf
# one PCL file page:
# gs -sDEVICE=pcl3 -dNOPAUSE -dBATCH -sOutputFile=page-%d.pgf ../dossier-de-recrutement--iut--2018.pdf
function convert_with_subs
{
for source in "$@"; do
basename="$(basename $source)"
basenamewithoutextension="$basename"
for extension in .mp4 .flv .ogv .avi; do
basenamewithoutextension=$(basename "$basenamewithoutextension" $extension)
done
target="$basenamewithoutextension.webm"
for x in "$(dirname $source)/$basenamewithoutextension".{sub,srt}; do
if [ -e "$x" ]; then
sourcesubs="$x"
fi
done
unset subsoptions
if [ -e "$sourcesubs" ]; then
#subfontsize=26
subfontsize=27
subsoptions="subtitles=\'$sourcesubs\':force_style=\'FontSize=$subfontsize\'"
fi
# This works, but I don't always want it.
scaleoptions="scale=320:0"
# Either converter works.
# ffmpeg -y -i "$source" $scaleoptions $subsoptions -threads $(coreno) "$target"
avconv -y -i "$source" -vf $scaleoptions,$subsoptions -threads $(coreno) "$target"
done
}
# Standardize s??e?? file names
function standardize_se_in_this_directory
{
for s in `seq -w 0 99`; do
for e in `seq -w 0 99`; do
for ext in sub srt flv mp4 avi webm ogv; do
# for e in `seq -w 0 99`; do
# if [ -e *[sS]$s[eExX]$e*.$ext ]; then
# echo mv -i *[sS]$s[eExX]$e.$ext s"$s"e"$e".$ext
# fi
# done
filename="*[sS]$s[eExX]$e*.$ext"
# echo $filename
# if [ -e "$filename" ]; then
if [ -e $filename ]; then
# echo mv -i "$filename" s"$s"e"$e".$ext
mv -i $filename s"$s"e"$e".$ext
fi
done
done
done
}
# SSH with every identity I have on the client.
function myssh
{
ssh -v `for x in ~/.ssh/*{_rsa,_dsa}; do echo -n "-i $x "; done` $@
}
function yt10
{
for x in `seq 1 10`; do
youtube-dl --ignore-errors -tc --restrict-filenames "$@"
done
}
function cpu_temperature
{
# FIXME: this is only tested on moore.
cat /sys/devices/platform/coretemp.0/hwmon/hwmon1/temp?_input | sort -n | tr '\n' ' '; echo
}
# for i in `seq -w 1 150`; do echo "$i"; convert "page-$i.png" -crop 634x913+164+45 +repage "page-$i-l.png"; convert "page-$i.png" -crop 629x913+1124+45 +repage "page-$i-r.png"; done
# for i in `seq -w 1 150`; do echo "$i"; convert "page-$i.png" -crop 598x886+181+59 +repage "page-$i-l.png"; convert "page-$i.png" -crop 598x886+1141+59 +repage "page-$i-r.png"; convert "page-$i-l.png" -resize 2000 "page-$i-l.png"; convert "page-$i-r.png" -resize 2000 "page-$i-r.png"; done
# export E=png; rm page-001-l.??? page-001-z.???; rm ?oo.pdf; convert page-???-[lr]."$E" -alpha off -depth 8 -compress zip foo.pdf
# recordmydesktop --no-sound --overwrite --no-frame --windowid=0x2200002 -o /tmp/ring-switcher.ogv
# Flip:
# avconv -y -i foo.mp4 -vf "hflip" -threads 8 foo--avconv.webm
# Convert subtitles to the ".ass" format:
# ffmpeg -i SUBS.srt SUBS.ass
# Convert audio only (no video): avconv -vn
# Convert everything in the parent directory to ogg/vorbis:
# for x in ../*.{webm,mp4,mp3,ogg,flv}; do avconv -y -i "$x" -threads 8 -c:a libvorbis -vn "`basename $x`.ogg"; done
# Hardsub (from .ass subtitles):
# mencoder -oac pcm -ovc lavc -lavdopts threads=8 -sub SUBS.ass INPUT -ass -o OUTPUT
# Stream TAE
#livestreamer --player=mplayer http://www.ustream.tv/channel/the-atheist-experience best
#livestreamer --player=mplayer http://www.ustream.tv/channel/the-atheist-experience worst
# Directly integrate subtitles (with a recent ffmpeg):
# ffmpeg -i video.avi -vf subtitles=subtitle.srt:force_style='FontSize=26' out.avi
# Print B&W: lpr -o saturation=0 td1-prof.pdf
# for x in swe*.{mp4,flv}; do echo avconv -y -i "$x" $(if test -e $(basename $(basename $x .mp4) .flv).srt 2> /dev/null; then echo "-vf subtitles=$(basename $(basename $x .mp4) .flv).srt:force_style=FontSize=26"; fi) -threads 8 $(basename $(basename $x .mp4) .flv).webm; done
#nc -l -p 12345 -c '/tmp/po --white m2' -T Minimize-Delay
# for x in `seq 0 10`; do mencoder -forceidx -alang en -slang en -dvd-device /dev/dvd dvd://$x -cache 655360 -lavcopts threads=8 -ovc lavc -oac lavc -o FOO--part-$x.avi; done
# cat /mnt/cdrom/VIDEO_TS/VTS_02_[0-9].VOB | avconv -y -i - -threads 8 FOO--avconv.webm
# Suppress video channel in the output (-vn):
# avconv -i foo.m4b -y -threads 32 -vn scratch.ogg
# avconv maximum quality:
# -qscale 0
# or something like
# -qscale 100
# Force rate:
# avconv -y -i foo.mp4 -vf subtitles=foo.srt:force_style='FontSize=26' -threads 8 -qscale 100 -b 40k -maxrate 40k bv.webm
# Conversion, hardsubbing and scaling.
# avconv -y -i IN.mp4 -vf scale=640:267,subtitles=SUB.srt:force_style='FontSize=28' -threads 8 OUT.webm
# Work stuff
case "$HOSTNAME" in
moore)
add-prefix "$HOME/usr-cosy"
;;
esac
# Enable cross-compilation environment, even at the cost of disabling my customized
# paths. FIXME: I'd like stack semantics.
function cross_like {
home_usr_suffix="$1"
prompt_prefix="$2"
# I keep all of my cross tools, for every host, under a single prefix.
add-prefix "$HOME/usr-${home_usr_suffix}" partial
# If I keep my usual include paths then my build headers take precedence over
# host headers, which can generate very confusing results; for example
# getc is a macro calling _IO_getc on GNU, but that is not true with uClibc.
unset CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH
# I also prefer not to use my library paths, for the same reason. FIXME: does this
# do any good?
unset LIBRARY_PATH LD_LIBRARY_PATH
# Show the particular state of the shell on the prompt.
PROMPTPREFIX="${prompt_prefix}${PROMPTPREFIX}"
}
#function crossriscv {
# cross_like cross-riscv 'v'
#}
function crossriscv32 {
cross_like cross-riscv32 'v'
}
function crossriscv64 {
cross_like cross-riscv64 'v'
}
function cross {
cross_like cross 'x'
}
function cross-scratch {
cross_like cross-scratch 'X'
}
function mps
(
case "$HOSTNAME" in
moore | sussman)
add-prefix ~/usr-mplayer;;
esac
# ls -Q "$@" | shuf | xargs mplayer --
# \ls --hide='*/' -Q -- "$@" | shuf | xargs echo mplayer --
\ls -Q --ignore='*.text' --ignore='*.txt' -- "$@" | shuf | xargs mplayer --
)
function mpshuf_options
{
options="$1"; shift
for directory in "$@"; do
\ls "${directory}"/*.*
done \
| shuf \
| while read f; do
mplayer ${options} "${f}"
sleep 1
done
}
function mpshuf
{
mpshuf_options "" "$@"
}
function vncpassword
{
# mkdir ~/.vnc/ &> /dev/null || true
# vncpasswd ~/.vnc/passwd
echo "Disabled. See ~/.vnc/passwd"
}
function vncserver
{
# x11vnc -viewonly -shared -many -loop -usepw -nowf -ncache 10 -cursor most &
# x11vnc -viewonly -shared -many -loop -usepw -nowf -ncache 10 -cursor most -nowait_bog -xrandr resize $@ &
# -ssl TMP -anontls plain:newdh:x509:support -vencrypt plain:newdh:x509:support -ssltimeout 0 \
# -stunnel TMP \
# -ncache 10 \
# FIXME: try -noxwarppointer
# FIXME: use -accept to blacklist IPs
# -usepw \
# -viewonly \
x11vnc -display :0 \
-passwdfile read:$HOME/.vnc/passwd \
-shared \
-many -loop \
-repeat \
-nowf \
-overlay -cursor most -nowait_bog -xrandr resize \
-ncache 0 \
-modtweak \
-skip_dups \
-clear_all \
-afteraccept "notify-send --icon vnc 'New VNC client '\$RFB_CLIENT_ID'' 'A new client connected RFB_CLIENT_IP='\'\$RFB_CLIENT_IP\'', RFB_CLIENT_ID='\'\$RFB_CLIENT_ID\'', RFB_STATE='\'\$RFB_STATE\'', RFB_TYPE='\'\$RFB_TYPE\'', RFB_LOGIN_VIEWONLY='\'\$RFB_LOGIN_VIEWONLY\''\\nClients are now '\$RFB_CLIENT_COUNT'.'" \
$@ &
# -gone "notify-send --icon vnc 'VNC client disconnected' \$RFB_CLIENT_IP' disconected.\\nClients are now '\$RFB_CLIENT_COUNT'.'" \
sleep 3
sshs -4R '*:5900:*:5900' luca@ageinghacker.net
killall -KILL x11vnc
sleep 0.2
# Sometimes I see autorepeat being turned off after playing with VNC.
# Turn it back on unconditionally; this is good enough for me, as I always
# want it on.
xset r on
}
function vncserver_xinerama0
{
vncserver -clip xinerama0 $@
}
function vncclient
{
xtightvncviewer -quality 0 $@ ageinghacker.net:0
# -quality 0 is a win, at least with xtightvncviewer
# -QualityLevel 0 should be the same with xtigervncviewer
# # These misbehave under fullscreen with i3 on the client:
# xtigervncviewer ageinghacker.net:0
# [xvncviewer is a debian alias for one of the others]
# Other clients:
# gvncviewer xvnc4viewer vnc-java (jvncviewer) ssvnc directvnc remmina (with remmina-plugin-vnc)
}
function vncclientlocal
{
xtightvncviewer localhost:0
# # These misbehave under fullscreen with i3 on the client:
# xtigervncviewer localhost:0
# xvncviewer localhost:0
}
# # Work in progress: screencast
# function screencast
# (
# # RandR output index, 0-based.
# I=0
# FRAMERATE=15
# THREADQUEUESIZE=5120
# OUTPUTRESOLUTION=640x360
# avconv -y -thread_queue_size "$THREADQUEUESIZE" -f alsa -ac 2 -i default -f x11grab -r "$FRAMERATE" -video_size `x_display_resolution $I` -i :0.0`x_display_offset $I | sed 's/+/q/;s/+/,/;s/q/+/'` -preset ultrafast -crf 0 -threads `coreno` -vf scale="$OUTPUTRESOLUTION" /tmp/screenoutput.avi
# )
# In order to solve problems like this...
# [avi @ 0xd82760] Non-monotonous DTS in output stream 0:1; previous: 15702, current: 14; changing to 15703. This may result in incorrect timestamps in the output file.
# ...first convert to some neutral format, for example raw uncompressed streams.
# (The uncompressed files are much faster to encode to mp4 with avconv than to webm)
#
# When converting with mencode, this trick avoids the green bar on the top of videos
# with very wide aspect
# mencoder -ni -vf softskip,expand=::::1:HORIZONTALRESOLUTION/VERTICALRESOLUTION:2 INPUT.avi -oac pcm -ovc raw -forceidx -lavcopts threads=16 -o OUTPUT.avi
function title
{
echo -e "${BEGINTITLE}$@${ENDTITLE}"
}
# Work in progress: screencast
function screencast
(
# It is important to use the actual ffmpeg, not a wrapper. I have ffmpeg
# installed under the prefix ~/usr-mplayer .
add-prefix ~/usr-mplayer
# RandR output index, 0-based.
I=0
FRAMERATE=15
THREADQUEUESIZE=51200
OUTPUTRESOLUTION=`x_display_resolution $I`
# OUTPUTRESOLUTION=640x360
# OUTPUTRESOLUTION=320x200
ALSA_BUFFER_SIZE_MAX=$((65536 * 1024))
ffmpeg -nostdin -y -thread_queue_size "$THREADQUEUESIZE" -f alsa -ac 2 -i default -f x11grab -r "$FRAMERATE" -video_size `x_display_resolution $I` -i :0.0`x_display_offset $I | sed 's/+/q/;s/+/,/;s/q/+/'` -threads `coreno` -vf scale="$OUTPUTRESOLUTION" /tmp/screenoutput.avi < /dev/null
# avconv -y -thread_queue_size "$THREADQUEUESIZE" -f alsa -ac 2 -i default -f x11grab -r "$FRAMERATE" -video_size `x_display_resolution $I` -i :0.0`x_display_offset $I | sed 's/+/q/;s/+/,/;s/q/+/'` -preset ultrafast -crf 0 -threads `coreno` -vf scale="$OUTPUTRESOLUTION" /tmp/screenoutput.avi
# FIXME: this seems to have a bad video source, but works well for audio:
# ffmpeg -f x11grab -r 25 -s 288x216 -i 0:0+1,20 -f alsa -i default -strict -2 -acodec aac -vcodec mpeg4 -y rec.mkv
)
# convert -units pixelsperinch -density 600 ../bureaucracy/esercito-italiano-foglio-matricolare-e-caratteristico--2016-november.pdf -units pixelsperinch -resample 1200 -colors 2 esercito-italiano-foglio-matricolare-e-caratteristico--2016-november--fixed.pdf
### An internal function used within gb. This assumes that the output of gbase
### is not an error message, and this is checked for within gb.
function gb_filter
{
sed 's/^Dec: //;s/^Hex: /0x/;s/^Oct: /0o/;s/^Bin: /0b/;' \
| tr '[:upper:]' '[:lower:]'
}
### Base conversion utility, as a thin layer over gbase. gbase does a useful
### job but its interface is very obtuse.
function gb
{
if [ "$#" != 1 ]; then
echo "bg: there should be exactly one parameter"
return -1
fi
number="$1"
sign=""
# Remove the sign, so that the user can write it before the prefix. A minus
# will be re-added later if needed.
if echo "$number" | grep -q '^+'; then
number="$(echo $number | sed 's/^+//')"
elif echo "$number" | grep -q '^-'; then
number="$(echo $number | sed 's/^-//')"
sign="-"
fi
# Detect the base from the number prefix, and remove the prefix.
if echo "$number" | grep -q '^0b'; then
base_option="-b"
number="$(echo $number | sed 's/^0b//')"
# The conditions for bases 2 and 8 subsume the one for base 16, so they have
# to come first.
elif echo "$number" | grep -q '^0x'; then
base_option="-h"
number="$(echo $number | sed 's/^0x//')"
elif echo "$number" | grep -q '^0o'; then
base_option="-o"
number="$(echo $number | sed 's/^0o//')"
elif echo "$number" | grep -q '^0'; then
base_option="-o"
else
base_option="-d"
fi
if test "$sign" = "-"; then
# Gbase doesn't like negative numbers in any base other than 10. So
# let's first convert the number's absolute value to decimal.
modulo=$(gbase $base_option "$number" | grep '^Dec: ' | awk '{print $2}')
# In order to give better error messages, which could have been hidden
# by the pipeline above, run gbase like before one more time, checking
# for error messages in the output. This fucking stupid program doesn't
# even exit with failure.
if gbase $base_option "$number" | grep -q '^Bad data'; then
echo "bg: invalid input $sign$number"
return -1
fi
# Now let's call gbase again with the negative version of the modulo,
# expressed in decimal as it likes.
gbase -s -d "-$modulo" | gb_filter
else
# In this case as well, let's provide some sensible error detection.
if gbase $base_option "$number" | grep -q '^Bad data'; then
echo "bg: invalid input $sign$number"
return -1
fi
gbase -s $base_option "$number" | gb_filter
fi
}
# A crude function to run a case-insentive locate, with the output filtered
# by zero or more case-insensitive strings.
function locatei ()
{
if test "$#" -lt 1; then
echo 'locatei takes one or more arguments.'
return -1
else
# No shifting: I will grep again for $1, for colorization's sake.
everything="$@"
commandline=$(echo -n "(locate -i \"$1\") ";
for x in $everything; do
echo -n "| grep --color=always -i \"$x\" "
done;
echo)
# echo "${commandline}"
bash -ic "${commandline}"
return 0
fi
}
### Aliases for quemu
alias qaarch64eabi="qemu-aarch64 -r 4.10.17 -L /home/luca/usr-cross/aarch64-unknown-linux-gnueabi/sysroot"
alias qaarch64="qemu-aarch64 -r 4.11.3 -L /home/luca/usr-cross/aarch64-unknown-linux-gnu/sysroot"
alias qalpha="qemu-alpha -r 4.10.17 -L /home/luca/usr-cross/alphaev4-unknown-linux-gnu/sysroot/"
#alias qarm="qemu-arm -L /home/luca/usr-cross/arm-unknown-linux-gnueabi/sysroot/"
alias qarm="qemu-arm -r 4.11.3 -L /home/luca/usr-cross/arm-unknown-linux-gnueabihf/sysroot"
alias qi386="qemu-i386 -cpu athlon -r 4.10.8 -L /home/luca/usr-cross/i586-unknown-linux-gnu/sysroot/"
alias qmips="qemu-mips -r 4.11.3 -L /home/luca/usr-cross/mips-unknown-linux-gnu/sysroot/"
alias qmips64="qemu-mips64 -r 4.10.17 -L /home/luca/usr-cross/mips64-unknown-linux-gnu/sysroot/"
alias qmips64el="qemu-mips64el -r 4.10.17 -L /home/luca/usr-cross/mips64el-unknown-linux-gnu/sysroot/"
alias qmipsel="qemu-mipsel -L /home/luca/usr-cross/mipsel-unknown-linux-gnu/sysroot/"
alias qmipselsussman="qemu-mipsel -r 4.10.8 -L /home/luca/usr-cross/mipsel-lemote-linux-gnu/sysroot/"
alias qmipselnanonote="qemu-mipsel -r 4.10.8 -L /home/luca/usr-cross/mipsel-nanonote-linux-uclibc/sysroot/"
alias qpowerpc="qemu-ppc -r 4.6.7 -L /home/luca/usr-cross/powerpc-unknown-linux-gnu/sysroot"
# FIXME: how do I work with 32-bit little-endian powerpc?
alias qpowerpc64="qemu-ppc64 -r 4.11.3 -L /home/luca/usr-cross/powerpc64-unknown-linux-gnu/sysroot"
alias qpowerpc64le="qemu-ppc64le -r 4.11.3 -L /home/luca/usr-cross/powerpc64le-unknown-linux-gnu/sysroot"
alias qs390x='qemu-s390x -r 4.11.3 -L /home/luca/usr-cross/s390x-ibm-linux-gnu/sysroot/'
alias qsparc="qemu-sparc32plus -r 4.10.17 -L /home/luca/usr-cross/sparc-unknown-linux-gnu/sysroot/"
alias qsparc64="qemu-sparc64 -r 4.10.17 -L /home/luca/usr-cross/sparc64-unknown-linux-gnu/sysroot/"
alias qsh4="qemu-sh4 -r 4.10.17 -L /home/luca/usr-cross/sh4-unknown-linux-gnu/sysroot/"
alias qsh4eb="qemu-sh4eb -r 4.10.17 -L /home/luca/usr-cross/sh4eb-unknown-linux-gnu/sysroot/"
# I installed the RISC-V toolchain in a different way, so the RISC-V sysroot
# path doesn't follow the same pattern as the others.
# alias qriscv32="qemu-riscv32 -r 4.10.17 -L /home/luca/usr-cross-riscv/sysroot/"
# alias qriscv64="qemu-riscv64 -r 4.10.17 -L /home/luca/usr-cross-riscv/sysroot/"
alias qriscv32="qemu-riscv32 -r 3.0.0 -L /home/luca/usr-cross-riscv32/sysroot/"
alias qriscv64="qemu-riscv64 -r 3.0.0 -L /home/luca/usr-cross-riscv64/sysroot/"
# Temporary workaround (August 2017) for a problem with fucking libreoffice in debian sid.
# (/usr/lib/libreoffice/program/javaldx: error while loading shared libraries: libreglo.so: cannot open shared object file: No such file or directory )
LD_LIBRARY_PATH="/usr/lib/libreoffice/program:$LD_LIBRARY_PATH"