This repository was archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 212
Github code opener from cli #203
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import os | ||
import sys | ||
import pyperclip | ||
|
||
# Install pyperclip module. Linux OS : sudo apt install python3-pyperclip | ||
# otherwise : pip3 install pyperclip | ||
|
||
def github_opener (filename, line_no): | ||
""" | ||
github_opener( filename, line_no ) : | ||
Generates a perma link to the code inside your Github repo which is remote for your current git project. | ||
And copies it to clipboard. | ||
|
||
Parameters: | ||
github_opener ( filename, line_no ) : takes two arguments. | ||
Filename in which the code is and line no which you want to highlight. | ||
eg. github_opener("hello.py", 8) | ||
|
||
Returns: | ||
Perma link copied to clipboard | ||
|
||
""" | ||
|
||
stream = os.popen('git remote -v | grep "origin"') | ||
cmd_output = stream.readline() #cmd_output => origin git@github:username/proj/name.git (fetch) | ||
info = cmd_output.split(":")[1].split(".")[0] #info => username/proj_name | ||
|
||
curr_dir = os.getcwd() | ||
|
||
proj_name = info.split("/")[1] #proj_name | ||
index = curr_dir.find(proj_name) #start index of proj name in current path | ||
perma_link = "https://github.com/" + info + "/blob/master" + curr_dir[(index+len(proj_name)):] + "/" + filename + "/#L" + line_no | ||
pyperclip.copy(perma_link) | ||
print("Link copied!") | ||
|
||
if __name__ == "__main__": | ||
""" | ||
It takes two command line arguments. | ||
Name of the file (Not complete path with directory) in which the desired line of code is present and | ||
the line number to high light. | ||
Eg. | ||
python github_opener.py mode.py 9 | ||
output: | ||
Link copied! | ||
(Link => https://github.com/username/proj_name/blob/master/directory/mode.py/#L9) | ||
|
||
|
||
In terminal, navigate to the directory in which the file is present. | ||
|
||
Run command : python github_opener.py filename.xyz 23 | ||
|
||
""" | ||
github_opener(sys.argv[1], sys.argv[2]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify sample I/O for your code, You are fetching system arguments so specify the run command in comments.
Everything else LGTM :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SKAUL05 Added sample I/O in comments. Please have a look.