private async contributorCopyToClipboard(node: ContributorNode) { if (!(node instanceof ContributorNode)) return; await env.clipboard.writeText( `${node.contributor.name}${node.contributor.email ? ` <${node.contributor.email}>` : ''}` ); }
async execute(editor?: TextEditor, uri?: Uri, args: CopyShaToClipboardCommandArgs = {}) { uri = getCommandUri(uri, editor); try { args = { ...args }; // If we don't have an editor then get the sha of the last commit to the branch if (uri == null) { const repoPath = await Container.git.getActiveRepoPath(editor); if (!repoPath) return undefined; const log = await Container.git.getLog(repoPath, { maxCount: 1 }); if (!log) return undefined; args.sha = Iterables.first(log.commits.values()).sha; } else if (args.sha === undefined) { const blameline = (editor && editor.selection.active.line) || 0; if (blameline < 0) return undefined; try { const gitUri = await GitUri.fromUri(uri); const blame = editor && editor.document && editor.document.isDirty ? await Container.git.getBlameForLineContents(gitUri, blameline, editor.document.getText()) : await Container.git.getBlameForLine(gitUri, blameline); if (blame === undefined) return undefined; args.sha = blame.commit.sha; } catch (ex) { Logger.error(ex, 'CopyShaToClipboardCommand', `getBlameForLine(${blameline})`); return Messages.showGenericErrorMessage('Unable to copy commit id'); } } void (await env.clipboard.writeText(args.sha)); return undefined; } catch (ex) { if (ex.message.includes("Couldn't find the required `xsel` binary")) { window.showErrorMessage( 'Unable to copy commit id, xsel is not installed. Please install it via your package manager, e.g. `sudo apt install xsel`' ); return undefined; } Logger.error(ex, 'CopyShaToClipboardCommand'); return Messages.showGenericErrorMessage('Unable to copy commit id'); } }
export async function writeBytecodeToBuffer(uri: Uri): Promise<void> { const contract = await readCompiledContract(uri); env.clipboard.writeText(contract[Constants.contractProperties.bytecode]); }
export async function writeAbiToBuffer(uri: Uri): Promise<void> { const contract = await readCompiledContract(uri); env.clipboard.writeText(JSON.stringify(contract[Constants.contractProperties.abi])); }
export async function addDataInClipboard(typeOfData: string, data?: string | null) { if (data) { await env.clipboard.writeText(data); window.showInformationMessage(typeOfData + Constants.dataCopied); } }