Expand alias from bash prompt

Sometimes, you need to recall how a complex alias was made and adjust it before execution. Ideally, you want to expand that bash alias from the interactive prompt. While there exist many full fledged snippets managers with interactive prompts and fancy features, I like to achieve my goals using vanilla tools when possible. It turns … Read more

Summarize youtube videos from the command line tool

Thanks to the recent innovations with LLM, and the fantastic work of justine.lol, we now have open source large language model to play with. While those models have no logic, their capacity to compress language is useful for summarizing.

In this post, we will see some bash functions to transform a youtube video into a summary that can quickly be read to get the gist of what is happening.

These functions can also be used to summarize any content that can be converted to raw txt format.

Read more

Useful git tricks

At Ableton, we use git extensively, aiming for a very good git history that tends to look like literate programming. Therefore, I have accumulated a few git config and commands to help with these workflows. To get utmost confidence when writing this page, I referenced the git rebase help page, it is a very good documentation piece that I recommend you to read top to bottom one day.

Here are useful git config flags and commands that solves common situations.

Read more

ed and a self documenting Makefile

Makefile is a powerful way to declare a chain of interdependent commands that create targets. In this article, we will explain how to create an auto-documenting Makefile that is able to print a help message when invoked without target.

The idea of a self-documenting Makefile comes from this almost perfect stackoverflow answer, if it wasn’t for some peculiarities of the unfortunately different version of macOS’s sed, compared to GNU.

ed as a compatible sed replacement

ed, one of the first three key elements of Unix according to Wikipedia, is the ancestor of sed.

Its legacy is an advantage for us because its interface hasn’t changed since ages, and thus remains a very interesting way of writing multi-platform scripts.

We will use ex, as its proximity with vi helps iterating quickly on the different options.

TL;DR, the Makefile

Here is an example Makefile that prints some help when invoked without target. We signify documentation with regular comments by doubling the hashtags trailing after some targets. For good measure, we also use the strict makefile headers. Continue reading for more details.

SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules

.PHONY:help
help:  ## print these help instructions
	@ex -s  '+%g!/^[\\.A-Za-z_-]\+:[^#]\+##.*$$/d _' '+%s/^\([\\.A-Za-z_-]\+\):.*## \+\(.*\)$$/\"\1\" \"\2\"/' -c'%p|q!'  <(cat ${MAKEFILE_LIST}) | xargs printf "make %-20s# %s\n"

a:
	echo $@ > $@

b: # some internal help, not to be printed
	echo $@ > $@

c.txt: a b  ## this target is what you want to generate probably
	cat $? > $@
	echo "Generation complete"

Read more

Compile any project on windows from vim directly

vim is a powerful editor, and can compile many standard ways, thanks to the vanilla capabilities, and plugins. But sometimes, projects have in-house build systems. Here too, the flexibility of vim makes it able to accommodate for that in just three simple steps: symlink nmake.exe, write a Makefile.win that bridges, and a .local.vimrc to save the settings per project. Here are detailed instructions for how to configure this.

Read more

TIL: grep comes from ed’s g/re/p

It is amazing to learn trivias from the beginning of computers. grep is such an ubuquitous tool, and when one of my colleagues asked me “why is it called this way?”, I had to look it up. Turns out, it comes from the tool ed that has a mode g that matches a regular expression re to an action, here p for printing.

gglobal
reregular expression
pprint

See more detailed story from the teletype era at https://thenewstack.io/brian-kernighan-remembers-the-origins-of-grep/

Working with multiple git identities with envrc

The canonical way to work with multiple git identities on the same computer is to specify different ssh hosts by modifying the home ssh config and each local git remote urls (see https://superuser.com/questions/232373/how-to-tell-git-which-private-key-to-use ).

But sometimes we want to achieve the same effect without modifying the ssh config, nor the git remote urls. Here is how to do so with envrc.

Read more

Browse huge database with vim and clangd

Vim is a powerful text editor that I like to use for its flexibility and customizability. One of the most useful features of Vim is its ability to easily install plugins to gain functionality, here navigating through code sources using the clangd language server. In this article, I will explain how to configure Vim for easy code source browsing with clangd.

Read more

Browse huge codebase with vim tags

Vim is a fantastic text editor. I really understood the benefits of it when reading “You don’t grok vim”, a famous (289 captures 2 Apr 2010 – 28 Mar 2023 in the Wayback Machine) stackoverflow post that explains the design of such tool, and its powers. Please take a moment to appreciate the dithyrambic comments.

However, when transitioning from a full-fledged c++ IDE, I missed the ability to browse symbols by going to definition, implementation or references. Here is how you give vim the ability to browse huge codebase with vim tags.

Read more