Categories
Code

Navigating Maven projects on the command line

Or how to avoid..

~/dev/myproject/src/main/java/com/example/foo $ cd ..
~/dev/myproject/src/main/java/com/example $ cd ..
~/dev/myproject/src/main/java/com $ cd ..
~/dev/myproject/src/main/java $ cd ../../..
~/dev/myproject $

This following Bash shell function, which is called pom.. (yes with two dots in the name), will allow you to navigate up to the closest ancestor directory containing a pom.xml file (closest module) with one command. Put it in your ~/.bashrc:

function pom..() {
    local start_dir="$(pwd)" prev_dir= rel_dir="$1"
    while [ "$prev_dir" != "$(pwd)" ]; do
        prev_dir="$(pwd)"
        cd ..
        if [ -f pom.xml ]; then
            if [ -d "$rel_dir" ]; then
                cd "$rel_dir"
            elif [ "$rel_dir" ]; then
                echo >&2 "Directory not found relative to pom.xml: $(pwd)/$rel_dir"
                cd "$start_dir"
                return 1
            fi
            pwd|sed "s#^$HOME#~#"
            return 0
        fi
    done
    echo >&2 "No pom.xml found in ancestor directories."
    cd "$start_dir"
    return 1
}

So you don’t have to waste any more time typing “cd ..” multiple times when navigating upwards to a Maven module root on the command line. Just type pom.. once.

~/dev/myproject/src/main/java/com/example/foo $ pom..
~/dev/myproject
~/dev/myproject $ 

It also accepts an optional argument, which is a desired directory relative to the nearest POM:

~/dev/myproject/src/main/java/com/example/foo $ pom.. target
~/dev/myproject/target
~/dev/myproject/target $ pom.. src/test
~/dev/myproject/src/test
~/dev/myproject/src/test $

The strategy will work for any style of hierarchically organized source code project where a typical marker file or directory exists at certain source code roots. Just be creative and modify the code.

Also, see this post for a more general approach to project directory navigation.

Categories
Hardware Linux

Ubuntu 20.04 on Thinkpad T14 gen 2 (Intel)

AnnouncedLate 2021
CPU, GPU, RAMIntel i5-1135G7 @ 2.40GHz 4 cores (8 threads), Iris Xe graphics, 16GiB soldered DDR4 3200 MHz (and one free slot for upgrades)
Screen14″ FHD (1920×1080) IPS 300nits Anti-glare
StorageSK Hynix NVMe 512GB
Lenovo part number 20W000R1MX (Lenovo Product Specification Reference)

TL; DR

This is a laptop with a slightly boring, but professional and discrete design, which I like. It’s a sturdy workhorse and has a quality feel to it – typical business segment. Overall Ubuntu Linux works great and this is probably as good as it gets regarding out of the box Linux compatibility, unless going for specialized commercial Linux offerings like a System76.

There are some issues with TrackPoint smoothness relating to kernel input drivers, and you may experience issues with the keyboard.

Read on for details.

What works fine

Installation alongside side Windows 10 Pro

For dual boot installation, I freed up around 300 GB of storage space for Ubuntu using Windows disk administration. Installation of Ubuntu 20.04 on new partition went without issues. Grub becomes primary boot loader with Windows as menu option.

Graphics and screen

Both Wayland and Xorg sessions work fine and perform well. Brightness controls are functional and screen is surprisingly bright and crisp.

Power management and cooling

The CPU cores are automatically clocked between 1,2GHz and 3,5GHz, depending on load. The fan rarely makes any noise at all on normal light weight usage, and it is subtle even when it needs to run faster.

The battery is a 51Wh SMP, and charge thresholds can be controlled at runtime. I typically set mine to stop charging at 85% when at home, to increase battery lifespan. You can control this by writing percentages to the files:

/sys/class/power_supply/BAT0/charge_stop_threshold
/sys/class/power_supply/BAT0/charge_start_threshold

The laptop has a USB-C port for charging, and when using the accompanying 65W A/C power supply, charging is fast. It will also accept charge from other power supplies, like common mobile quick chargers, but the BIOS may issue a warning on boot if the charger is too weak.

Update 2023-01-14: you can check out the following script for a handy tool that shows Thinkpad battery information on the command line. It also displays the charge stop and start thresholds.

Suspend to RAM

Suspend to RAM and resume works fine. There are some ACPI errors appearing in the kernel log upon resume:

ACPI BIOS Error (bug): Could not resolve symbol [\_SB.PC00.RP09.PEGP.DDNT], AE_NOT_FOUND (20210730/psargs-330)
[...]
ACPI Error: Aborting method \_SB.PC00.LPCB.EC.SEN4._TMP due to previous error (AE_NOT_FOUND) (20210730/psparse-529)

I haven’t look into these, probably buggy firmware code. It does not seem to cause any real problems.

Power usage in suspended state is nothing out of the ordinary. I would have liked to have hibernate option available, but this is apparently disabled due to locked down kernel and secure boot.

Audio

The HDA audio chip identifies as Realtek ALC257. I have not noticed any issues and it works well. The laptop speakers are a bit disappointing and sound rather weak, but I rarely rely on them anyway.

Wireless networking

The wifi chip is detected as Intel(R) Wi-Fi 6 AX201 160MHz, REV=0x354 by the iwlwifi driver. No issues experienced, wireless networking is solid.

Also note that there is no RJ45 ethernet port on this laptop model.

Bluetooth

Bluetooth is usually a bit buggy on Linux, and it can be a hit and miss experience, depending on the devices your are trying to connect. For the Thinkpad T14, it uses an Intel Bluetooth chip connected to the USB bus.

I’ve tested connectivity with a pair of Bose QC35 headsets and a Samsung Galaxy mobile phone, both work.

