Employ File.expand_path as appropriate
Any path in amazing will now understand tilde-syntax,
and the code doesn't need to handle relative paths directly.
| |   |
| 92 | 92 | def load_scripts |
| 93 | 93 | scripts = @options[:include] |
| 94 | 94 | @config["include"].each do |script| |
| 95 | | script = "#{File.dirname(@options[:config])}/#{script}" if script[0] != ?/ |
| 95 | script = File.expand_path(script, File.dirname(@options[:config])) |
| 96 | 96 | scripts << script |
| 97 | 97 | end |
| 98 | 98 | if @options[:autoinclude] |
| toggle raw diff |
--- a/lib/amazing/cli.rb
+++ b/lib/amazing/cli.rb
@@ -92,7 +92,7 @@ module Amazing
def load_scripts
scripts = @options[:include]
@config["include"].each do |script|
- script = "#{File.dirname(@options[:config])}/#{script}" if script[0] != ?/
+ script = File.expand_path(script, File.dirname(@options[:config]))
scripts << script
end
if @options[:autoinclude] |
| |   |
| 19 | 19 | default { @last } |
| 20 | 20 | |
| 21 | 21 | init do |
| 22 | | @file = "#{ENV["HOME"]}/#@file" if @file[0] != ?/ |
| 22 | @file = ::File.expand_path(@file, "~") |
| 23 | 23 | @lines = ::File.readlines(@file).map {|line| line.chomp } |
| 24 | 24 | @first = @lines.first || "" |
| 25 | 25 | @last = @lines.last || "" |
| toggle raw diff |
--- a/lib/amazing/widgets/file.rb
+++ b/lib/amazing/widgets/file.rb
@@ -19,7 +19,7 @@ module Amazing
default { @last }
init do
- @file = "#{ENV["HOME"]}/#@file" if @file[0] != ?/
+ @file = ::File.expand_path(@file, "~")
@lines = ::File.readlines(@file).map {|line| line.chomp }
@first = @lines.first || ""
@last = @lines.last || "" |
| |   |
| 14 | 14 | init do |
| 15 | 15 | raise WidgetError, "No directories configured" unless @directories |
| 16 | 16 | @directories.each do |glob| |
| 17 | | glob = "#{ENV["HOME"]}/#{glob}" if glob[0] != ?/ |
| 17 | glob = ::File.expand_Path(glob, "~") |
| 18 | 18 | @count += Dir["#{glob}/*"].size |
| 19 | 19 | end |
| 20 | 20 | end |
| toggle raw diff |
--- a/lib/amazing/widgets/maildir.rb
+++ b/lib/amazing/widgets/maildir.rb
@@ -14,7 +14,7 @@ module Amazing
init do
raise WidgetError, "No directories configured" unless @directories
@directories.each do |glob|
- glob = "#{ENV["HOME"]}/#{glob}" if glob[0] != ?/
+ glob = ::File.expand_Path(glob, "~")
@count += Dir["#{glob}/*"].size
end
end |
| |   |
| 8 | 8 | class Raggle < Widget |
| 9 | 9 | description "Unread posts in raggle" |
| 10 | 10 | dependency "pstore", "Ruby standard library" |
| 11 | | option :feed_list_path, "Path to feeds list", ".raggle/feeds.yaml" |
| 12 | | option :feed_cache_path, "Path to feeds cache", ".raggle/feed_cache.store" |
| 11 | option :feed_list_path, "Path to feeds list", "~/.raggle/feeds.yaml" |
| 12 | option :feed_cache_path, "Path to feeds cache", "~/.raggle/feed_cache.store" |
| 13 | 13 | field :count, "Ammount of unread posts", 0 |
| 14 | 14 | default { @count } |
| 15 | 15 | |
| 16 | 16 | init do |
| 17 | | @feed_list_path = "#{ENV["HOME"]}/#@feed_list_path" if @feed_list_path[0] != ?/ |
| 17 | @feed_list_path = ::File.expand_path(@feed_list_path, "~") |
| 18 | 18 | feeds = YAML.load_file(@feed_list_path) |
| 19 | | @feed_cache_path = "#{ENV["HOME"]}/#{@feed_cache_path}" if @feed_cache_path[0] != ?/ |
| 19 | @feed_cache_path = ::File.expand_path(@feed_cache_path, "~") |
| 20 | 20 | cache = PStore.new(@feed_cache_path) |
| 21 | 21 | cache.transaction(false) do |
| 22 | 22 | feeds.each do |feed| |
| toggle raw diff |
--- a/lib/amazing/widgets/raggle.rb
+++ b/lib/amazing/widgets/raggle.rb
@@ -8,15 +8,15 @@ module Amazing
class Raggle < Widget
description "Unread posts in raggle"
dependency "pstore", "Ruby standard library"
- option :feed_list_path, "Path to feeds list", ".raggle/feeds.yaml"
- option :feed_cache_path, "Path to feeds cache", ".raggle/feed_cache.store"
+ option :feed_list_path, "Path to feeds list", "~/.raggle/feeds.yaml"
+ option :feed_cache_path, "Path to feeds cache", "~/.raggle/feed_cache.store"
field :count, "Ammount of unread posts", 0
default { @count }
init do
- @feed_list_path = "#{ENV["HOME"]}/#@feed_list_path" if @feed_list_path[0] != ?/
+ @feed_list_path = ::File.expand_path(@feed_list_path, "~")
feeds = YAML.load_file(@feed_list_path)
- @feed_cache_path = "#{ENV["HOME"]}/#{@feed_cache_path}" if @feed_cache_path[0] != ?/
+ @feed_cache_path = ::File.expand_path(@feed_cache_path, "~")
cache = PStore.new(@feed_cache_path)
cache.transaction(false) do
feeds.each do |feed| |