Skip to content

Instantly share code, notes, and snippets.

@jimbert
Created July 28, 2020 17:34
Show Gist options
  • Save jimbert/4789f478868c24f568cdbee59426792b to your computer and use it in GitHub Desktop.
Save jimbert/4789f478868c24f568cdbee59426792b to your computer and use it in GitHub Desktop.
Set custom screen resolutions
#!/usr/bin/env bash
# Sets custom screen resolution using xrandr and gtf.
# Usage: sh set_resolution.sh <x_resolution> <y_resolution> <refresh_rate>
# 1080p: sh set_resolution.sh 1920 1080 60
# 1440p: sh set_resolution.sh 2560 1440 60
# Pixelbook: sh set_resolution.sh 2400 1600 60
xres=$1
yres=$2
refresh=$3
gtf_result=`gtf $1 $2 $3 | sed 's/.*Modeline //' | grep \"`
mode_name=`echo $gtf_result | cut -d' ' -f1 | sed 's/"//g'`
mode_config=`echo $gtf_result | cut -d' ' -f2-`
if ! [[ $(xrandr | grep $mode_name) ]]; then
echo 'creating mode'
xrandr --newmode $mode_name $mode_config
xrandr --addmode screen $mode_name
fi
xrandr --output screen --mode $mode_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment