Skip to content

Instantly share code, notes, and snippets.

@rindPHI
Created November 30, 2016 08:17
Show Gist options
  • Save rindPHI/8025124a6fbcec9eee25a4cc1b8d75ca to your computer and use it in GitHub Desktop.
Save rindPHI/8025124a6fbcec9eee25a4cc1b8d75ca to your computer and use it in GitHub Desktop.
An interactive script for the fish shell, managing the connection to connected screens / beamers especially in cases where the beamer is not recognized, and therefore the normal (graphical) system configuraion tools fail.
#!/usr/bin/fish
set fish_greeting
function res_x_prompt
echo -n 'Please enter the horizontal resolution [1024]: '
end
function res_y_prompt
echo -n 'Please enter the vertical resolution [768]: '
end
function res_rate_prompt
echo -n 'Please enter the refresh rate [60]: '
end
function output_prompt
echo -n 'Press enter too keep the current selection[*],
or enter your choice: '
end
function setup_prompt
echo -n 'Press enter too keep the current selection[*],
or enter your choice: '
end
# Reads an input into a global variable
# Param 1: Maximum number of characters
# Param 2: Function name of prompt
# Param 3: Name of resulting variable
# Param 4: Default value
function readln
read -n $argv[1] -g -p $argv[2] $argv[3]
echo -en "\033[1A\033[2K"
if [ $$argv[3] ]
else
# empty
set $argv[3] $argv[4]
end
end
readln 4 res_x_prompt resolution_x 1024
readln 4 res_y_prompt resolution_y 768
readln 2 res_rate_prompt rate 60
echo $resolution_x"x"$resolution_y"_"$rate".00" | read -l mode
echo $resolution_x"x"$resolution_y | read -l native_mode
echo
echo -e "Please choose an output:\n"
echo " Ouput Port Description"
echo "-------------------------------"
echo "* 1 DP-2 VGA"
echo " 2 DP-1 Display Port"
echo
readln 1 output_prompt beamer_no 1
math 3-$beamer_no | read -g beamer_no
echo "DP-"$beamer_no | read -l beamer
cvt $resolution_x $resolution_y $rate | tail -1 | sed 's/Modeline \(.*$\)/\1/' | read -l modeline
echo
echo -e "Please choose the desired setup:\n"
echo " Setup Description"
echo "------------------------------"
echo "* 1 Mirrored"
echo " 2 Beamer at the right"
echo " 3 Beamer at the left"
echo " 4 Beamer above"
echo " 5 Beamer below"
echo
readln 1 setup_prompt the_setup 1
switch $the_setup
case 1
set the_setup "--same-as"
case 2
set the_setup "--right-of"
case 3
set the_setup "--left-of"
case 4
set the_setup "--above"
case 5
set the_setup "--below"
end
# Now, we're actually using those settings
echo xrandr --newmode $modeline | xargs -0 bash -c
xrandr --addmode $beamer "$mode" ; or echo "Adding the mode to $beamer did not succeed"
xrandr --addmode eDP-1 "$mode" ; or echo "Adding the mode to the internal display did not succeed"
xrandr --output eDP-1 --mode "$native_mode"
xrandr --output $beamer --mode "$mode" $the_setup eDP-1 ; or echo "Applying the chosen setup did not succeed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment