Skip to content

Instantly share code, notes, and snippets.

@Fmstrat
Last active July 3, 2020 12:13
Show Gist options
  • Save Fmstrat/7de01996206537b9dbc8f673b2c5ced2 to your computer and use it in GitHub Desktop.
Save Fmstrat/7de01996206537b9dbc8f673b2c5ced2 to your computer and use it in GitHub Desktop.
Fixes texture corruption in VS Code terminal after resuming from suspend
#!/bin/bash
#
# Fixes texture corruption in VS Code terminal after resuming from suspend.
#
# Place script in /lib/systemd/system-sleep/ so it can run after resuming
# and edit the CONFIG variable with the location of your settings.json
#
# Based of stephan-t's https://gist.github.com/stephan-t/561d0e473dddb270be3da6a8ca994306
# but without the jq requirement or 5s login delay and works with dotfiles (symlinks)
#
# Ref: https://github.com/microsoft/vscode/issues/69665
#
case "${1}" in
post|thaw)
TARGET_USER=$(users | awk '{print $1}')
CONFIG=/home/${TARGET_USER}/.config/Code/User/settings.json
if [ -n "$(pgrep -x code)" ]; then
tail -f /var/log/auth.log -n1 | sed '/unlocked login keyring/ q;/Power key pressed/ q'
ZOOM=$(grep "window.zoomLevel" ${CONFIG})
if [ -n "${ZOOM}" ]; then
ZOOM=${ZOOM##*:}
LASTCHAR="${ZOOM: -1}";
if [ "${LASTCHAR}" = "," ]; then
ZOOM=${ZOOM::-1}
else
LASTCHAR=""
fi
let ZOOM++
sed -i "s/\"window.zoomLevel\":.*/\"window.zoomLevel\": ${ZOOM}${LASTCHAR}/g" ${CONFIG}
else
ZOOM=1
LASTCHAR=","
sed -i 's/^{/{\n "window.zoomLevel": 1,/g' ${CONFIG}
fi
let ZOOM--
sleep 0.5
sed -i "s/\"window.zoomLevel\":.*/\"window.zoomLevel\": ${ZOOM}${LASTCHAR}/g" ${CONFIG}
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment