Skip to content
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ Added blame URL opening feature
Refactored some code

### 2.1.0
Fixed for https remote url
Fixed for https remote url

### 3.0.0
Added feature - Copy File GitHub History url to Clipboard
Optiimized package size
145 changes: 134 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "github-links",
"displayName": "Github Links",
"description": "This extension opens up the github links in your browser",
"version": "2.0.0",
"version": "3.0.0",
"license": "MIT",
"publisher": "riteshksriv",
"engines": {
"vscode": "^1.37.0"
Expand All @@ -16,7 +17,8 @@
"activationEvents": [
"onCommand:extension.github_history",
"onCommand:extension.github_page",
"onCommand:extension.github_blame"
"onCommand:extension.github_blame",
"onCommand:github.links.history_clipboard"
],
"main": "./dist/extension.js",
"contributes": {
Expand All @@ -32,6 +34,10 @@
{
"command": "extension.github_blame",
"title": "Open File GitHub Blame url"
},
{
"command": "github.links.history_clipboard",
"title": "Copy File GitHub History url to Clipboard"
}
]
},
Expand Down Expand Up @@ -60,6 +66,7 @@
"webpack-cli": "^4.8.0"
},
"dependencies": {
"clipboardy": "^2.3.0",
"git-branch": "^2.0.1",
"git-remote-origin-url": "^3.0.0",
"lodash": "^4.17.15",
Expand Down
24 changes: 23 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import _ from 'lodash'
import _, { create } from 'lodash'
import util from 'util'
import gitRemoteOriginUrl from 'git-remote-origin-url'
import branch from 'git-branch'
import voca from 'voca'
import url from './url'
import { exec } from 'child_process'
import simplegit from 'simple-git/promise';
import clipboardy from 'clipboardy';

export function activate(context: vscode.ExtensionContext) {
console.log('Congratulations, your extension "github-links" is now active!');
Expand All @@ -23,9 +25,14 @@ export function activate(context: vscode.ExtensionContext) {
doAction(createBlameUrl, addLineSuffix).then(e => console.log("Opened blame url"))
});

let clipboardHistory = vscode.commands.registerCommand('github.links.history_clipboard', () => {
doActions(() => getUrl(getCurrentFile(), createHistoryUrl), [copy2Clipboard]).then(e => vscode.window.showInformationMessage('Copied URL to clipboard'))
});

context.subscriptions.push(page);
context.subscriptions.push(blame);
context.subscriptions.push(disposable);
context.subscriptions.push(clipboardHistory);
}

function getCurrentFile() {
Expand All @@ -43,6 +50,21 @@ function addLineSuffix(link: string) {
return `${link}#L${lineno}`
}

async function copy2Clipboard(url: string) {
await clipboardy.write(url)
return url
}

type actionFunction = (url: string) => Promise<string>

async function doActions(createUrl: () => Promise<string>, actions: actionFunction[]) : Promise<string> {
let urlPromise = createUrl()
for(let actionFunc of actions) {
urlPromise = urlPromise.then(actionFunc)
}
return await urlPromise
}

async function doAction(createUrl: (a: string, b: string) => string, patchUrl: (a: string) => string = _.identity) {
return getUrl(getCurrentFile(), createUrl)
.then(url => {
Expand Down