from IPython.display import Javascript,HTML,display
-# this replaces the content of the current input cell with txt
+# this replaces the content of the current input cell with txt and the output
+# with msg, where msg may be any HTML string
def set_current_input(txt,msg="") :
js = ("""Jupyter.notebook.get_selected_cell().set_text({});"""
"""element[0].innerHTML={};"""
# with a bitbucket_snippet cell magic
def create_bitbucket_snippet(line) :
+ """Create a new snippet with the given title using the username and authentication
+ credentials supplied. The current input of the cell will be replaced with a
+ %%bitbucket_snippet magic command that corresponds to the new snippet. The URL to
+ the snippet on bitbucket is added as a comment.
creds_match = re.match(r'"([^"]*)"\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)$',line)
return "Usage: %create_bitbucket_snippet \"<snippet title>\" <username> <email> <password>"
def bitbucket_snippet(line,cell):
+ """Cell magic to commit, pull, or source an existing snippet. Usage goes like:
+ %%bitbucket_snippet "<snippet title>" <snippet_id> <username> <email> <password>
+ The last line of the cell defines the behavior of the magic. If the last line is:
+ #COMMIT [<commit message>]
+ Take all the input of the cell except the magic line and commit it
+ as the current source of the snippet. The snippet title will be changed
+ to reflect the title specified in the magic line. The contents of the
+ cell are exec'ed into the global scope.
+ Replace the source of the current cell, excluding the magic line, with
+ the content of the snippet and execute it in global scope.
+ Execute the source of the snippet in the global scope and do not replace
+ the source of the current cell.
creds_match = re.match(r'"([^"]*)"\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)$',line)
return "Usage: %%bitbucket_snippet \"<snippet title>\" <snippet id> <username> <email> <password>"
-#COMMIT added message to output on current input set
+#COMMIT added comments like a good little developer