Created
June 18, 2018 21:29
-
-
Save rjfonseca/4843233bc4b14d8a1dd2e276746b6cdb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HDMI=HDMI1 | |
EDP=eDP1 | |
if xrandr | grep -q "${HDMI} disconnected"; then | |
dmode=disconnected | |
else | |
dmode=connected | |
fi | |
BG=$HOME/pics/wallpaper.png | |
MODE='--right-of' | |
ROTATE='' | |
function print_usage { | |
cat <<EOF | |
Usage: display.sh [OPTIONS] | |
This program checks if there is a second monitor conected and | |
configures X to use multiple displays using xrandr. | |
Options: | |
-m,--mirror Acivates mirror mode. Default is extended mode. | |
-d,--disconected Turn off the second display. | |
-b,--background Sets background image. Default is ${BG} | |
-r,--rotate Sets background image. Default is ${BG} | |
-h,--help Diplays this text | |
EOF | |
} | |
while [[ $# -gt 0 ]] | |
do | |
case $1 in | |
-m|--mirror) | |
MODE='--same-as' | |
;; | |
-d|--disconnected) | |
dmode=disconnected | |
;; | |
-b|--background) | |
if [[ ! -f $2 ]]; then | |
echo "File not found: $2" | |
exit 1 | |
fi | |
BG=$2 | |
shift | |
;; | |
-r|--rotate) | |
ROTATE='--rotate left' | |
;; | |
-h|--help) | |
print_usage | |
exit 0 | |
;; | |
*) | |
echo "Unknown option: $1" | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
# I have doubts about this next config | |
# This script is called as root and without X knowledge | |
#export DISPLAY=:0.0 | |
if [ "${dmode}" = disconnected ]; then | |
echo "Setting single monitor" | |
xrandr --output $EDP --auto --output $HDMI --off | |
elif [ "${dmode}" = connected ]; then | |
echo "Setting dual monitor" | |
xrandr --output $EDP --primary --auto \ | |
--output $HDMI \ | |
--auto \ | |
${ROTATE} \ | |
${MODE} $EDP | |
else | |
echo "Ops... I don't undestand ${dmode}" | |
exit 1 | |
fi | |
# Set wallpaper | |
feh --no-fehbg --bg-scale ${BG} | |
# set random wallpaper from directory | |
#feh --no-fehbg --bg-scale $(find ~/pics/stellaris -type f | shuf -n 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment