Generating compile_commands.json

What the heck is this?

When I first started doing C++ programming this Summer with Grail, I wanted to use Emacs as my primary editor. I quickly found out that ccls exists, and was well integrated into Doom Emacs. The primary issue with this setup was that ccls couldn't tell where different imports were, and kept giving an error. The way that Clang based language servers (like clangd) work is they require a compile_commands.json file which contains the commands that run on each file in the project when compiled. Without one of these, the language server doesn't know how to index the project, and starts throwing out false errors.

How do I get one?

The easy way

If your project uses CMake, set the variable CMAKE_EXPORT_COMPILE_COMMANDS to ON and a compile_commands.json will generate in the build folder. Symlink that thing to the root directory of the project and you're good to go.

If you like to have your sanity while using a build system and use Meson, the JSON file should be automatically generated for you and placed in your build files folder.

The slightly more painful way

If your project doesn't use CMake (Grail used a bizarre and confusing system using make before this Summer), the best way to generate one of these files is going to be with bear. As per the README, generating the file is as easy as:

bear -- <your-build-command>

Debian Backup Script

Author's Note 02/13/22

This note is out of date, as I'm no longer using a Debian based distribution on my laptop. However, for anybody using Debian/Ubuntu based distributions and dealing with the pain of multiple package managers, hopefully this guide can still be of use.


I've been using Pop!_OS for ages now, and I only ended up doing a clean reinstall once because I wanted to try out the beta build of 21.04. Despite this amazing track record, I still try and prepare like my installation is going to instantaneously explode and any moment, and I'll have to reinstall everything from scratch. Here's what I do to prepare.

Backing up manually installed apt packages

apt-mark showmanual > ~/Documents/new_machine/manual_installed
echo "Successfully backed up manually installed packages"

It's worth noting that often times this list will contain more than just the packages you've manually installed, and usually will have packages installed by default in the OS, but it won't include the massive list of dependencies.

Backing up programs installed with flatpak

flatpak list --columns=application > ~/Documents/new_machine/flatpaks
echo "Successfully backed up installed flatpaks"

Backing up dconf data

dconf dump / > ~/Documents/new_machine/xenon_backup
echo "Successfully backed up dconf configuration"

Backing up pipx packages

pipx list | grep package | awk '{print $2}' | grep -v pipx > ~/Documents/new_machine/pipx_backup
echo "Successfully backed up pipx programs"

This is one of the more interesting commands, here's how it works.

1. pipx list

venvs are in /home/david/.local/pipx/venvs
apps are exposed on your $PATH at /home/david/.local/bin
   package gdtoolkit 3.2.7, Python 3.9.4
    - gdformat
    - gdlint
    - gdparse

The only thing I want from this output is the name after the word package, gdtoolkit, so I need to cut out everything else besides that.

2. grep package

   package gdtoolkit 3.2.7, Python 3.9.4

If you know what grep is, then this is pretty self-explanatory. If not, grep searches either a file or whatever is given to it from stdin for the supplied regex (in this case just a word) and sends to stdout the lines of text containing the regex.

3. awk {print $2}


Awk is a bit of a magical tool that I don't fully understand, but what you see here just gets the second word from the previous output, which in this case is the name of the package.

Backup fisher plugins

fish -c 'fisher list' > ~/Documents/new_machine/fisher_backup
echo "Successfully backed up fisher plugins"

Full system backup

For backing up the state of the system (everything in the root directory besides home folders more or less), I have a program called timeshift making daily backups.

Home folder backup

For backing up my home folder I use Deja Dup, and have it backup via SFTP to the NAS on my home network.