Skip to content

Instantly share code, notes, and snippets.

@fouad-j
Created November 25, 2016 20:24
Show Gist options
  • Select an option

  • Save fouad-j/8fca70a14b3b6f4943312c770c6c99e3 to your computer and use it in GitHub Desktop.

Select an option

Save fouad-j/8fca70a14b3b6f4943312c770c6c99e3 to your computer and use it in GitHub Desktop.

Revisions

  1. fouad-j created this gist Nov 25, 2016.
    85 changes: 85 additions & 0 deletions ecran2.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,85 @@
    #! /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