Skip to content

Instantly share code, notes, and snippets.

@frafra
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frafra/babfe4c32478923687ea to your computer and use it in GitHub Desktop.
Save frafra/babfe4c32478923687ea to your computer and use it in GitHub Desktop.
Disable ghosts video outputs on Linux
#!/bin/bash -e
#
# How to run this script:
# $ (source <(curl https://gist.githubusercontent.com/frafra/babfe4c32478923687ea/raw))
DIR=/sys/class/drm
REGEX="(card[0-9]+-(.+))"
OUTPUTS=($(for f in $DIR/*
do [[ $f =~ $REGEX ]] && echo ${BASH_REMATCH[1]} || true
done))
echo "Video outputs:"
i=1
for output in ${OUTPUTS[@]}
do
echo "$i) $output " $(cat $DIR/$output/{status,enabled})
let i++
done | column -t
read -p "Select video output [1-${#OUTPUTS[@]}]: " id
[[ $id -ge 1 && $id -le ${#OUTPUTS[@]} ]] || exit 1
let id--
[[ ${OUTPUTS[$id]} =~ $REGEX ]] || exit 1
pkexec sed -ri 's/(GRUB_CMDLINE_LINUX=)"(.*)"/\1"\2 video='${BASH_REMATCH[2]}':d"/' /etc/sysconfig/grub
for f in /boot/{grub2,efi/EFI/fedora}/grub.cfg
do [ -f $f ] && pkexec grub2-mkconfig -o $f
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment