Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add git remote add/rm/show command #432

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
]
}
Expand Down
56 changes: 56 additions & 0 deletions remote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python
#coding:utf-8
# Author : tuxpy
# Email : [email protected]
# 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()