/mgsloan-dotfiles

Linux and xmonad configuration files

Primary LanguageShell

This repo contains my computer configuration files! The code and configuration here is covered by the MIT license - see the text here.

XMonad configuration

Particularly highlighting stuff that may be interesting for others to use:

Logging and process running

Logging and process running is implemented by using rio package. To integrate nicely with rio, a couple monads are defined:

  • An XX monad, which wraps the X monad and adds a reader context compatible with rio.

  • Similarly, a Xio monad, which wraps the IO monad in the same reader context.

There are also process running utilities which log process start and end. In particular:

  • The spawn function asynchronously spawns a process, similarly to the standard xmonad function of the same name.

  • The syncSpawn function synchronously spawns a process. Its type is intentionally restricted to run in Xio,

  • The syncSpawnAndRead function runs a process and reads its output.

  • Implements a couple utilities inspired by XMonad.Actions.SpawnOn - spawnOn and spawnAndDo. These utilities record the spawned process ID and associate it with a ManageHook. The configuration uses this to spawn applications on particular workspaces at startup.

  • If a sanity check of systemd-cat succeeds on startup, then it gets used to wrap the processes. This way the logs of all processes end up in the systemd log. One cool thing this allows is bringing up the logs for a particular window on request (currently bound to M-y).

  • These utilities rely on the SIGCHLD patch to xmonad, described in a section below.

Startup

At startup, some standard stuff like a browser and emacs get run. The following also gets run:

  • dunst, a minimal notification display daemon. My configuration is located at .config/dunst/dunstrc. I wrote a couple patches which this config uses - dunst#590 and dunst#598.

  • keynav, a utility to use the keyboard to perform mouse actions. I find this most useful for putting focus on things and sending scroll events. My configuration is located at .keynavrc.

  • redshift, a utility to adjust screen color temperature at night.

  • A terminal using systemd journalctl, on workspace 9, to display all error messages since boot. These errors get filtered by env/errlog-filter/errlog-filter.hs - the goal being to investigate errors encountered and hide them once the conclusion is that they are benign. I don't yet have an exhaustive list of benign errors outputted by my computer.

  • A terminal using systemd journalctl, also on workspace 9, to display the most recent logs.

  • A terminal running bluetoothctl, also on workspace 9, for cli control of bluetooth devices. Specifically, Bluetooth.hs has some utilities for connecting and disconnecting devices which have been paired. It uses tmux send-keys to enter commands into the bluetoothctl terminal. For some reason, non-interactive cli approaches to controlling bluetooth didn't work properly for me.

  • A terminal running nmtui, also on workspace 9, for controlling internet connections, particularly wifi. I've found nmtui to be more reliable than using GUI interfaces, and more convenient than using nmcli.

Screen lock on startup and after sleep

Probably more effort than it was worth, but I liked the idea of the startup applications starting up in parallel with the password screen. To do this, I enabled gdm autologin, and immediately start slock on start of xmonad. See ScreenLock.hs.

I also wanted to require the password after resuming from sleep. Installing env/systemd/slock@.service causes slock to be run before sleeping.

Other bits of code

  • Audio.hs has utilities for adjusting volume and toggling the microphone via use of amixer. It also uses notify-send to report the state of the audio.

  • Background.hs has utilities for selecting a random image stored in ~/env/untracked/backgrounds and using feh to set the desktop background.

  • Brightness.hs has utilities for adjusting laptop screen brightness by writing to /sys/class/backlight/intel_backlight/brightness (works for thinkpad screens). User access to this is enabled by copying env/udev-rules/90-backlight.rules.

  • byzanz is a utility for capturing gif recordings of the screen. Byzanz.hs has code to run [env/byzanz-record-region.sh], a script using [xrectsel] and byzanz to record a region of the screen. The script also uses imagemagick to downscale the captured gif by a factor of 2 if HIDPI is set.

  • Scrot.hs has a utility for running scrot, taking a screenshot of a rectangular region of the screen. Also uses imagemagick to downscale the captured screenshot by a factor of 2 if HIDPI is set.

  • Gist.hs runs gist to create GitHub gists of the current selection, and opens the gist in the browser.

  • RedShift.hs has code for running redshift and allowing toggling it (by a rather crude mechanism - killing and starting).

  • Spotify.hs has utilities for dbus control of spotify - basic stuff like play / pause / next / previous.

  • TallWheel.hs is just like the built in xmonad Tall layout, but

  • Touchpad.hs uses xinput to toggle the enabling / disabling of a thinkpad touchpad. The touchpad is initially disabled.

  • Prompt.hs provides prompts for running shell actions (shellPrompt) or xmonad actions (actionPrompt). actionPrompt is used for the xmonad actions that I use quite infrequently, and so shouldn't have keybindings.

