Skip to content

Instantly share code, notes, and snippets.

@thexavier666
Last active April 10, 2020 07:04
Show Gist options
  • Save thexavier666/d5f3e239a577767e60d4151332ae2c65 to your computer and use it in GitHub Desktop.
Save thexavier666/d5f3e239a577767e60d4151332ae2c65 to your computer and use it in GitHub Desktop.
#!/bin/bash
# path of your alacritty config file
# this should be the default path
FILE_LOC="/home/$USER/.config/alacritty/alacritty.yml"
def_change_opacity ()
{
delta_val="0.05"
METRIC_ID="background_opacity"
if [[ $1 -eq 1 ]]; then
delta_val=$(echo "$delta_val*1" | bc)
elif [[ $1 -eq -1 ]]; then
delta_val=$(echo "$delta_val*-1" | bc)
else
echo "usage: <cmd> <+1/-1>"
echo " +1 : increase opacity"
echo " -1 : decrease opacity"
exit
fi
# finding current opacity value and stripping of white space
opacity_val=$(grep $METRIC_ID $FILE_LOC | cut -d':' -f2 | cut -d' ' -f2)
# if opacity values are beyond the range of 0/1
# then exit the program
val1=$(echo "$opacity_val==0 && $1==-1" | bc)
val2=$(echo "$opacity_val==1 && $1==1" | bc)
# lower extreme (min opacity)
if [[ $val1 -eq 1 ]]; then
exit
# upper extreme (max opacity)
elif [[ $val2 -eq 1 ]]; then
exit
fi
# calculating new opacity value by applying delta change
new_opacity_val=$(echo "$opacity_val+$delta_val" | bc)
# replacing old value with new value
sed -i "s/$METRIC_ID: $opacity_val/$METRIC_ID: $new_opacity_val/g" $FILE_LOC
}
def_change_opacity $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment