Running a MacBook Pro and MacBook Air at native resolution

I wrote displaymode, a simple command line utility for changing the resolution of the main display of a macOS machine. It lets you run Retina displays at their native resolution. For a recent 15″ MacBook Pro this means 2880×1800 and for the 2018 MacBook Air Retina, 2560×1600

The repository is at https://github.com/p00ya/displaymode and you can download a binary in the releases section.

To get native resolution on the MacBook Air, run:

./displaymode t 2560 1600

and on the MacBook Pro:

./displaymode t 2880 1800

Continue reading “Running a MacBook Pro and MacBook Air at native resolution”

Making zsh history conditional on command success

So I thought it would be useful to exclude failed commands from my on-disk zsh history, while still having them available in the in-memory history until the current shell exits. This means that when you’re trying to find the one magic incantation that works of some esoteric command that you haven’t used for years, you can just search for it in your history without fear of repeating old mistakes.

From my .zshrc:


# Prevent the command from being written to history before it's
# executed; save it to LASTHIST instead.  Write it to history
# in precmd.
#
# called before a history line is saved.  See zshmisc(1).
function zshaddhistory() {
  # Remove line continuations since otherwise a "\" will eventually
  # get written to history with no newline.
  LASTHIST=${1//\\$'\n'/}
  # Return value 2: "... the history line will be saved on the internal
  # history list, but not written to the history file".
  return 2
}

# zsh hook called before the prompt is printed.  See zshmisc(1).
function precmd() {
  # Write the last command if successful, using the history buffered by
  # zshaddhistory().
  if [[ $? == 0 && -n ${LASTHIST//[[:space:]\n]/} && -n $HISTFILE ]] ; then
    print -sr -- ${=${LASTHIST%%'\n'}}
  fi
}

Continue reading “Making zsh history conditional on command success”

Connecting to NBN HFC with a linux router

Update 2021-03-04: for a modern setup with dual-stack IPv4/IPv6 and systemd, see this post.

Internode recently migrated me from an ADSL connection to an NBN HFC connection. Here’s how I configured the connection using my own Debian GNU/Linux router instead of the TP-Link VR1600v internode supplies…

NBN Co supplies an Arris CM8200 NTD, which is a modem that bridges local ethernet to the ISP via DOCSIS over the coaxial cable.

Additionally, Internode’s configuration requires PPPoE encapsulation with 802.1q VLAN tagging.

I’m using physical interface eth1, so in /etc/network/interfaces I have:

# See interfaces(5)
auto eth1
iface eth1 inet static
    address 192.168.1.2/24

# VLAN ID 2 for Internode's NBN HFC.
auto eth1.2
iface eth1.2 inet manual

auto nbn
iface nbn inet ppp
    pre-up /bin/ip link set eth1.2 up
    provider nbn

Continue reading “Connecting to NBN HFC with a linux router”