Skip to content

Instantly share code, notes, and snippets.

@siers
Last active January 30, 2017 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siers/cb5d2accf2de923111934c6b871c48ef to your computer and use it in GitHub Desktop.
Save siers/cb5d2accf2de923111934c6b871c48ef to your computer and use it in GitHub Desktop.
Print all files synchronized with syncthing.
#!/usr/bin/env ruby
require 'json'
if ARGV.length == 0
puts "usage: $0 '?folder=$FOLDERID'"
exit
end
key = %x{grep -Po '(?<=<apikey>)[^<]+' ~/.config/syncthing/config.xml}.strip
url = "http://localhost:8384/rest/db/browse#{ ARGV[0] }"
cmd = %{curl -sH "X-API-Key: #{ key }" "#{ url }"}
puts "In a second, going to request:\n#{ cmd }"
sleep 1
def print_files(hash, prefix='')
hash.each do |name, contents|
if contents.is_a? Hash
print_files contents, "#{ prefix }#{ name }/"
else
puts "#{ prefix }#{ name }"
end
end
end
print_files(JSON.parse(%x{#{ cmd }}))
@siers
Copy link
Author

siers commented Jan 16, 2017

Pass "?folder=FOLDERID" in arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment