Posts tagged with “linux”

Super quick guide to Espanso

Espanso is a text expanding utility, and it's really good at what it does. If you find yourself typing the same text (your name, address, greetings, etc.) over and over again, Espanso is what you need. Deploying the tool is a matter of grabbing the right package, installing it, and running it as a service:

wget https://github.com/federico-terzi/espanso/releases/download/v2.2.1/espanso-debian-x11-amd64.deb
sudo apt install ./espanso-debian-x11-amd64.deb
espanso service register
espanso start

The example above uses Espanso 2.2.1 for Debian with X11. So if you use a different setup, adjust the first two commands accordingly.

To add text expansion rules, switch to $HOME/.config/espanso/match and open the base.yml file for editing.

An expansion rule consists of a trigger (that is, an abbreviation) and a text that replaces it:

- trigger: ":hello"
    replace: "Oh, hello there!"

Add the rules you need, and you're done. When you save the changes, Espanso automatically reloads, and you can use triggers everywhere — including command-line applications.

Get your exact position with a Bash one-liner

Need to get the geographical coordinates of your current position? On a Debian and Linux Mint, install the geoclue-2-demo package using the sudo apt install geoclue-2-demo command, then run the following one-liner:

/usr/libexec/geoclue-2.0/demos/where-am-i | grep -e 'Latitude' -e 'Longitude' | tail -n 2

If you need the latitude and longitude values only, use this one-liner instead:

/usr/libexec/geoclue-2.0/demos/where-am-i | \
grep -e 'Latitude' -e 'Longitude' | tr -d ' ' | \
cut -d':' -f2 | tr -d ° | tail -n 2

Running a systemd service as a regular user

A "note to self" post on how to create a systemd service and run it a regular user.

Assuming, you're logged in as a regular user, create the ~/.config/systemd/user/ directory using the mkdir -p ~/.config/systemd/user/ command. Then, create a .service file:

nano ~/.config/systemd/user/my_service.service

Specify the service options:

[Unit]
Description=My_service

[Service]
Restart=always
ExecStart=/path/to/executable
ExecStop=/usr/bin/kill -HUP $MAINPID

[Install]
WantedBy=default.target

It's important that WantedBy is set to default.target.

Save the unit file, and reload the systemd daemon using the systemctl --user daemon-reload command. Enable and start the service as the user:

systemctl --user enable my_service.service
systemctl --user start my_service.service

Finally, run the loginctl enable-linger $USER command.

Give the notebook battery some TLC with TLP

Notebook batteries are fickle creatures. They don't like being charged to 100%. But they also not keen on being completely depleted. According to the conventional wisdom, to give your notebook's battery a long, productive, and healthy life, you should avoid charging it above 80% and discharging it below 25%.

Sounds simple, but how can you actually accomplish that without keeping your eyes peeled to the battery charge indicator? By letting the TLP worry about that. Install the tool on your system, configure battery charging thresholds, and leave it to TLP to take care of the rest. Here's how to do this on Linux Mint.

Continue reading

Language learning hack: Generate a "Word of the day" wallpaper

The best way to learn new words and phrases is to use them actively. The next-best way to learn new words is to be exposed to them as much as possible. And since the wallpaper that adorns my graphical desktop environment is what I stare at most of my waking hours, I thought that it'd only make sense to add words and phrases I want to memorize there.

Half an hour after the eureka moment, I had a working hack consisting of a plain text file with words and phrases along with their translations, a wallpaper template PNG file, and a simple Bash shell script. The latter pulls a random line from the text file, and uses the template to generate a new wallpaper with the picked line. Below are all the gory details worth knowing if you want to roll out something similar.

Continue reading