Created
May 18, 2024 10:28
-
-
Save naranyala/30139dc9cc7d0494e6b6394e31856df4 to your computer and use it in GitHub Desktop.
setup redshift in-range using rofi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Parses command-line arguments and executes the appropriate action | |
parse_args() { | |
case $1 in | |
-r | --reset) | |
reset_temperature | |
;; | |
-t | --temperature) | |
if [ -n "$2" ]; then | |
set_temperature "$2" | |
else | |
echo "Error: Temperature option requires an argument" | |
exit 1 | |
fi | |
;; | |
-h | --help) | |
usage | |
;; | |
*) | |
echo "Error: Invalid option '$1'" | |
usage | |
;; | |
esac | |
} | |
# Generates a list of color temperature labels for selection | |
generate_menu() { | |
echo "Very High" | |
echo "High" | |
echo "Medium" | |
echo "Low" | |
echo "Very Low" | |
} | |
# Maps the selected label to a color temperature and sets it | |
set_temperature() { | |
local label=$1 | |
local temp | |
case $label in | |
"Very High") temp=1900 ;; | |
"High") temp=3700 ;; | |
"Medium") temp=5500 ;; | |
"Low") temp=7500 ;; | |
"Very Low") temp=10000 ;; | |
*) | |
echo "Invalid selection" | |
exit 1 | |
;; | |
esac | |
redshift -O "$temp" | |
} | |
# This function integrates with Rofi | |
rofi_menu() { | |
generate_menu | rofi -dmenu -p "Redshift Temperature:" -lines 5 -width 25 | |
} | |
# Reset the color temperature to default | |
reset_temperature() { | |
redshift -x | |
} | |
# Displays usage information | |
usage() { | |
echo "Usage: redshift-selector.sh [OPTIONS]" | |
echo "Options:" | |
echo " -t, --temperature <label> Set the color temperature" | |
echo " -r, --reset Reset the color temperature to default" | |
echo " -h, --help Display this help message" | |
exit 0 | |
} | |
# Main logic | |
if [ $# -eq 0 ]; then | |
selection=$(rofi_menu) | |
if [ -n "$selection" ]; then | |
reset_temperature | |
set_temperature "$selection" | |
fi | |
else | |
parse_args "$1" "$2" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment