Permalink
Browse files

add `simulator_bookmarks rm` functionality

  • Loading branch information...
1 parent f915020 commit 75337b40d24b2f1b54ac69b60afb96514a5bda7e @mislav committed Sep 5, 2011
Showing with 39 additions and 2 deletions.
  1. +39 −2 bin/simulator_bookmarks
View
@@ -9,8 +9,11 @@
#
# Apart from specifying the URL with the "-u" argument, you can also pipe it in via STDIN.
#
-# This only affects the simulator running in the "en_US" locale. To edit bookmarks of
-# a different locale, use the "-l" option:
+# Remove a bookmark:
+# $ simulator_bookmarks rm "Toggle Livereload"
+#
+# These commands only affect the simulator running with the "en_US" locale.
+# To edit bookmarks of a different locale, use the "-l" option:
#
# $ simulator_bookmarks add "Título" -l es_ES -u http://example.es
#
@@ -43,6 +46,11 @@ class Bookmarks
@items.unshift("Title" => title, "URL" => url)
end
+ def remove_bookmark(title)
+ idx = @items.find_index {|item| item['Title'] == title }
+ @items.delete_at idx if idx
+ end
+
def writable?
File.writable? path
end
@@ -137,6 +145,35 @@ if __FILE__ == $0
warn "Warning: no bookmarks edited"
exit 1
end
+ when 'rm'
+ title = ARGV.shift
+
+ if title.nil? or title.empty?
+ warn "Error: no title given"
+ exit 1
+ end
+
+ num_removed = 0
+
+ Bookmarks.find_by_locale(locale).each do |file|
+ bookmarks = Bookmarks.new file
+ unless bookmarks.writable?
+ warn "Error: no write permissions to edit boomarks"
+ warn "(Try running with sudo)"
+ exit 1
+ end
+
+ if bookmarks.remove_bookmark title
+ bookmarks.save
+ puts "Edited #{bookmarks.short_path}"
+ num_removed += 1
+ end
+ end
+
+ if num_removed.zero?
+ warn "Warning: no bookmarks edited"
+ exit 1
+ end
when 'list'
files = Bookmarks.find_by_locale(locale).each_with_index do |file, idx|
bookmarks = Bookmarks.new file

0 comments on commit 75337b4

Please sign in to comment.