| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 | 
							- #!/bin/bash
 
- # This is a simple program that toggles an external monitor on and off
 
- # using xrandr.
 
- # This program won't work out of the box. You will have to rename the variables
 
- # $Internal and $External to suit your needs.
 
- # i3-xrandr-toggle - A simple xrandr toggle addon
 
- # Copyright (C) 2017 Fabrizio Romano Genovese <egonigredo@gmail.com>
 
- # This copyrighted material is made available to anyone wishing to use,
 
- # modify, copy, or redistribute it subject to the terms and conditions of
 
- # the GNU General Public License v.2, or (at your option) any later version.
 
- #
 
- # This program is distributed in the hope that it will be useful, but WITHOUT
 
- # ANY WARRANTY expressed or implied, including the implied warranties of
 
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 
- # Public License for more details.
 
- # You should have received a copy of the
 
- # GNU General Public License along with this program; if not, 
 
- # see <http://www.gnu.org/licenses/>
 
- # Put this file in /bin/ or in /usr/bin. Do not forget to give 
 
- # sudo chmod +x i3-xrandr-toggle
 
- # to make it executable.
 
- version=1.0
 
- if [[ "$#" -ge 2 ]]; then
 
-         echo "Usage: $0 {-v, --version | -h --help}"
 
-         exit 2
 
- elif [[ "$#" -eq 1 ]]; then
 
-         case $1 in
 
-         -v | --version)
 
-                 echo "$0 - Version $version"
 
-                 exit 0;;
 
-         -h | --help)
 
-                 echo "This is a simple program that toggles an external monitor on and off using xrandr. This program won't work out of the box. You will have to rename the variables \$Internal and \$External in the script to suit your needs."
 
-                 echo "- v, --version            Display current version"
 
-                 echo "-h, --help                Display this message"
 
-                 exit 0;;
 
-         *)
 
-                 echo "Usage: $0 {-v, --version | -h, --help}"
 
-                 exit 2;;
 
-         esac
 
- fi
 
- Internal="eDP1"
 
- External="DP1-3"
 
- # Grep current external monitor status. Do noting if not connected
 
- if xrandr | grep "DP1-3 connected" > /dev/null; then
 
- # Check if the program has been used before. If yes, reads previous 
 
- # Status from a file. If not, initialises the variables.
 
- 	if [ ! -f "/tmp/monitor_mode.dat" ]; then
 
- 		monitor_mode="ON"
 
- 	else
 
- 		monitor_mode=`cat /tmp/monitor_mode.dat`
 
- 	fi
 
- 	
 
- 	if [ $monitor_mode = "OFF" ]; then
 
- 		monitor_mode="ON"
 
- 		xrandr -d :0.0 --output $External --auto
 
- 		xrandr -d :0.0 --output $Internal --auto
 
- 		xrandr -d :0.0 --output $External --right-of $Internal
 
- # Reloads background if using feh
 
-                 if [ -a "/bin/feh" ]; then
 
-                 ~/.fehbg
 
-                 fi
 
- 	else 
 
- 		monitor_mode="OFF"
 
- 		xrandr -d :0.0 --output $External --off 
 
- 		xrandr -d :0.0 --output $Internal --auto
 
- 	fi	
 
- # Rewrites the file for the next use.
 
- 	echo "${monitor_mode}" > /tmp/monitor_mode.dat
 
- fi
 
 
  |