Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 110 lines (97 sloc) 2.36 KB
#!/bin/bash
NAME="dldsply"
BLURB="Enable|disable extended desktop using XRandR"
SOURCE="https://github.com/vonbrownie/homebin/blob/master/dldsply"
set -eu
FOO=${1:-} # Script requires an option to be specified.
LAYOUT="--off"
Conf_homebin_lib() {
local LIB="https://github.com/vonbrownie/homebin/blob/master/Library.sh"
local HOMEBIN="$HOME/bin"
# A library of functions for shell scripts
local HOMEBIN_LIB="$HOMEBIN/Library.sh"
if [ -x "$HOMEBIN_LIB" ]; then
# shellcheck source=/dev/null
. $HOMEBIN_LIB
else
echo -e "\n(O<"
echo "(/)_ .: ERROR: I require '$HOMEBIN_LIB' to do my magic."
echo "Download script from $LIB and place in $HOMEBIN."
exit 1
fi
}
Hello_you() {
L_echo_yellow "\n$( L_penguin ) .: Howdy!"
cat << _EOF_
NAME
$NAME
SYNOPSIS
$NAME [ options ]
OPTIONS
-h print details
-l display layout is LEFT->RIGHT
-r display layout is RIGHT->LEFT
-q disable extended desktop
EXAMPLE
$BLURB.
Scenario: A large display on the LEFT connected to a laptop on the RIGHT.
The external display is the primary desktop, and when the cursor moves
past the right edge of the primary screen it emerges from the left edge
of the (secondary) laptop screen ...
$ ./$NAME -l
DEPENDS
bash, xrandr
SOURCE
$SOURCE
_EOF_
}
Conf_desktop() {
local DISPLAY1
DISPLAY1=$(xrandr | grep " connected" | awk 'FNR == 1 {print $1}')
local DISPLAY2
DISPLAY2=$(xrandr | grep " connected" | awk 'FNR == 2 {print $1}')
local DESKTOP="--output $DISPLAY1 --auto --output $DISPLAY2 --primary"
if [[ -n $DISPLAY2 ]]; then
if [[ $LAYOUT == "--off" ]]; then
/usr/bin/xrandr $DESKTOP $LAYOUT
else
/usr/bin/xrandr $DESKTOP --auto $LAYOUT $DISPLAY1
fi
fi
}
Run_options() {
# Verify an option has been specified.
if [[ -z $FOO ]]; then
L_echo_red "\n$( L_penguin ) .: ERROR: No option specified."
exit 1
fi
#
while getopts ":hlrq" OPT
do
case $OPT in
h)
Hello_you
exit
;;
l)
LAYOUT="--left-of"
;;
r)
LAYOUT="--right-of"
;;
q)
LAYOUT="--off"
;;
?)
L_echo_red "\n$( L_penguin ) .: ERROR: Invalid option '-$OPTARG'"
exit 1
;;
esac
done
}
# (O< .: Start
# (/)_
Conf_homebin_lib
Run_options "$@"
Conf_desktop
#L_all_done