Last active
October 19, 2016 13:06
-
-
Save pawndev/9152330aca0443c858ac7cd9aceb7d2a to your computer and use it in GitHub Desktop.
A brightness manager script, writting in ruby
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
#!/usr/bin/ruby | |
require 'optparse' | |
require 'optparse/time' | |
require 'ostruct' | |
require 'pp' | |
Version = [0, 0, 1] | |
class OptparseBright | |
def self.parse(args) | |
options = OpenStruct.new | |
options.encoding = "utf8" | |
opt_parser = OptionParser.new do |opts| | |
opts.banner = "Usage: bright [options]\nVersion: %{version}" % {version: ::Version.join('.')} | |
opts.separator "" | |
opts.separator "Specific options:" | |
opts.on("-i", "--inc", "Increment the brightness") do | |
exec "xbacklight -inc 10" | |
end | |
opts.on("-d", "--dec", "Decrement the brightness") do | |
exec "xbacklight -dec 10" | |
end | |
opts.separator "" | |
opts.separator "Common options:" | |
opts.on_tail("-h", "--help", "Show this message") do | |
puts opts | |
exit | |
end | |
opts.on_tail("-v", "--version", "Show version") do | |
puts ::Version.join('.') | |
exit | |
end | |
end | |
opt_parser.parse!(args) | |
options | |
end | |
end | |
if ARGV.empty? | |
ARGV.push "-h" | |
end | |
begin | |
options = OptparseBright.parse(ARGV) | |
pp options | |
pp ARGV | |
rescue OptionParser::InvalidOption => e | |
e = e.to_s | |
e[0] = e.chars.first.upcase | |
puts e | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment