A place where I capture raw, quick notes worth remembering.

February 15, 2023

linux utils

Espanso, text expander for Linux

I love the smart dashes – and I use them heavily – on the Mac and it’s something I missed on PopOS!.

Luck be it, Espanso comes along. Installation on a Debian system is easy.

Configuration of Espanso is done by editing configuration files located in ~/.config/espanso directory. You can also find it by tying espanso path. The files contained in the match directory define what Espanso should do. The files contained in the config directory define how Espanso should perform its expansions.

To replace our double dashes with a long dash we are going to edit $CONFIG/match/base.yml add change it to:

matches:
  - trigger: "--"
    replace: ""

However, now this also happens in our terminal, which is annoying, so we are going to disable Espanso completely in the terminal with an app specific configuration.

We’ll disable it in Alacritty, my terminal of choice by creating a config/alacritty.yml and match on the class name:

filter_class: Alacritty
enable: false

That’s it, Espanso is super powerful and I can recommend reading the docs on what else it can do. Oh, and it also works on MacOS or Windows.

Permalink

December 27, 2022

git

A quick gitignore from a template

Often when I start a new project, I also need to have a .gitignore for the specific language that I’m working in.

To easily do this, I added the following alias to my git, which pulls a template from gitignore.io:

git config --global alias.ignore \
'!gi() { curl -sL https://www.toptal.com/developers/gitignore/api/$@ ;}; gi'

Now you can do git ignore zig and it will show you the default ignore file for a Zig project.

To automatically put it in your gitignore, just redirect the output:

git ignore zig >> .gitignore

Permalink

December 13, 2022

zig

Easily install Zig with zigup

I used to manage my Zig installation by installing the binary and copying to my path. Not too hard, but now there is even an easier way by using zigup.

To install zig, it enables you to simply type zigup master

I would recommend to get the latest binary from the Github releases page. Or if you already have Zig, install it from source:

# Install the binary
git clone [email protected]:marler8997/zigup.git
cd zigup
zig build -Dfetch
cp zig-out/bin/zigup ~/.local/bin/

Permalink

November 26, 2022

helix

Language Servers for Helix

I have been trying out Helix as my daily editor and the editor has built in support for LSP. However, it does not install the Language Servers, so you have to do that yourself.

Below are the language servers I installed for writing my code in HTML, CSS and Markdown.

You can always check if a language is setup by doing:

hx --health <lang>

So for example this will tell you if your HTML is supported:

hx --health html

HTML, CSS and SCSS

Both HTML, CSS and SCSS use the language server from Visual Studio Code:

npm i -g vscode-langservers-extracted

Markdown

For Markdown it uses marksman and to install it you can download the latest version from their releases page

wget <link from releases page>

# Make it executable
chmod +x marksman-<dist>

# Move it to a directory in your path, in my case `~/.local/bin`
mv marksman-<dist> ~/.local/bin/marksman

Move it to somewhere in your $PATH and you should be good to go.

Permalink

November 24, 2022

zig

Zig types explained in Ziglings

I have been tinkering with Zig lately and to get a grasp on the language I have been using the excellent Ziglings quizes.

In Quiz #58 there is a great comment which lists the different types for Zig:

//
// We've absorbed a lot of information about the variations of types
// we can use in Zig. Roughly, in order we have:
//
//                          u8  single item
//                         *u8  single-item pointer
//                        []u8  slice (size known at runtime)
//                       [5]u8  array of 5 u8s
//                       [*]u8  many-item pointer (zero or more)
//                 enum {a, b}  set of unique values a and b
//                error {e, f}  set of unique error values e and f
//      struct {y: u8, z: i32}  group of values y and z
// union(enum) {a: u8, b: i32}  single value either u8 or i32
//
// Values of any of the above types can be assigned as "var" or "const"
// to allow or disallow changes (mutability) via the assigned name:
//
//     const a: u8 = 5; // immutable
//       var b: u8 = 5; //   mutable
//
// We can also make error unions or optional types from any of
// the above:
//
//     var a: E!u8 = 5; // can be u8 or error from set E
//     var b: ?u8 = 5;  // can be u8 or null

Permalink

November 20, 2022

git

Create a new repository with Github CLI

Github has their own CLI tool which enables you to interact with Github through the command line.

I often start new repositories and started using the following command to quickly create a accompanying, private repo on Github:

gh repo create <name> --private --source=. --remote=origin

Permalink

October 14, 2022

emacs macos

Install Emacs on the Mac

There are many ways to install Emacs on the Mac, from pre-build Applications, to Homebrew, to installing from source.

My current favorite way to get the latest Emacs which has some additional stuff for the Mac is by using a build script, which builds Emacs from its source.

It’s called build-emacs-macos and is on Github. The instructions to use it are here in the README.

Permalink

October 12, 2022

emacs wsl

Emacs on Windows WSL2

So, it turns out that WSL2 is actually kind of neat, where it runs a Linux image at almost native speed, and also supports Wayland.

So, what’s the first thing you do in WSL2? Install Emacs of course!

Below is the script I use to install Emacs on an Ubuntu image.

To know what the latest stable version on master is, I look at this Github issue from Jim Myhrberg, who keeps track of those.

# Checkout Emacs
$ git clone git://git.sv.gnu.org/emacs.git

# Checkout latest stable version, see note above.
$ git checkout 8febda4

# Vanilla Emacs requirements
$ sudo apt install build-essential autoconf libgtk-3-dev libgnutls28-dev libtiff5-dev libgif-dev libjpeg-dev libpng-dev librsvg2-dev libxpm-dev libncurses-dev texinfo adwaita-icon-theme-full

# Native compilation requirements
$ sudo apt install libgccjit-11-dev

# Required for Native JSON
$ sudo apt install libjansson4 libjansson-dev

# Required for tree-sitter support
$ sudo apt install libtree-sitter-dev

$ cd emacs
$ export CC=/usr/bin/gcc-11 CXX=/usr/bin/gcc-11
$ ./autogen.sh
$ ./configure --with-pgtk --with-native-compilation --with-tree-sitter --with-json --without-pop
$ make -j$(nproc)
$ sudo make install

And, sometimes when you update the repository, it refuses to build. I usually fix that with running make bootstrap er make distclean.

Permalink

September 7, 2022

wsl

Syncthing on WSL2

I like to use Syncthing to sync files between accounts and machines, and now even between my Windows subsystem and Windows itself.

To run Syncthing on WSL I use this script:

#!/usr/bin/env bash
SERVICE="syncthing"
USER="petar"
PORT=2103
OPTS="
        --no-browser
        --home=/home/$USER/.config/syncthing
        --gui-address=http://127.0.0.1:$PORT
        --logfile=/home/$USER/.config/syncthing/syncthing.log
"

if ! pgrep -x "$SERVICE" >/dev/null
then
        daemonize /usr/bin/syncthing serve "$OPTS"
fi

Make sure to change your username and to make the port unique, if you run multiple Syncthings on your machine.

Permalink

September 5, 2022

rust

Rust Analyzer from Source

I’m developing on a FreeBSD machine and rust-analyzer is not available as a pre-build release.

Luckily, it’s easy to build rust-analyzer from source. Just clone the repository and run:

cargo xtask install --server

I’m on Emacs, so I only need the server, hence the --server argument. If you are using Visual Studio Code, don’t add it.

Permalink