Special keys

Most Fn-special keys work fine: audio controls, mic mute, brightness, flight mode. There are some that generate no key events in Xorg: Fn+F9 through F11. These are labeled with symbols for chat, answer call and hangup call.

Firmware upgrades

The Thinkpad firmware can be automatically updated using the built-in fwupdmgr application. Which is a great improvement from earlier days of having to flash updates from thumb drives or being forced to use Windows.

Fingerprint reader

The fingerprint reader works out of the box. You can enroll your prints in the standard Ubuntu settings app.

Webcam

It works fine, but is only a 720p camera.

Problems 💀

Poor keyboard quality control

I noticed the left trackpad mouse button had erratic click detection – some clicks were missed. I primarily use the TrackPoint and rely on the physical mouse buttons beneath the space bar. Having premium on-site support, I decided to call for assistance, suspecting hardware malfunction. Lenovo sent a service technician a few days later, and the entire keyboard was replaced, at no additional cost. The new keyboard is fine.

Speaking of keyboard, the keys are a bit too hesitant and mushy for my taste. But solid.

TrackPoint cursor movement

TrackPoint cap
TrackPoint cap

The [Elan] TrackPoint cursor movement is slightly rough and jittery (using Xorg), resulting in reduced precision. It is almost like not enough input events are generated per time during movement. Also, the following message is printed in the kernel log:

psmouse serio1: synaptics: Your touchpad (PNP: LEN2072 PNP0f13) says it can support a different bus.
If i2c-hid and hid-rmi are not used, you might want to try setting psmouse.synaptics_intertouch to 1 and report this to linux-input@vger.kernel.org.

I have experimented with the suggested psmouse module setting, and it does indeed result in a smoother cursor. However, it also causes TrackPoint to randomly stop working, which is a deal breaker. I have not found a solution to this problem yet, but trust it will improve with future kernels.

Swapped Ctrl and Fn-keys

Thinkpads come with physically swapped left control and Fn-key compared to most keyboards. So you have this layout on the left bottom row:

[Fn] [Ctrl] [Win] [Alt] [ Space ] …

Being an Emacs user, this can be uncomfortable, since the distance between the control key and frequently used letter combinations is too short. Not to mention having to mentally re-calibrate your typing when switching between the Thinkpad and other keyboards. Fortunately the BIOS allows you to software swap the function of these keys, so the Fn-key becomes the left control. But the Fn-key is physically smaller and provides a poorer “left control experience”.


Show Thinkpad battery info on the command line

You can use the following shell script to check your battery vitals from the command line. Copy-paste the code into a file tpbinfo, save it somewhere in your PATH and make it executable with:
chmod +x tpbinfo

#!/bin/sh

set -e

cd /sys/class/power_supply/BAT0

exec awk '
  NR == 1 { cstop=$1 }
  NR == 2 { cstart=$1 }
  NR == 3 { status=$0 }
  NR == 4 { enow=$1 }
  NR == 5 { efull=$1 }
  NR == 6 { efull_design=$1 }

  END {
    charge_percent = (enow / efull) * 100
    capacity_percent = (efull / efull_design) > 1 ? 100 : (efull / efull_design)*100
    print "# Thinkpad battery info"
    printf("%-23s %.1f%%\n", "Charge:", charge_percent)
    printf("%-23s %s\n", "Status:", status)
    printf("%-23s %d%%\n", "Charge start threshold:", cstart)
    printf("%-23s %d%%\n", "Charge stop threshold:", cstop)
    printf("%-23s %d%%\n", "Capacity:", capacity_percent)
  }
' charge_stop_threshold charge_start_threshold status energy_now energy_full energy_full_design

Running tpbinfo produces something like the following output:

# Thinkpad battery info
Charge:                 79,2%
Status:                 Discharging
Charge start threshold: 70%
Charge stop threshold:  85%
Capacity:               99%
Categories
Other

Shall I gift wrap your browser monopoly, sir ?

Back in 2019 I write a post about the importance of supporting the Mozilla Firefox web browser:

I think standards are hugely important to keeping the web open and accessible for all, and I strongly dislike browser engine monopolies. Web publishing needs diversity in applications which consume, process and present the data, as a force that pulls it towards agreed upon and open standards.

https://stegard.net/2019/01/why-you-should-use-mozilla-firefox/

Fast forward three years, and the web is even closer to complete Google domination, with Firefox usage on the decline. By that, I mean Google controlling a browser with a market share close to 65%[1], and that’s not including all the Blink engine Chrome clones out there. If we include all of those browsers, the market share is over 70%[1]. Compare that with Mozilla Firefox’ current 3.3%[1] market share – and you get a truly unfortunate story. If you want a history lesson, in case you are too young to remember, check out the First browser war[3]. The bottom line is that it’s rarely, if ever, a good thing when a single profit driven entity controls important technology world wide at this scale. It takes away your freedom. The open web of information should belong the people and not corporations using the people as products.

I recently stumbled across a YouTuber by the name of Gardiner Bryant, and he has published a video where he elaborates on the issue of browser and web tech domination. I urge you to watch it and make up your own mind:

Video poster
Gardiner Bryant – Firefox is on the verge of extinction. What can they do about it?

https://www.youtube.com/watch?v=7xvtz3pN_Sw

I say well said. And in case you had forgotten; Mozilla Firefox is still a great open source browser, and you really need no political reasons to use and support it.

References

  1. https://gs.statcounter.com/, at time of publication
  2. https://www.youtube.com/watch?v=7xvtz3pN_Sw
  3. https://en.wikipedia.org/wiki/Browser_wars#First_Browser_War_(1995%E2%80%932001)