config snippets

some helpful scripts and configuration snippets I use in my i3 setup

fakescan

Sometimes it is handy to not print and scan a document but to just “virtually” scan it.

~ % cat .bin/fakescan  
#!/bin/bash
if [ -z $1 ]; then
    echo 'Usage: fakescan <source_file.pdf>'
    exit 1
fi

echo "$1"
BASE_FILENAME="${1/.pdf/}"

# fakescanning file
convert -density 150 $1 -colorspace gray -linear-stretch 3.5%x10% -blur 0x0.5 -attenuate 0.25 +noise Gaussian -rotate .5 $BASE_FILENAME\_scanned.pdf

# reducing file size
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$BASE_FILENAME\_scanned_reduced_filesize.pdf $BASE_FILENAME\_scanned.pdf

wallpaper

~ % ls ~/wallpapers
daniel-lincoln-pjjOpkk5i1k-unsplash.jpg  wallace-bentt-P9mxR5UsHLI-unsplash.jpg
jeremy-bishop-BuQ-jgeexaQ-unsplash.jpg

~ % cat .bin/wallpaper
#!/bin/bash
feh --bg-fill `find ~/wallpapers |sort -R |tail -1`

~ % cat .config/i3/config | grep wallpaper
exec ~/.bin/wallpaper

i3locklog

~ % cat .bin/i3locklog
#!/bin/bash
echo "i3lock:   `date`" >> ~/i3lock.log
i3lock -n
echo "i3unlock: `date`" >> ~/i3lock.log

~ % tail i3lock.log
i3unlock: Tue 07 Jan 2020 06:00:15 PM CET
i3lock:   Tue 07 Jan 2020 06:46:41 PM CET
i3unlock: Wed 08 Jan 2020 09:44:21 AM CET
i3lock:   Wed 08 Jan 2020 10:00:51 AM CET
i3unlock: Wed 08 Jan 2020 10:03:10 AM CET

~ % cat .config/i3/config | grep i3locklog                                   :(
bindsym $mod+x exec ~/.bin/i3locklog

dpdetect

Detect external screen (here: DisplayPort) and apply xrandr config.

~ % cat .bin/dpdetect
#!/bin/bash
xrandr | grep 'DP-2 disconnected' > /dev/null
displayport_connected=$?

if [ $displayport_connected -eq 1 ]
then
  echo "Displayport connected"
  ~/.screenlayout/screenlayout_config_created_by_arandr.sh  # or just place your own xrandr command
else
  echo "Displayport disconnected"
  xrandr --auto
fi

i3 multi-monitor setup

When using a multi-monitor setup, it’s super handy to move your current workspace including all open windows to the next monitor.

~ % cat .config/i3/config | grep -A 1 'next screen'                            :(
# move workspace to next screen
bindsym $mod+Shift+m move workspace to output up

Switch between two workspaces back and forth by using the same keybinding (e.g. pressing $mod+2 multiple times:

~ % cat .config/i3/config | grep back_and_forth
workspace_auto_back_and_forth yes

i3 soundboard

set $mode_soundboard sound board
bindsym $mod+m mode "$mode_soundboard"

mode "$mode_soundboard" {
    bindsym d exec mpv ~/Sounds/DeMaiziereHackerMoegenHacken.mp3
    bindsym s exec mpv ~/Sounds/01_Science_is_Fun.mp3
    bindsym p exec mpv ~/Sounds/Hey_Pippi_Langstrumpf.ogg
    bindsym b exec mpv ~/Sounds/BaDumTss.webm

    bindsym BackSpace exec killall mpv
    bindsym Escape mode "default" 
    bindsym Return mode "default"
}