def sanity_check(env={}, error_log=False): if not env: env = sh.env() ns = '(not set)' sl = [ ('install state', _inst_state()), ('sublime.version', sublime.version()), ('sublime.channel', sublime.channel()), ('about.ann', gs.attr('about.ann', '')), ('about.version', gs.attr('about.version', '')), ('version', about.VERSION), ('platform', about.PLATFORM), ('~bin', '%s' % gs.home_dir_path('bin')), ('margo.exe', '%s (%s)' % _tp(_margo_bin())), ('go.exe', '%s (%s)' % _tp(sh.which('go') or 'go')), ('go.version', sh.GO_VERSION), ('GOROOT', '%s' % env.get('GOROOT', ns)), ('GOPATH', '%s' % env.get('GOPATH', ns)), ('GOBIN', '%s (should usually be `%s`)' % (env.get('GOBIN', ns), ns)), ('set.shell', str(gs.lst(gs.setting('shell')))), ('env.shell', env.get('SHELL', '')), ('shell.cmd', str(sh.cmd('${CMD}'))), ] if error_log: try: with open(gs.home_path('log.txt'), 'r') as f: s = f.read().strip() sl.append(('error log', s)) except Exception: pass return sl
def sanity_check(env={}, error_log=False): if not env: env = sh.env() ns = "(not set)" sl = [ ("install state", _inst_state()), ("sublime.version", sublime.version()), ("sublime.channel", sublime.channel()), ("about.ann", gs.attr("about.ann", "")), ("about.version", gs.attr("about.version", "")), ("version", about.VERSION), ("platform", about.PLATFORM), ("~bin", "%s" % gs.home_dir_path("bin")), ("margo.exe", "%s (%s)" % _tp(_margo_bin())), ("go.exe", "%s (%s)" % _tp(sh.which("go") or "go")), ("go.version", sh.GO_VERSION), ("GOROOT", "%s" % env.get("GOROOT", ns)), ("GOPATH", "%s" % env.get("GOPATH", ns)), ("GOBIN", "%s (should usually be `%s`)" % (env.get("GOBIN", ns), ns)), ("set.shell", str(gs.lst(gs.setting("shell")))), ("env.shell", env.get("SHELL", "")), ("shell.cmd", str(sh.cmd("${CMD}"))), ] if error_log: try: with open(gs.home_path("log.txt"), "r") as f: s = f.read().strip() sl.append(("error log", s)) except Exception: pass return sl
def cmd_which(view, edit, args, wd, rkey): l = [] am = aliases() m = builtins() if not args: args = [] args.extend(sorted(m.keys())) args.extend(sorted(am.keys())) fm = '%{0}s: %s'.format(max(len(s) for s in args)) for k in args: if k == 'sh': v = '9o builtin: %s' % sh.cmd('${CMD}') elif k in ('go'): v = '9o builtin: %s' % sh.which(k) elif k in m: v = '9o builtin' elif k in am: v = '9o alias: `%s`' % am[k] else: v = sh.which(k) l.append(fm % (k, v)) push_output(view, rkey, '\n'.join(l))
def cmd_which(view, edit, args, wd, rkey): l = [] am = aliases() m = builtins() if not args: args = [] args.extend(sorted(m.keys())) args.extend(sorted(am.keys())) fm = "%{0}s: %s".format(max(len(s) for s in args)) for k in args: if k == "sh": v = "9o builtin: %s" % sh.cmd("${CMD}") elif k in ("go"): v = "9o builtin: %s" % sh.which(k) elif k in m: v = "9o builtin" elif k in am: v = "9o alias: `%s`" % am[k] else: v = sh.which(k) l.append(fm % (k, v)) push_output(view, rkey, "\n".join(l))
def run(self, edit, save_hist=False): view = self.view pos = gs.sel(view).begin() line = view.line(pos) wd = view.settings().get('9o.wd') try: os.chdir(wd) except Exception: gs.error_traceback(DOMAIN) ln = view.substr(line).split('#', 1) if len(ln) == 2: cmd = ln[1].strip() if cmd: vs = view.settings() aso = gs.aso() hkey = _hkey(wd) hist = gs.dval(aso.get(hkey), []) m = HIST_EXPAND_PAT.match(cmd) if m: pfx = m.group(1) hl = len(hist) idx = hl - int(m.group(2)) cmd = '' if idx >= 0 and idx < hl: cmd = hist[idx] if pfx == '^' or not cmd: view.replace(edit, line, ('%s# %s' % (ln[0], cmd))) return elif save_hist: try: hist.remove(cmd) except ValueError: pass hist.append(cmd) aso.set(hkey, hist) gs.save_aso() if not cmd: view.run_command('gs9o_init') return view.replace(edit, line, (u'[ `%s` %s ]' % (cmd, HOURGLASS))) rkey = '9o.exec.%s' % uuid.uuid4() view.add_regions(rkey, [sublime.Region(line.begin(), view.size())], '') view.run_command('gs9o_init') nv = sh.env() anv = nv.copy() seen = {} am = aliases() while True: cli = cmd.split(' ', 1) nm = cli[0] if not nm: break ag = cli[1].strip() if len(cli) == 2 else '' alias = am.get(nm, '') if not alias: break if alias in seen: gs.error(DOMAIN, 'recursive alias detected: `%s`' % alias) break seen[alias] = True anv['_args'] = ag cmd = string.Template(alias).safe_substitute(anv) if nm != 'sh': f = builtins().get(nm) if f: args = [] if ag: args = [_exparg(s, nv) for s in shlex.split(gs.astr(ag))] f(view, edit, args, wd, rkey) return if nm == 'sh': args = sh.cmd(ag) else: args = sh.cmd(cmd) cmd_sh(view, edit, args, wd, rkey) else: view.insert(edit, gs.sel(view).begin(), '\n')
def _exec(view, edit, save_hist=False): pos = gs.sel(view).begin() line = view.line(pos) wd = view.settings().get('9o.wd') try: os.chdir(wd) except Exception: ui.trace(DOMAIN) ln = view.substr(line).split('#', 1) if len(ln) == 2: cmd = ln[1].strip() if cmd: vs = view.settings() aso = gs.aso() hkey = _hkey(wd) hist = gs.dval(aso.get(hkey), []) m = HIST_EXPAND_PAT.match(cmd) if m: pfx = m.group(1) hl = len(hist) idx = hl - int(m.group(2)) cmd = '' if idx >= 0 and idx < hl: cmd = hist[idx] if pfx == '^' or not cmd: view.replace(edit, line, ('%s# %s' % (ln[0], cmd))) return elif save_hist: try: hist.remove(cmd) except ValueError: pass hist.append(cmd) aso.set(hkey, hist) gs.save_aso() if not cmd: view.run_command('gs9o_init') return line = view.full_line(pos) ctx = '9o.exec.%s' % gs.uid() view.replace(edit, line, ('[`%s`]\n' % cmd)) view.run_command('gs9o_init') ep = view.full_line(line.begin()).end() view.add_regions(ctx, [sublime.Region(ep, ep)], '') hellip = u'[ \u22EF ]' ep += 1 view.insert(edit, ep, hellip+'\n\n') view.add_regions(ctx+'.done', [sublime.Region(ep, ep+len(hellip))], '') cli = cmd.split(' ', 1) if cli[0] == 'sh': a = cli[1].strip() if len(cli) == 2 else '' mk_cmd(view, wd, ctx, sh.cmd(a)).start() return nv = sh.env() a = [_exparg(s, nv) for s in shlex.split(gs.astr(cmd))] f = builtins().get(a[0]) if f: f(view, edit, a[1:], wd, ctx) else: mk_cmd(view, wd, ctx, a).start() else: view.insert(edit, gs.sel(view).begin(), '\n')
def _exec(view, edit, save_hist=False): pos = gs.sel(view).begin() line = view.line(pos) wd = view.settings().get('9o.wd') try: os.chdir(wd) except Exception: ui.trace(DOMAIN) ln = view.substr(line).split('#', 1) if len(ln) == 2: cmd = ln[1].strip() if cmd: vs = view.settings() aso = gs.aso() hkey = _hkey(wd) hist = gs.dval(aso.get(hkey), []) m = HIST_EXPAND_PAT.match(cmd) if m: pfx = m.group(1) hl = len(hist) idx = hl - int(m.group(2)) cmd = '' if idx >= 0 and idx < hl: cmd = hist[idx] if pfx == '^' or not cmd: view.replace(edit, line, ('%s# %s' % (ln[0], cmd))) return elif save_hist: try: hist.remove(cmd) except ValueError: pass hist.append(cmd) aso.set(hkey, hist) gs.save_aso() if not cmd: view.run_command('gs9o_init') return line = view.full_line(pos) ctx = '9o.exec.%s' % gs.uid() view.replace(edit, line, ('[`%s`]\n' % cmd)) view.run_command('gs9o_init') ep = view.full_line(line.begin()).end() view.add_regions(ctx, [sublime.Region(ep, ep)], '') hellip = u'[ \u22EF ]' ep += 1 view.insert(edit, ep, hellip + '\n\n') view.add_regions(ctx + '.done', [sublime.Region(ep, ep + len(hellip))], '') cli = cmd.split(' ', 1) if cli[0] == 'sh': a = cli[1].strip() if len(cli) == 2 else '' mk_cmd(view, wd, ctx, sh.cmd(a)).start() return nv = sh.env() a = [_exparg(s, nv) for s in shlex.split(gs.astr(cmd))] f = builtins().get(a[0]) if f: f(view, edit, a[1:], wd, ctx) else: mk_cmd(view, wd, ctx, a).start() else: view.insert(edit, gs.sel(view).begin(), '\n')
def run(self, edit, save_hist=False): view = self.view pos = gs.sel(view).begin() line = view.line(pos) wd = view.settings().get('9o.wd') try: os.chdir(wd) except Exception: gs.error_traceback(DOMAIN) ln = view.substr(line).split('#', 1) if len(ln) == 2: cmd = ln[1].strip() if cmd: vs = view.settings() aso = gs.aso() hkey = _hkey(wd) hist = gs.dval(aso.get(hkey), []) m = HIST_EXPAND_PAT.match(cmd) if m: pfx = m.group(1) hl = len(hist) idx = hl - int(m.group(2)) cmd = '' if idx >= 0 and idx < hl: cmd = hist[idx] if pfx == '^' or not cmd: view.replace(edit, line, ('%s# %s' % (ln[0], cmd))) return elif save_hist: try: hist.remove(cmd) except ValueError: pass hist.append(cmd) aso.set(hkey, hist) gs.save_aso() if not cmd: view.run_command('gs9o_init') return view.replace(edit, line, (u'[ `%s` %s ]' % (cmd, HOURGLASS))) rkey = '9o.exec.%s' % uuid.uuid4() view.add_regions(rkey, [sublime.Region(line.begin(), view.size())], '') view.run_command('gs9o_init') nv = sh.env() anv = nv.copy() seen = {} am = aliases() while True: cli = cmd.split(' ', 1) nm = cli[0] if not nm: break ag = cli[1].strip() if len(cli) == 2 else '' alias = am.get(nm, '') if not alias: break if alias in seen: gs.error(DOMAIN, 'recursive alias detected: `%s`' % alias) break seen[alias] = True anv['_args'] = ag cmd = string.Template(alias).safe_substitute(anv) if nm != 'sh': f = builtins().get(nm) if f: args = [] if ag: args = [ _exparg(s, nv) for s in shlex.split(gs.astr(ag)) ] f(view, edit, args, wd, rkey) return if nm == 'sh': args = sh.cmd(ag) else: args = sh.cmd(cmd) cmd_sh(view, edit, args, wd, rkey) else: view.insert(edit, gs.sel(view).begin(), '\n')