I've tried to create the following:
function change_brightness
set -l brightness_level $argv[1]
if not string match -r '^[1-9][0-9]*$' $brightness_level
echo "Expect a single non-zero integer value to be passed."
return 1
end
sudo echo $brightness_level > /sys/class/backlight/amdgpu_bl0/brightness
end
When I run this function I get the following output:
$ change_brightness 30
30
warning: An error occurred while redirecting file '/sys/class/backlight/amdgpu_bl0/brightness'
open: Permission denied
I'm not sure why the permission is denied, but I'm not sure why 30
is being echo'd to the console either (i was just expecting this to be written to the setting file).
Edit - running from shell with sudo
The following doesn't work:
$ sudo change_brightness 30
[sudo] password for user:
sudo: change_brightness: command not found
Solution
function change_brightness
set -l brightness_level $argv[1]
if not string match -r '^[1-9][0-9]*$' $brightness_level
echo "Expect a single non-zero integer value to be passed."
return 1
end
echo $brightness_level | sudo tee /sys/class/backlight/amdgpu_bl0/brightness
end