Skip to content

Instantly share code, notes, and snippets.

@luismrsilva
Last active October 10, 2021 14:04
Show Gist options
  • Save luismrsilva/07b280d990ae26d038310219c1e1a742 to your computer and use it in GitHub Desktop.
Save luismrsilva/07b280d990ae26d038310219c1e1a742 to your computer and use it in GitHub Desktop.
Present a menu to select and apply a screen layout script
#!/bin/bash
# present a menu to select and apply a screen layout script
# requires "arandr" and "dialog" package
# to run with hotkeys, use:
# lxterminal -e choose-layout.sh
# 2018-11-27 L
# from https://gist.github.com/luismrsilva/07b280d990ae26d038310219c1e1a742
# (c) 2018 luismrsilva
LAYOUTS_DIR="$HOME/.screenlayout"
########
MENU="Choose a screen layout script"
HEIGHT=18
WIDTH=50
CHOICE_HEIGHT=10
OPTIONS="1 arandr 2 lxrandr"
OPTIONS_ARR[1]="arandr"
OPTIONS_ARR[2]="lxrandr"
OPTION_COUNT=2
for file in `find $LAYOUTS_DIR -type f -iname "*.sh"`
do
OPTION_COUNT=$((OPTION_COUNT+1))
#echo $file
LAYOUT_NAME=$(basename "$file")
OPTIONS="$OPTIONS $OPTION_COUNT $LAYOUT_NAME"
OPTIONS_ARR[$OPTION_COUNT]="$LAYOUT_NAME"
done
function show_dialog(){
dialog --clear \
--title "Screen Layout" \
--menu "$MENU" $HEIGHT $WIDTH $CHOICE_HEIGHT \
"$@" \
2>&1 > /dev/tty
}
OPTION=$(show_dialog $OPTIONS)
echo $OPTION
TO_RUN="${OPTIONS_ARR[$OPTION]}"
echo $TO_RUN
if [[ $TO_RUN =~ ^.*sh$ ]]; then
echo "OK! (script)"
echo "$LAYOUTS_DIR/$TO_RUN"
"$LAYOUTS_DIR/$TO_RUN"
elif [[ $TO_RUN =~ ^arandr$|lxrandr$ ]]; then
echo "OK! (absolute)"
"$TO_RUN"
else
echo "NOK"
exit -1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment