-
Notifications
You must be signed in to change notification settings - Fork 0
/
ob_rmenu_steam.rb
executable file
·45 lines (35 loc) · 1.1 KB
/
ob_rmenu_steam.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/ruby
require 'pathname'
steamapps_dir = ARGV[0]
def main(steamapps_dir)
games = Array.new
get_acf_files(steamapps_dir || "#{ENV['HOME']}/.steam/steam/SteamApps/").each do |f|
id, name = nil, nil
File.open(f).each_line.collect do |line| line.strip end.each do |line|
if names = line.match(/^"name"[ \t]*"(.*)"$/)
name = names[1]
end
if ids = line.match(/^"appID"[ \t]*"(.*)"$/)
id = ids[1]
end
end
name.gsub! "&", "&"
games << [id, name]
end
games.sort_by! do |game| game[0].to_i end
puts '<openbox_pipe_menu>'
puts '<item label="Steam"><action name="Execute"><execute>steam</execute></action></item>'
puts '<separator/>'
games.each do |game|
puts "<item label=\"#{game[1]}\"><action name=\"Execute\"><execute>steam steam://run/#{game[0]}</execute></action></item>"
end
puts '</openbox_pipe_menu>'
end
def get_acf_files(dir)
if !dir.nil? and Pathname.new(dir).directory?
return Pathname.new(dir).children.select do |c| c.file? and c.readable? and not c.symlink? and c.basename.to_s =~ /appmanifest_\d+\.acf/ end
else
return []
end
end
main(steamapps_dir)