Adding Space Before Equals in Git Prompt

I like using Git-Prompt to decorate my bash prompt. It’s nice, simple, and it would be perfect if it didn’t put equals next to branch name. Not sure what I’m talking about?

If you have modified files, Git-Prompt will make sure to let you know by writing master %= in prompt line. If you want to quickly copy branch name, you simply double click it and only master is selected. However, when there are no modifications to Git tree, output will be master=. Notice the lack of space. When you double click on this, both branch name and equals sign get copied. What I want is to have a space no matter whether branch is modified or not.

Cause for this issue can be found in the following line

local gitstring="$c$b^^${f:+$z$f}^^$r$p"

This makes it for that extra flags get space. If there are no flags, there is no space. Solution is simple - just add space always thus changing line like this:

local gitstring="$c$b$z$f$r$p"

Or, if you like to do it programmatically:

sed -i 's/local gitstring=.*/local gitstring=$c$b$z$f$r$p/' ~/.git-prompt.sh

PS: If you are wondering, this is how my prompt setup looks:

LC_COLLATE=C

if [ -f ~/.git-prompt.sh ]; then
    GIT_PS1_SHOWDIRTYSTATE=true
    GIT_PS1_SHOWSTASHSTATE=true
    GIT_PS1_SHOWUNTRACKEDFILES=true
    GIT_PS1_SHOWUPSTREAM="auto"
    GIT_PS1_STATESEPARATOR=" "
    GIT_PS1_DESCRIBE_STYLE="default"
    GIT_PS1_SHOWCOLORHINTS=true
    GIT_PS1_HIDE_IF_PWD_IGNORED=
    . ~/.git-prompt.sh
fi

function ps1_timer_start {
    PS1_TIMER=${PS1_TIMER:-$SECONDS}
}

function ps1_timer_stop {
    PS1_TIMER_VALUE=$(($SECONDS-$PS1_TIMER))
    if [[ $PS1_TIMER_VALUE -eq 0 ]]; then
        PS1_TIMER_VALUE=""
    elif [[ $PS1_TIMER_VALUE -lt 60 ]]; then
        PS1_TIMER_VALUE=" ${PS1_TIMER_VALUE}s"
    else
        PS1_TIMER_VALUE=" $((PS1_TIMER_VALUE / 60))m$((PS1_TIMER_VALUE % 60))s"
    fi
  unset PS1_TIMER
}

trap 'ps1_timer_start' DEBUG
PROMPT_COMMAND=ps1_timer_stop

PS1='\[\e[36m\]\n\u@\h\[\e[0m\] \w\[\e[34m\]$PS1_TIMER_VALUE\[\e[37m\] \[\e[36m\]\[\e[7m\]`__git_ps1 " %s "`\[\e[0m\]\n\[\e[36m\]\\$\[\e[0m\] '

Disabling USB Auto-Suspend on Ubuntu

These days Linux supports a lot of devices. However, occasionally you will find a device that works but only for a while, requiring a reboot to work again. This is often due to the device itself not behaving according to the USB standard, and that’s more often than not caused by misbehaving USB suspend.

The proper way of fixing this would be either a workaround in the driver or, God forbid, a fix in the device’s firmware. But quite often nobody does anything, so what’s left is to do the improper. And the easiest improper fix is to disable USB autosuspend.

For the command line, just add usbcore.autosuspend=-1 to GRUB_CMDLINE_LINUX_DEFAULT:

sudo sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="[a-z ]*/& usbcore.autosuspend=-1/' \
    /etc/default/grub

sudo update-grub2

reboot

Once the system is up, you can check that the value is indeed -1 (disabled).

cat /sys/module/usbcore/parameters/autosuspend

Increasing and Decreasing Surface Go Backlight on LXQt

Illustration

One annoying absence from LXQt is lack of keyboard support for backlight adjustment. Yes, you can adjust backlight from settings but doing so just via keyboard is not possible. Well actually it is, if you are willing to adjust system a bit.

The first order of business is installing Backlight Tracer. As of 0.1.1 this utility has ability of increasing/decreasing backlight via command line. Why would you need this? Well, this is so you can go to Preferences, LXQt settings, Shortcut Keys. There just add two new shortcuts: XF86MnBrightnessDown executing /usr/bin/backlight-decrease command. And a similar XF86MnBrightnessUp executing /usr/bin/backlight-increase.

Now you can use your laptop keyboard to control backlight.

Determine Client WiFi Channel on Linux

If you have network with the same name on both 2.4 and 5 GHz it might not be obvious which network you are connected too. Well, on Linux, it’s easy enough - use iwlist utility.

If you run it with frequency as an argument you’ll get list of all supported channels followed by currently used channel.

iwlist frequency
 wlp4s0    32 channels in total; available frequencies :
           Channel 01 : 2.412 GHz
           Channel 02 : 2.417 GHz
           Channel 03 : 2.422 GHz
           Channel 04 : 2.427 GHz
           Channel 05 : 2.432 GHz
           Channel 06 : 2.437 GHz
           Channel 07 : 2.442 GHz
           Channel 08 : 2.447 GHz
           Channel 09 : 2.452 GHz
           Channel 10 : 2.457 GHz
           Channel 11 : 2.462 GHz
           Channel 12 : 2.467 GHz
           Channel 13 : 2.472 GHz
           Channel 36 : 5.18 GHz
           Channel 40 : 5.2 GHz
           Channel 44 : 5.22 GHz
           Channel 48 : 5.24 GHz
           Channel 52 : 5.26 GHz
           Channel 56 : 5.28 GHz
           Channel 60 : 5.3 GHz
           Channel 64 : 5.32 GHz
           Channel 100 : 5.5 GHz
           Channel 104 : 5.52 GHz
           Channel 108 : 5.54 GHz
           Channel 112 : 5.56 GHz
           Channel 116 : 5.58 GHz
           Channel 120 : 5.6 GHz
           Channel 124 : 5.62 GHz
           Channel 128 : 5.64 GHz
           Channel 132 : 5.66 GHz
           Channel 136 : 5.68 GHz
           Channel 140 : 5.7 GHz
         ^^Current Frequency=2.462 GHz (Channel 11)^^

LXQt High DPI Settings For Surface Go

Ubuntu Unity on the Surface Go is not the lightest environment out there. And on device with low memory (mine has only 4 GB) there is a definite need for something lighter. Based on my research, there are three comfortable alternatives: Xfce, LXDE, and LXQt. After a bit of testing, I decided to go with LXQt.

Installing LXQt into existing ubuntu is as easy as installing its package and selecting it on next login:

sudo apt install lxqt

What greets you are really small window elements and almost impossible to read interface. LXQt does not detect high-DPI environment and thus 1800x1200 Surface Go has to offer is used as if screen was 24" and not mere 10" in size.

Fortunately, there is a forum with high DPI advice. Unfortunately, a lot of those advices are not really applicable when it comes to Ubuntu 19.10. To spare you a lot of research, here is what worked for me.

Illustration

The first argument you will want to adjust is QT_AUTO_SCREEN_SCALE_FACTOR=2. Forum advice is to adjust QT_SCALE_FACTOR=2 but I found this to be counter productive as properly written Qt applications will have their size quadrupled. Yes, you can use QT_SCALE_FACTOR=2 combined with QT_AUTO_SCREEN_SCALE_FACTOR=0 but that still leaves you with increased toolbar icons in high-DPI aware applications. So, for my use case, just setting QT_AUTO_SCREEN_SCALE_FACTOR=2 worked the best.

Small cursor is also a problem but there is an easy way to correct this. Most often I found setting XCURSOR_SIZE=32 mentioned but I personally like to go with XCURSOR_SIZE=48.

That said, where do you set them? Just go to Preferences, LXQt settings, Session Settings, Environment (Advanced) and add those two environment variables.

Those two changes will make your Qt applications look bigger but non-Qt applications like Chrome will still look way too tiny. For those you need to set Xft.dpi in ~/.Xresources.

echo "Xft.dpi: 192" > ~/.Xresources

With these three changes I find windows once again reasonably sized on my Surface Go.