Advertisement
metalx1000

xrandr fzf script for Linux Displays

Dec 12th, 2021
2,061
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.76 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2021 Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20. default_resolution="1920x1080"
  21.  
  22. function main(){
  23.   display="$(get_display)"
  24.   resolution="$(get_resolution)"
  25.   position="$(get_position)"
  26.   display2="$(get_display)"
  27.  
  28.   eval xrandr --output $display --mode $resolution $position $display2
  29.  
  30. }
  31.  
  32. function error(){
  33.   echo $*
  34.   exit 1
  35. }
  36.  
  37. function get_position(){
  38.   p="$(echo -e "--right-of\n--left-of\n--above\n--below\n--same-as"|fzf --prompt "Select a position: ")"
  39.   [[ "$p" == "" ]] && error "No Position Selected."
  40.   echo "$p"
  41. }
  42.  
  43. function get_resolution(){
  44.   r="$(xrandr |grep "^   "|awk '{print $1}'|sort -u;echo "$default_resolution")"
  45.   r="$(echo -e "$r" |fzf --tac --prompt "Select a resolution: ")"
  46.   [[ "$r" == "" ]] && error "No Resolution Selected."
  47.   echo $r
  48. }
  49.  
  50. function get_display(){
  51.   d="$(xrandr |grep " connected "|awk '{print $1}'|fzf --prompt "Select a display: ")"
  52.   [[ "$d" == "" ]] && error "No Display Selected."
  53.   echo "$d"
  54. }
  55.  
  56. main $*
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement