Advertisement
Tamius_Han

Untitled

May 16th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.67 KB | None | 0 0
  1. #! /bin/bash
  2. kquitapp plasma-desktop
  3.  
  4. xtvga=$(xrandr | grep -c "VGA-0 connected")
  5. xthdmi=$(xrandr | grep -c "HDMI-0 connected")
  6. xtmon=$(($xtvga + $xthdmi))
  7. restartArg=1                    #If 1, plasma-desktop is up for a restart.
  8. doBackup=0
  9. isTest=0
  10. lastused="single"
  11.  
  12. function checkExistence {
  13.     if [ ! -d "/home/tamius-han/.kde/share/config/last" ]; then
  14.     mkdir "/home/tamius-han/.kde/share/config/last"
  15.     mkdir "/home/tamius-han/.kde/share/config/last/single"
  16.     fi
  17.     for f in "left-of" "right-of" "above" "below" "same-as" "off" "single" ; do
  18.     if [ ! -d "/home/tamius-han/.kde/share/config/configs/$f" ]; then
  19.           mkdir /home/tamius-han/.kde/share/config/configs/$f
  20.           cp /home/tamius-han/.kde/share/config/* /home/tamius-han/.kde/share/config/configs/$f
  21.     fi
  22.     done
  23. }
  24.  
  25. function backup {
  26.       lastused=single
  27.       for f in "left-of" "right-of" "above" "below" "same-as" "off" "single" ; do
  28.       if [ -d "/home/tamius-han/.kde/share/config/last/$f" ]; then
  29.           lastused=$f
  30.       fi
  31.       done
  32.       rm -rf "/home/tamius-han/.kde/share/config/last/$lastused"
  33.       mkdir "/home/tamius-han/.kde/share/config/last/$1"
  34.       cp /home/tamius-han/.kde/share/config/* /home/tamius-han/.kde/share/config/configs/$lastused
  35. }
  36.  
  37. function recfg-multi {              #Reconfigures monitors and restarts that shit.
  38.       checkExistence
  39.       backup $1     #$1 tells backup which config we're importing so it gets backed up properly next time we run this script.
  40.     # $1 — tells location of the secondary monitor (left, right, upwards, downwards of LVDS, duplicate of LVDS, etc.)
  41.     # $2 — tells if it's primary monitor (not yet implemented)
  42.     # $3 — tells if it's mirror over x (not even close ti implementing)
  43.       if [ $xtvga == 1 ] ; then
  44.       loldefined="VGA-0"
  45.       echo "We detected secondary output on VGA-0."
  46.       fi
  47.       if [ $xthdmi == 1 ] ; then
  48.       loldefined="HDMI-0"]
  49.       echo "We detected secondary output on HDMI-0."
  50.       fi
  51.      
  52.      
  53.     xrandr --output LVDS --auto
  54.       xrandr --output $loldefined --$1 LVDS --auto
  55.      # if [ $2 == "primary" ] ; then
  56.       xrandr --output $loldefined --primary
  57.      # fi
  58.       echo "New display has been placed $1 the previous one. Resolution has been set on prefered value."      
  59.     rm /home/tamius-han/.kde/share/config/* #Deleting old configs
  60.     cp /home/tamius-han/.kde/share/config/configs/$1/* /home/tamius-han/.kde/share/config  
  61.     echo "Copying = finito"
  62. }
  63. echo "-----------------------------------"
  64. echo "Number of external monitors: $xtmon"
  65. echo "VGA-0: $xtvga"
  66. echo "HDMI-0: $xthdmi"
  67. echo "restartArg: $restartArg"
  68. echo "doBackup: $doBackup"
  69. echo "whoami: tamius-han"
  70. echo "-----------------------------------"
  71.  
  72.  
  73. if [ $xtmon == 1 ] ; then
  74.     #default values
  75.     echo "xtmon = 1"
  76.    
  77.     monlayout="left-of"
  78.     for f in "left-of" "right-of" "above" "below" "same-as" "off" "last" "single" ; do
  79.     if [ "$1" = "$f" ] ; then
  80.         monlayout=$f
  81.     fi
  82.     done
  83.     #if [ "$monlayout" = "$(ls /home/tamius-han/.kde/share/config/last/)" ] ; then
  84.     #exit 0
  85.     #fi
  86.     recfg-multi $monlayout
  87.    
  88. fi
  89. if [ $xtmon == 0 ] ; then
  90.     #if [ "single" = "$(ls /home/tamius-han/.kde/share/config/last/)" ] ; then
  91.     #exit 0
  92.     #fi
  93.  
  94.     backup single
  95.    
  96.     echo "No external monitors are connected."
  97.     xrandr --output VGA-0 --off
  98.     xrandr --output HDMI-0 --off
  99.     xrandr --output LVDS --auto
  100.     echo "All displays have been removed."
  101.        
  102.  
  103.     cp /home/tamius-han/.kde/share/config/configs/single/* /home/tamius-han/.kde/share/config
  104.  
  105.     echo "Single monitor configuration pulled from the storage."
  106.    
  107. fi
  108. # echo "Chown to all!"
  109. # chown -R tamius-han /home/tamius-han/.kde/share/
  110. kstart plasma-desktop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement