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 button to Discord RP #111

Merged
merged 9 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions DiscordRichPresence.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
// Use the language icon as the big icon, overrides 'small_icon'
"big_icon": true,

// Show button for opening git repository on browser
"git_repository_button": false,

// Default message for git repository button (supports format)
"git_repository_message": "Open Repository",

// Defines the order of name sources that should be used for the project name in format stings, if available.
//
// "project_file_name" - The name of the .sublime-project file.
Expand Down
24 changes: 24 additions & 0 deletions drp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import time
import re
from time import mktime

import sublime
Expand Down Expand Up @@ -230,6 +231,13 @@ def handle_activity(view, is_write=False, idle=False):
if settings.get('show_elapsed_time'):
act['timestamps'] = {'start': stamp}

if settings.get('git_repository_button'):
git_url = get_git_url(window)
git_btn_format = settings.get('git_repository_message')

if git_btn_format and git_url is not None:
act['buttons'] = [{'label': git_btn_format.format(**format_dict), 'url': git_url}]

logger.info(window.folders())
try:
ipc.set_activity(act)
Expand All @@ -256,6 +264,22 @@ def handle_error(exc, retry=True):
sublime.set_timeout_async(connect_background, 0)


def get_git_url(window):
for folder in window.folders():
gitcfg_path = folder+"/.git/config"

if (os.path.exists(gitcfg_path)):
f = open(gitcfg_path, "r")
FichteFoll marked this conversation as resolved.
Show resolved Hide resolved
filteredConfig = ''.join(f.read().split())
ma = re.search("\[remote\"origin\"\]url=(.*)\.git", filteredConfig)
DryByte marked this conversation as resolved.
Show resolved Hide resolved
if ma is None:
continue

return ma.group(1)

return None


def get_project_name(window, current_file):
sources = settings.get("project_name", [])
for source in sources:
Expand Down