No symlink manager, just git

This dotfiles repo uses git directly instead of having an install procedure or symlink manager. This has quite a few benefits:

  • Simplicity - no configuration needed.

  • It helps keep my home directory tidy, as new files and folders either get added to this repo, deleted, or added to .gitignore.

  • No need to research, compare and contrast symlink management approaches.

This might initially seem like a bad idea, since git searches parent folders for .git repos, and so commands might inadvertantly apply to the home dir repo. There's a pretty good solution to this, though it requires a bit of setup. See env/home-dir-git.md for more info on this.

Upstream patches

The submodules referenced by this repo have a few non-standard patches applied. Some of these are in the form of PRs which will hopefully be merged, and some already have been merged.

xmonad patches

This configuration uses a patched xmonad - the submodule is located at env/xmonad. At time of writing this readme, it has the following patches:

  • XMonad by default installs a SIGCHLD handler which does nothing. The problem with this is that it means that the typical process functions don't work properly if you want to wait for process exit. Since I want to have proper process handling and logging, SIGCHLD can't get ignored. The comments in the code indicate that it was ignored to avoid zombie processes, but I haven't seen them accumulate. Even when zombies do occur, they are pretty benign. The patch

  • Omits implicit recompile on XMonad start. The patch

  • Exposes sendRestart function, which seems to be a much nicer way to handle restarting XMonad, as it doesn't require running another xmonad process just to send the signal. The patch

  • Exposes constructor for the X monad, which allowed me to define MonadThrow and MonadCatch instances for it. The patch

xmonad-contrib patches

Uses a patched xmonad-contrib - the submodule is located at env/xmonad-contrib. At time of writing this readme, it has the following patches:

  • A PR I wrote to make XMonad.Prompt more reliable on exceptions: xmonad-contrib#287

  • A significant optimization to extended window manager hooks written by bgamari but not yet merged: xmonad-contrib#263

  • A change to XMonad.Prompt to make it ignore more keymasks. Some users of XMonad may need these keymasks, so it's not a change everyone might want. See discussion in xmonad-contrib#290.

systemd-cat patch

Systemd version 242 and above includes my small patch to systemd-cat, which allows using different log levels for stdout and stderr. In particular, with my config, stderr gets logged with err level and stdout gets logged with info level.

Most systems do not yet have this recent of a systemd version. It's possible to only build the systemd-cat and its deps, and it seems to work fine atop near enough systemd versions. Here's how to build it:

sudo apt install meson
sudo apt build-dep systemd
meson build
ninja -C build systemd-cat

Then, from within the repo I did ln -s build/systemd-cat ~/.local/bin/systemd-cat to put it in my local bin. If just a copy is done then it will complain about missing shared objects.

Ubuntu / debian dependencies

I typically use ubuntu / debian flavor. For convenience, I'm including some apt install invocations that install dependencies of this configuration.

Here are some development dependencies needed to build this XMonad configuration, some of the submodules, and some of the other programs it invokes:

sudo apt install libcairo2-dev libxinerama-dev libxdo-dev libxrandr-dev libgmp-dev libxext-dev libxss-dev libxft-dev libdbus-1-dev libgtk-3-dev

And a few programs that I use unmodified:

sudo apt install scrot feh byzanz

Fonts:

sudo apt-get install fonts-hack-otf fonts-hack-ttf

Other stuff

  • Log of setup notes - specific steps I've taken to setup my computer.

  • Separate repository for emacs configuration.

  • .bashrc and .profile don't have anything particularly special. The main thing to note is that .profile loads ~/env/untracked/settings.sh if it exists. The purpose of this is to set HIDPI, which in turn will cause some settings specific to using high pixel density displays.