Last active
July 4, 2020 22:49
-
-
Save stephan49/561d0e473dddb270be3da6a8ca994306 to your computer and use it in GitHub Desktop.
Fixes texture corruption in VS Code terminal after resuming from suspend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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. | |
| # | |
| # Dependencies: jq | |
| case "$1" in | |
| post) | |
| # Check if VS Code is running | |
| if [ -z "$(pgrep -x code)" ]; then | |
| exit 0 | |
| fi | |
| user=$(cut -d " " -f 1 <<< $(users)) | |
| settings_file="/home/$user/.config/Code/User/settings.json" | |
| # Check if settings file is a symlink | |
| if [ -L "$settings_file" ]; then | |
| settings_link=$settings_file | |
| settings_file=$(readlink $settings_file) | |
| fi | |
| # Create backup of settings | |
| backup_file="/home/$user/.config/Code/User/settings.json.bak" | |
| if [ ! -e "$backup_file" ]; then | |
| cp $settings_file $backup_file | |
| fi | |
| # Before overwriting, ensure settings file is not truncated from errors | |
| tmp_file='/tmp/settings.json' | |
| overwrite() { | |
| local tmp_file_lines=$(wc -l $tmp_file | cut -d " " -f 1) | |
| if [ "$tmp_file_lines" -le 1 ]; then | |
| rm $tmp_file | |
| exit 1 | |
| else | |
| chown $user:$user $tmp_file | |
| mv $tmp_file $settings_file | |
| if [ ! -z ${settings_link+x} ]; then | |
| touch -h $settings_link | |
| fi | |
| fi | |
| } | |
| # Wait for screen unlock | |
| tail -f /var/log/auth.log -n 1 | sed '/unlocked login keyring/ q;/Power key pressed/ q' | |
| # Get current zoom level | |
| zoom_level=$(jq '.["window.zoomLevel"]' $settings_file) | |
| # Add missing key if required | |
| if [ "$zoom_level" = "null" ]; then | |
| jq '. + { "window.zoomLevel": 0 }' $settings_file > $tmp_file | |
| overwrite | |
| fi | |
| # Change zoom level | |
| let zoom_level++ | |
| jq '.["window.zoomLevel"] = $zoom' --argjson zoom $zoom_level \ | |
| $settings_file > $tmp_file | |
| overwrite | |
| sleep 0.5 | |
| let zoom_level-- | |
| jq '.["window.zoomLevel"] = $zoom' --argjson zoom $zoom_level \ | |
| $settings_file > $tmp_file | |
| overwrite | |
| ;; | |
| esac |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good catch @Fmstrat, thank you. I've updated my script to include that as well.