From e397accc1788491b303c391411b6bdf667d9e361 Mon Sep 17 00:00:00 2001 From: tuxpy Date: Fri, 28 Aug 2015 02:46:37 +0800 Subject: [PATCH] add git remote add/rm/show command --- Default.sublime-commands | 12 +++++++++ Main.sublime-menu | 8 ++++++ remote.py | 56 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 remote.py diff --git a/Default.sublime-commands b/Default.sublime-commands index 2adddd11..6001705b 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -166,6 +166,18 @@ "caption": "Git: Custom Command", "command": "git_custom" } + ,{ + "caption": "Git: Remote Add", + "command": "git_remote_add" + } + ,{ + "caption": "Git: Remote Remove", + "command": "git_remote_remove" + } + ,{ + "caption": "Git: Remote Show", + "command": "git_remote_show" + } ,{ "caption": "Git Flow: Feature Start", "command": "git_flow_feature_start" diff --git a/Main.sublime-menu b/Main.sublime-menu index a88db6e5..ce22929e 100644 --- a/Main.sublime-menu +++ b/Main.sublime-menu @@ -85,6 +85,14 @@ ,{ "caption": "Status...", "command": "git_status" } ,{ "caption": "Branches...", "command": "git_branch" } ,{ "caption": "Merge...", "command": "git_merge" } + ,{ "caption": "Remote...", + "children": + [ + { "caption": "add", "command": "git_remote_add"} + ,{ "caption": "remove", "command": "git_remote_remove"} + ,{ "caption": "show", "command": "git_remote_show"} + ] + } ,{ "caption": "See commit history...", "command": "git_commit_history"} ] } diff --git a/remote.py b/remote.py new file mode 100644 index 00000000..6005ee27 --- /dev/null +++ b/remote.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +#coding:utf-8 +# Author : tuxpy +# Email : q8886888@qq.com.com +# Last modified : 2015-08-28 00:48:42 +# Filename : remote.py +# Description : +import sublime +from git import GitWindowCommand + +class GitRemoteCommand(GitWindowCommand): + def is_enabled(self): + return True + + def list_remote(self): + self.run_command(['git', 'remote', '-v'], self.show_remote) + + def show_remote(self, result): + _remote_hash = {} + for line in result.strip().split('\n'): + remote_name, remote_url = [ field.strip() for field in line.split()[:2]] + _remote_hash[remote_name] = remote_url + + self.results = [ list(item) for item in _remote_hash.items() ] + self.quick_panel(self.results, self.panel_done, sublime.MONOSPACE_FONT) + + def panel_done(self, picked): + print(picked) + +class GitRemoteAddCommand(GitRemoteCommand): + def run(self): + self.get_window().show_input_panel('Remote Name:Url', '', self.remote_add, None, None) + + def remote_add(self, remote_string): + if ':' not in remote_string: + sublime.status_message('Usage remote_name:remote_url') + return + + remote_params = [ param.strip() for param in remote_string.split(':', 1)] + + self.run_command(['git', 'remote', 'add'] + remote_params) + +class GitRemoteRemoveCommand(GitRemoteCommand): + def run(self): + self.list_remote() + + def panel_done(self, picked): + if picked >= len(self.results) or picked < 0: + return + remote = self.results[picked] + self.run_command(['git', 'remote' , 'rm', remote[0]]) + +class GitRemoteShowCommand(GitRemoteCommand): + def run(self): + self.list_remote() +