<commit_before>#!/bin/sh
# auto config new screen
# screen are considered in one line
# a new screen will be added to the right of the previous screen

if [ -n "$DISPLAY" -a ! -f /tmp/.display ]
then
    echo "$DISPLAY" > /tmp/.display
else
    DISPLAY=$(cat /tmp/.display)
    export DISPLAY
fi

if [ -n "$XAUTHORITY" -a ! -f /tmp/.xauthority ]
then
    echo "$XAUTHORITY" > /tmp/.xauthority
else
    XAUTHORITY=$(cat /tmp/.xauthority)
    export XAUTHORITY
fi

# XXX override xrandr command to only call it once
_xrandr=$(xrandr)
xrandr() {
    echo "$_xrandr"
}

cmd=''

nb_connected=$(xrandr | grep -c ' connected ')
nb_disconnected=$(xrandr | grep -c 'disconnected [0-9]')
nb_diff=$(($nb_connected - $nb_disconnected))

disconnected=$(xrandr | grep 'disconnected [0-9]' | cut -d ' ' -f 1)
for output in $disconnected
do
    # XXX keep always one screen to avoid killing the current session
    if [ "${nb_diff}" -eq 1 -a "${nb_disconnected}" -gt 1 ]
    then
        cmd="${cmd} --output ${output} --off"
    else
        cmd="${cmd} --output eDP1 --preferred --scale 1x1"
        cmd="${cmd} --output ${output} --off"

        command xrandr $cmd
        exit 0
    fi
    nb_disconnected=$(($nb_disconnected - 1))
done

connected=$(xrandr | grep ' connected (' | cut -d ' ' -f 1)

clones=$(xrandr | awk '/(+[0-9]{1,4}){2}/{print $1}')<commit_msg>Refactoring on how to handle disconnected screen<commit_after>#!/bin/sh
# auto config new screen
# screen are considered in one line
# a new screen will be added to the right of the previous screen

if [ -n "$DISPLAY" -a ! -f /tmp/.display ]
then
    echo "$DISPLAY" > /tmp/.display
else
    DISPLAY=$(cat /tmp/.display)
    export DISPLAY
fi

if [ -n "$XAUTHORITY" -a ! -f /tmp/.xauthority ]
then
    echo "$XAUTHORITY" > /tmp/.xauthority
else
    XAUTHORITY=$(cat /tmp/.xauthority)
    export XAUTHORITY
fi

# XXX override xrandr command to only call it once
_xrandr=$(xrandr)
xrandr() {
    echo "$_xrandr"
}

cmd=''

nb_connected=$(xrandr | grep -c ' connected [0-9]')
disconnected=$(xrandr | grep 'disconnected [0-9]' | cut -d ' ' -f 1)
if [ "${nb_connected}" -eq 0 ]
then
    # XXX keep always one screen to avoid killing the current session
    cmd="${cmd} --output eDP1 --preferred --scale 1x1"
    disconnected="echo ${disconnected} | grep -v eDP1"
fi

for output in $disconnected
do
    cmd="${cmd} --output ${output} --off"
done

connected=$(xrandr | grep ' connected (' | cut -d ' ' -f 1)

clones=$(xrandr | awk '/(+[0-9]{1,4}){2}/{print $1}')
{'fraction_non_alphanumeric': 0.16028708133971292, 'fraction_numerical': 0.014354066985645933, 'mean_word_length': 3.1266447368421053, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1412203', 'n_tokens_mistral': 918, 'n_tokens_neox': 891, 'n_words': 286}