示例#1
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'))
示例#2
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"))
 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 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)
示例#5
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)
示例#6
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))
示例#7
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))
示例#8
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')
示例#9
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')
示例#10
0
 def f():
     gs.aso().set('install_version', INSTALL_VERSION)
     gs.save_aso()
示例#11
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'))
示例#12
0
			def f():
				gs.aso().set('mg9_install_tokens', _gen_tokens())
				gs.save_aso()
示例#13
0
文件: mg9.py 项目: OlingCat/GoSublime
			def f():
				gs.aso().set('mg9_install_tokens', _gen_tokens())
				gs.save_aso()
示例#14
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')
示例#15
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'))
示例#16
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')
示例#17
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')
示例#18
0
文件: mg9.py 项目: allanw1/Arianrhod
			def f():
				gs.aso().set('install_version', INSTALL_VERSION)
				gs.save_aso()
示例#19
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')