 
 define (require) ->
   URI = require 'URIjs'
+  Q = require 'q'
   modules = require 'modules'
   http = require 'http'
+  global_settings = require 'settings'
 
   notebook = null
   require ['notebook'], (nb) ->


    cmd 'load', 'Loads a file from GitHub', (path, options={}) ->
      url = github.to_repo_url path
      @async ->
        @text "Loading file #{path}"
        promise = github.get_repo_contents(url)

          'notebook.lnb':
            content: JSON.stringify notebook, undefined, 2
      @async ->
        authorized = ensure_access @
        authorized.then =>
          promise = github.save_gist gist
          promise.done (result) =>
            @html "<a href='#{result.html_url}'>#{result.html_url}</a>"
            lead_uri = URI window.location.href
            lead_uri.fragment "/#{result.html_url}"
            @html "<a href='#{lead_uri}'>#{lead_uri}</a>"
          promise.fail =>
            @error 'Save failed. Make sure your access token is configured correctly.'

    github
