From 1d930c571da27c29a895311734a6ef525abe2642 Mon Sep 17 00:00:00 2001 From: paulbdavis Date: Thu, 26 Mar 2015 14:57:43 -0400 Subject: [PATCH 1/5] fix shebang --- hsandbox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hsandbox b/hsandbox index e64e218..a8b2756 100755 --- a/hsandbox +++ b/hsandbox @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python2 """ The Hacking Sandbox - hsandbox From 015146d4bca7b06a4dfc40476ff22b3e354efb4c Mon Sep 17 00:00:00 2001 From: paulbdavis Date: Thu, 26 Mar 2015 14:58:19 -0400 Subject: [PATCH 2/5] add emacs goto-line for startup --- hsandbox | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hsandbox b/hsandbox index a8b2756..6188251 100755 --- a/hsandbox +++ b/hsandbox @@ -52,11 +52,20 @@ except ImportError: HSANDBOX_DIR = os.path.expanduser("~/.hsandbox") VIM_ARGS = "+$HSANDBOX_LINE +'normal $'" +EMACS_ARGS = """-nw --eval ' + (add-hook '"'"'after-change-major-mode-hook + (lambda() + (let ((target-line (string-to-number (getenv "HSANDBOX_LINE")))) + (message (number-to-string target-line)) + (goto-line target-line) + (end-of-line)))) +'""" EDITOR_ARGS = { "vi": VIM_ARGS, "vim": VIM_ARGS, "gvim": VIM_ARGS, + "emacs": EMACS_ARGS } From 354a3749855c91bc4c8fc300988bb86aa1cd6692 Mon Sep 17 00:00:00 2001 From: paulbdavis Date: Thu, 26 Mar 2015 15:01:00 -0400 Subject: [PATCH 3/5] allow setting tmux prefix key default prefix key comes from tmux conf or is C-b --- hsandbox | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hsandbox b/hsandbox index 6188251..f32cd1d 100755 --- a/hsandbox +++ b/hsandbox @@ -351,13 +351,17 @@ def screen(hacking, argv, vertical): splitopt = "-v" if vertical: splitopt = "-h" # Split horizontally, vertical pane. - subprocess.call([ + tmux_args = [ "tmux", "new-session", "-n", "Sandbox", hsandbox + " --editor", ";", "set-option", "-q", "status", "off", ";", "split-window", splitopt, hsandbox + " --runner", ";", - "last-pane", ";", - ]) + "last-pane", ";" + ] + if "HSANDBOX_PREFIX" in os.environ: + tmux_prefix = os.environ.get("HSANDBOX_PREFIX") + tmux_args.extend(["set", "prefix", "C-" + tmux_prefix, ";"]) + subprocess.call(tmux_args) except OSError: raise Error("Couldn't run 'tmux'. Is it installed?") finally: @@ -441,7 +445,7 @@ def describe_languages(): def format_line(tag, label): return " %-*s - %s" % (max_tag_length, tag, label) - + lines = [format_line(tag, label) for (tag, label) in descriptions] return "\n".join(lines) From 629c3942cb8a7abb49656a31b8da865db82ecbeb Mon Sep 17 00:00:00 2001 From: paulbdavis Date: Thu, 26 Mar 2015 15:04:04 -0400 Subject: [PATCH 4/5] tweak go template --- hsandbox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hsandbox b/hsandbox index f32cd1d..8a4688c 100755 --- a/hsandbox +++ b/hsandbox @@ -120,7 +120,7 @@ class GoHacking(Hacking): filename = "sandbox.go" template = ("package main\n\n" - "import (\n)\n\n" + "import (\n\"fmt\"\n)\n\n" "func main() {\n\n}\n") def get_command(self, version): From 7639307dd952eb4c914b92256c9ac0415875fc19 Mon Sep 17 00:00:00 2001 From: paulbdavis Date: Thu, 26 Mar 2015 15:58:28 -0400 Subject: [PATCH 5/5] properly pass editor env var to sub command --- hsandbox | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/hsandbox b/hsandbox index 8a4688c..d2abc48 100755 --- a/hsandbox +++ b/hsandbox @@ -353,11 +353,20 @@ def screen(hacking, argv, vertical): splitopt = "-h" # Split horizontally, vertical pane. tmux_args = [ "tmux", - "new-session", "-n", "Sandbox", hsandbox + " --editor", ";", + ] + editor = os.environ.get("HSANDBOX_EDITOR") + if not editor: + tmux_args.extend(["new-session", "-n", "Sandbox", hsandbox + " --editor", ";",]) + else: + tmux_args.extend([ + "new-session", "-n", "Sandbox", + "HSANDBOX_EDITOR=" + editor + " " + hsandbox + " --editor", ";", + ]) + tmux_args.extend([ "set-option", "-q", "status", "off", ";", "split-window", splitopt, hsandbox + " --runner", ";", "last-pane", ";" - ] + ]) if "HSANDBOX_PREFIX" in os.environ: tmux_prefix = os.environ.get("HSANDBOX_PREFIX") tmux_args.extend(["set", "prefix", "C-" + tmux_prefix, ";"]) @@ -387,6 +396,8 @@ def editor(hacking): cmd = os.environ.get("EDITOR") if not cmd: cmd = "vi" + cmd_list = cmd.split() + if len(cmd_list) is 1: cmd_args = EDITOR_ARGS.get(cmd.split()[0]) if cmd_args: cmd += " " + cmd_args