Skip to content

Instantly share code, notes, and snippets.

@fouad-j
Created November 25, 2016 20:24
Show Gist options
  • Save fouad-j/8fca70a14b3b6f4943312c770c6c99e3 to your computer and use it in GitHub Desktop.
Save fouad-j/8fca70a14b3b6f4943312c770c6c99e3 to your computer and use it in GitHub Desktop.
Add new resolution for an additional screen
#! /bin/sh
########################################################
# Auteur : Fouad JADOUANI <[email protected]>
# Description : Ajoute une nouvelle resolution pour un
# ecran additionel s'elle n'existe pas
################
# French documentation : http://doc.ubuntu-fr.org/xrandr
# Version 1.0
###############
# Historique :
# 07/04/2015 (1.0) :
# Ecriture initiale
set -u
width=1280;
height=1024;
frequency=60;
connector="VGA-0" # look at the CMD 'xrandr' to see the name of your connector
interative=false
OPTERR=0
while getopts ":r:f:c:hi" option ; do
case $option in
r )
if echo $OPTARG | grep -E "^[0-9]{3,4}x[0-9]{3,4}$" > /dev/null 2>&1 ; then
width=${OPTARG%%x*}; height=${OPTARG##*x};
else
echo "L'argument de -r (resolution) doit etre sous cette forme 1280x1024 !" >&2;
exit 1;
fi
;;
f )
if echo $OPTARG | grep -E "^[0-9]{2,}$" > /dev/null 2>&1 ; then
frequency=$OPTARG;
else
echo "L'argument de -f (frequnce) doit etre un nombre !" >&2;
exit 1;
fi
;;
c ) connector=$OPTARG ;;
i ) interative=true ;;
h )
cat <<- FIN
Usage : $0 [option ...]
Options:
-r Resolution (Ex: 1280x1024)
-f Frequence (Ex: 60)
-c Connecteur (Ex: HDMI-0) verifiez avec la cmd 'xrandr' le nom du connecteur
-i Mode interative pour confirmer les infos avant de valider
-h Aide
FIN
exit 0;
;;
: ) echo "Argument manquant pour l'option -$OPTARG\n" >&2; $0 -h; exit 1 ;;
? ) echo "Option -$OPTARG inconnue\n" >&2; $0 -h; exit 1 ;;
esac
done
shift $((OPTIND - 1));
# verifier s'il y a un argument inconnu
if [ $# != '0' ] ; then
echo "Argument '$1' inconnu" >&2; $0 -h; exit 1;
fi
if [ $interative = 'true' ] ; then
echo "Resolution:${width}x${height}, Frequence:${frequency}, Connecteur:${connector}";
while true ; do
echo -n "Voulez vous continuer (y/n) ? : ";
read rep
case $rep in
[yY] ) break; ;;
[nN] ) exit 0; ;;
* ) echo "Choix inconnu"; ;;
esac
done
fi
xrandr --newmode $(gtf ${width} ${height} ${frequency} | sed -ne 's/"//g;s/ Modeline //p')
xrandr --addmode ${connector} ${width}x${height}_${frequency}.00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment