示例#1
0
def gs_init(m={}):
    """Called by GoSublime.py::plugin_loaded
        m = {
                'version': VERSION,
                'ann': ANN,
                'margo_exe': MARGO_EXE,
            }
    """

    global INSTALL_VERSION
    global INSTALL_EXE

    # Kill server on process exit.
    atexit.register(killSrv)

    version = m.get("version")
    if version:
        INSTALL_VERSION = version

    margo_exe = m.get("margo_exe")
    if margo_exe:
        INSTALL_EXE = margo_exe

    force = about.FORCE_INSTALL is True
    # install_version recorded in 'GoSublime-aux.sublime-settings'
    aso_install_vesion = gs.aso().get("install_version", "")
    f = lambda: install(aso_install_vesion, force)
    # GsQ handles threaded processes.
    # Install latest version.
    gsq.do("GoSublime", f, msg="Installing MarGo", set_status=False)
示例#2
0
文件: mg9.py 项目: OlingCat/GoSublime
	def cb():
		aso = gs.aso()
		old_version = aso.get('version', '')
		if about.VERSION > old_version:
			aso.set('version', about.VERSION)
			gs.save_aso()
			gs.focus(gs.dist_path('CHANGELOG.md'))
 def cb():
     aso = gs.aso()
     old_version = aso.get('version', '')
     old_ann = aso.get('ann', '')
     if about.VERSION > old_version or about.ANN > old_ann:
         aso.set('version', about.VERSION)
         aso.set('ann', about.ANN)
         gs.save_aso()
         gs.focus(gs.dist_path('CHANGELOG.md'))
示例#4
0
 def cb():
     aso = gs.aso()
     old_version = aso.get("version", "")
     old_ann = aso.get("ann", "")
     if about.VERSION > old_version or about.ANN > old_ann:
         aso.set("version", about.VERSION)
         aso.set("ann", about.ANN)
         gs.save_aso()
         gs.focus(gs.dist_path("CHANGELOG.md"))
示例#5
0
    def on_query_completions(self, view, prefix, locations):
        pos = gs.sel(view).begin()
        if view.score_selector(pos, 'text.9o') == 0:
            return []

        cl = set()

        hkey = _hkey(view.settings().get('9o.wd', ''))
        cl.update((k, k + ' ') for k in gs.dval(gs.aso().get(hkey), []))
        cl.update((k, k + ' ') for k in aliases())
        cl.update((k, k + ' ') for k in builtins())
        cl.update(DEFAULT_CL)

        return ([cl_esc(e) for e in sorted(cl)], AC_OPTS)
示例#6
0
	def on_query_completions(self, view, prefix, locations):
		pos = gs.sel(view).begin()
		if view.score_selector(pos, 'text.9o') == 0:
			return []

		cl = set()

		hkey = _hkey(view.settings().get('9o.wd', ''))
		cl.update((k, k+' ') for k in gs.dval(gs.aso().get(hkey), []))
		cl.update((k, k+' ') for k in aliases())
		cl.update((k, k+' ') for k in builtins())
		cl.update(DEFAULT_CL)

		return ([cl_esc(e) for e in sorted(cl)], AC_OPTS)
示例#7
0
    def on_query_completions(self, view, prefix, locations):
        pos = gs.sel(view).begin()
        if view.score_selector(pos, 'text.9o') == 0:
            return []

        cl = []

        hkey = '9o.hist.%s' % view.settings().get('9o.wd', '')
        for i, cmd in enumerate(reversed(gs.dval(gs.aso().get(hkey), []))):
            if not cmd in cl:
                cl.append(('^%d %s' % (i + 1, cmd), cmd + ' '))

        cl.extend(DEFAULT_CL)

        return (cl, AC_OPTS)
示例#8
0
	def on_query_completions(self, view, prefix, locations):
		pos = gs.sel(view).begin()
		if view.score_selector(pos, 'text.9o') == 0:
			return []

		cl = []

		hkey = '9o.hist.%s' % view.settings().get('9o.wd', '')
		for i, cmd in enumerate(reversed(gs.dval(gs.aso().get(hkey), []))):
			if not cmd in cl:
				cl.append(('^%d %s' % (i+1, cmd), cmd+' '))

		cl.extend(DEFAULT_CL)

		return (cl, AC_OPTS)
示例#9
0
文件: mg9.py 项目: allanw1/Arianrhod
def gs_init(m={}):
	global INSTALL_VERSION
	global INSTALL_EXE

	atexit.register(killSrv)

	version = m.get('version')
	if version:
		INSTALL_VERSION = version

	margo_exe = m.get('margo_exe')
	if margo_exe:
		INSTALL_EXE = margo_exe

	aso_install_vesion = gs.aso().get('install_version', '')
	f = lambda: install(aso_install_vesion, bool(ext_main_file()))
	gsq.do('GoSublime', f, msg='Installing MarGo', set_status=False)
示例#10
0
def gs_init(m={}):
    global INSTALL_VERSION
    global INSTALL_EXE

    atexit.register(killSrv)

    version = m.get('version')
    if version:
        INSTALL_VERSION = version

    margo_exe = m.get('margo_exe')
    if margo_exe:
        INSTALL_EXE = margo_exe

    aso_install_vesion = gs.aso().get('install_version', '')
    f = lambda: install(aso_install_vesion, bool(ext_main_file()))
    gsq.do('GoSublime', f, msg='Installing MarGo', set_status=False)
示例#11
0
文件: mg9.py 项目: vivicai/GoSublime
def gs_init(m={}):
    global INSTALL_VERSION
    global INSTALL_EXE

    atexit.register(killSrv)

    version = m.get("version")
    if version:
        INSTALL_VERSION = version

    margo_exe = m.get("margo_exe")
    if margo_exe:
        INSTALL_EXE = margo_exe

    aso_install_vesion = gs.aso().get("install_version", "")
    f = lambda: install(aso_install_vesion, False)
    gsq.do("GoSublime", f, msg="Installing MarGo", set_status=True)
示例#12
0
def cmd_hist(view, edit, args, wd, rkey):
	aso = gs.aso()
	hkey = _hkey(wd)

	s = 'hist: invalid args: %s' % args

	if len(args) == 0:
		hist = gs.dval(aso.get(hkey), [])
		hist.reverse()
		hlen = len(hist)
		s = '\n'.join('^%d: %s' % (i+1, v) for i,v in enumerate(hist))
	elif len(args) == 1:
		if args[0] == 'erase':
			aso.erase(hkey)
			gs.save_aso()
			s = ''

	push_output(view, rkey, s)
示例#13
0
def cmd_hist(view, edit, args, wd, rkey):
    aso = gs.aso()
    hkey = _hkey(wd)

    s = 'hist: invalid args: %s' % args

    if len(args) == 0:
        hist = gs.dval(aso.get(hkey), [])
        hist.reverse()
        hlen = len(hist)
        s = '\n'.join('^%d: %s' % (i + 1, v) for i, v in enumerate(hist))
    elif len(args) == 1:
        if args[0] == 'erase':
            aso.erase(hkey)
            gs.save_aso()
            s = ''

    push_output(view, rkey, s)
示例#14
0
	def on_query_completions(self, view, _, locations):
		pos = locations[0]
		if view.score_selector(pos, 'text.9o') == 0:
			return []

		if view.substr(locations[0]-2) == '$':
			return ([('$'+k, '\$'+k+' ') for k in sh.env()], AC_OPTS)

		cl = set()

		slash = os.path.sep
		# the prefix passed tho us by definition doesn't contain slash because it's not a word char
		p = view.substr(sublime.Region(view.line(pos).begin(), pos))
		p = p.split()[-1].lstrip(' #')
		file_only_comp = p.startswith('.') or slash in p

		if not p.startswith(('.', slash)):
			p = '.'+slash+p

		rm = ''
		m = word_sep_pat.match(p)
		if m:
			rm = m.group(1)

		try:
			for fn in glob.iglob(p+'*'):
				space = ' '
				if os.path.isdir(fn):
					space = ''
					fn += '/'

				cl.add((fn, fn[len(rm):]+space))
		except Exception:
			pass

		if not file_only_comp:
			hkey = _hkey(view.settings().get('9o.wd', ''))
			cl.update((k, k+' ') for k in gs.dval(gs.aso().get(hkey), []))
			cl.update((k, k+' ') for k in builtins())
			cl.update(DEFAULT_CL)

		return ([cl_esc(e) for e in sorted(cl)], AC_OPTS)
示例#15
0
    def on_query_completions(self, view, _, locations):
        pos = locations[0]
        if view.score_selector(pos, 'text.9o') == 0:
            return []

        if view.substr(locations[0] - 2) == '$':
            return ([('$' + k, '\$' + k + ' ') for k in sh.env()], AC_OPTS)

        cl = set()

        slash = os.path.sep
        # the prefix passed tho us by definition doesn't contain slash because it's not a word char
        p = view.substr(sublime.Region(view.line(pos).begin(), pos))
        p = p.split()[-1].lstrip(' #')
        file_only_comp = p.startswith('.') or slash in p

        if not p.startswith(('.', slash)):
            p = '.' + slash + p

        rm = ''
        m = word_sep_pat.match(p)
        if m:
            rm = m.group(1)

        try:
            for fn in glob.iglob(p + '*'):
                space = ' '
                if os.path.isdir(fn):
                    space = ''
                    fn += '/'

                cl.add((fn, fn[len(rm):] + space))
        except Exception:
            pass

        if not file_only_comp:
            hkey = _hkey(view.settings().get('9o.wd', ''))
            cl.update((k, k + ' ') for k in gs.dval(gs.aso().get(hkey), []))
            cl.update((k, k + ' ') for k in builtins())
            cl.update(DEFAULT_CL)

        return ([cl_esc(e) for e in sorted(cl)], AC_OPTS)
示例#16
0
    def run(self, edit, up):
        view = self.view
        pos = gs.sel(view).begin()
        if view.score_selector(pos, 'prompt.9o') <= 0:
            return

        aso = gs.aso()
        vs = view.settings()
        wd = vs.get('9o.wd')
        hkey = _hkey(wd)
        hist = [s for s in gs.dval(aso.get(hkey), []) if s.strip()]
        if not hist:
            return

        r = view.extract_scope(pos)
        cmd = view.substr(r).strip('#').strip()
        try:
            idx = hist.index(cmd) + (-1 if up else 1)
            found = True
        except Exception:
            idx = -1
            found = False

        if cmd and not found:
            hist.append(cmd)
            aso.set(hkey, hist)
            gs.save_aso()

        if idx >= 0 and idx < len(hist):
            cmd = hist[idx]
        elif up:
            if not found:
                cmd = hist[-1]
        else:
            cmd = ''

        view.replace(edit, r, '# %s \n' % cmd)
        n = view.line(r.begin()).end()
        view.sel().clear()
        view.sel().add(sublime.Region(n, n))
示例#17
0
	def run(self, edit, up):
		view = self.view
		pos = gs.sel(view).begin()
		if view.score_selector(pos, 'prompt.9o') <= 0:
			return

		aso = gs.aso()
		vs = view.settings()
		wd = vs.get('9o.wd')
		hkey = _hkey(wd)
		hist = [s for s in gs.dval(aso.get(hkey), []) if s.strip()]
		if not hist:
			return

		r = view.extract_scope(pos)
		cmd = view.substr(r).strip('#').strip()
		try:
			idx = hist.index(cmd) + (-1 if up else 1)
			found = True
		except Exception:
			idx = -1
			found = False

		if cmd and not found:
			hist.append(cmd)
			aso.set(hkey, hist)
			gs.save_aso()

		if idx >= 0 and idx < len(hist):
			cmd = hist[idx]
		elif up:
			if not found:
				cmd = hist[-1]
		else:
			cmd = ''

		view.replace(edit, r, '# %s \n' % cmd)
		n = view.line(r.begin()).end()
		view.sel().clear()
		view.sel().add(sublime.Region(n, n))
示例#18
0
			def f():
				gs.aso().set('mg9_install_tokens', _gen_tokens())
				gs.save_aso()
示例#19
0
	def cb():
		aso = gs.aso()
		if about.ANN != aso.get('ann', ''):
			aso.set('ann', about.ANN)
			gs.save_aso()
			vu.open(gs.dist_path('CHANGELOG.md'))
示例#20
0
	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')
示例#21
0
def gs_init():
	atexit.register(killSrv)

	aso_tokens = gs.aso().get('mg9_install_tokens', '')
	f = lambda: install(aso_tokens, False)
	gsq.do('GoSublime', f, msg='Installing MarGo', set_status=True)
示例#22
0
	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')

		ln = view.substr(line).split('#', 1)
		if len(ln) == 2:
			cmd = ln[1].strip()
			if cmd:
				vs = view.settings()
				aso = gs.aso()
				hkey = '9o.hist.%s' % 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')

			cli = cmd.split(' ', 1)

			# todo: move this into margo
			if cli[0] == 'sh':
				def on_done(c):
					out = gs.ustr('\n'.join(c.consume_outq()))
					sublime.set_timeout(lambda: push_output(view, rkey, out), 0)

				c = gsshell.Command(cmd=cli[1], shell=True, cwd=wd)
				c.on_done = on_done
				c.start()
				return

			f = globals().get('cmd_%s' % cli[0])
			if f:
				args = shlex.split(gs.astr(cli[1])) if len(cli) == 2 else []
				f(view, edit, args, wd, rkey)
			else:
				push_output(view, rkey, 'Invalid command %s' % cli)
		else:
			view.insert(edit, gs.sel(view).begin(), '\n')
示例#23
0
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')
示例#24
0
 def f():
     gs.aso().set('install_version', INSTALL_VERSION)
     gs.save_aso()
示例#25
0
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')
示例#26
0
文件: mg9.py 项目: allanw1/Arianrhod
			def f():
				gs.aso().set('install_version', INSTALL_VERSION)
				gs.save_aso()
示例#27
0
    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')

        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')

            cli = cmd.split(' ', 1)
            nm = cli[0]
            ag = cli[1].strip() if len(cli) == 2 else ''

            if nm == "cd":
                args = [ag] if ag else []
                cmd_cd(view, edit, args, wd, rkey)
                return

            # todo: move this into margo
            if nm == 'sh':

                def on_done(c):
                    out = gs.ustr('\n'.join(c.consume_outq()))
                    sublime.set_timeout(lambda: push_output(view, rkey, out),
                                        0)

                c = gsshell.Command(cmd=ag, shell=True, cwd=wd)
                c.on_done = on_done
                c.start()
                return

            f = gs.gs9o.get(nm) or globals().get('cmd_%s' % nm)
            if f:
                args = shlex.split(gs.astr(ag)) if ag else []
                f(view, edit, args, wd, rkey)
            else:
                push_output(view, rkey, 'Invalid command %s' % cli)
        else:
            view.insert(edit, gs.sel(view).begin(), '\n')
示例#28
0
 def cb():
     aso = gs.aso()
     if about.ANN != aso.get('ann', ''):
         aso.set('ann', about.ANN)
         gs.save_aso()
         vu.open(gs.dist_path('CHANGELOG.md'))
示例#29
0
文件: mg9.py 项目: OlingCat/GoSublime
def gs_init():
	atexit.register(killSrv)

	aso_tokens = gs.aso().get('mg9_install_tokens', '')
	f = lambda: install(aso_tokens, False)
	gsq.do('GoSublime', f, msg='Installing MarGo', set_status=True)
示例#30
0
文件: mg9.py 项目: OlingCat/GoSublime
			def f():
				gs.aso().set('mg9_install_tokens', _gen_tokens())
				gs.save_aso()
示例#31
0
    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')