Skip to content

Commit b31b09c

Browse files
committed
Closes #2980 add new format tokens
1 parent f0def4a commit b31b09c

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1010

1111
- Adds [Cursor](https://cursor.so) support — closes [#3222](https://github.com/gitkraken/vscode-gitlens/issues/3222)
1212
- Adds monospace formatting in commit messages — closes [#2350](https://github.com/gitkraken/vscode-gitlens/issues/2350)
13+
- Adds a new `${authorFirst}` and `${authorLast}` commit formatting tokens that can be used in inline blame, commit hovers, etc — closes [#2980](https://github.com/gitkraken/vscode-gitlens/issues/2980)
1314

1415
### Changed
1516

src/git/formatters/commitFormatter.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export interface CommitFormatOptions extends FormatOptions {
7878
agoOrDate?: TokenOptions;
7979
agoOrDateShort?: TokenOptions;
8080
author?: TokenOptions;
81+
authorFirst?: TokenOptions;
82+
authorLast?: TokenOptions;
8183
authorAgo?: TokenOptions;
8284
authorAgoOrDate?: TokenOptions;
8385
authorAgoOrDateShort?: TokenOptions;
@@ -201,8 +203,21 @@ export class CommitFormatter extends Formatter<GitCommit, CommitFormatOptions> {
201203
}
202204

203205
get author(): string {
204-
let { name, email } = this._item.author;
205-
const author = this._padOrTruncate(name, this._options.tokenOptions.author);
206+
return this.formatAuthor(this._item.author.name, this._item.author.email, this._options.tokenOptions.author);
207+
}
208+
209+
get authorFirst(): string {
210+
const [first] = this._item.author.name.split(' ');
211+
return this.formatAuthor(first, this._item.author.email, this._options.tokenOptions.authorFirst);
212+
}
213+
214+
get authorLast(): string {
215+
const [first, last] = this._item.author.name.split(' ');
216+
return this.formatAuthor(last || first, this._item.author.email, this._options.tokenOptions.authorLast);
217+
}
218+
219+
private formatAuthor(name: string, email: string | undefined, tokenOptions: TokenOptions | undefined): string {
220+
const author = this._padOrTruncate(name, tokenOptions);
206221

207222
switch (this._options.outputFormat) {
208223
case 'markdown':

src/webviews/apps/settings/settings.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,14 @@ <h3 class="token-popup__title">Available Tokens</h3>
400400
<td>Commit Author</td>
401401
<td><span class="token" data-token="author">author</span></td>
402402
</tr>
403+
<tr>
404+
<td>Commit Author First Name</td>
405+
<td><span class="token" data-token="authorFirst">authorFirst</span></td>
406+
</tr>
407+
<tr>
408+
<td>Commit Author Last Name</td>
409+
<td><span class="token" data-token="authorLast">authorLast</span></td>
410+
</tr>
403411
<tr>
404412
<td>Commit Author (except you)</td>
405413
<td><span class="token" data-token="authorNotYou">authorNotYou</span></td>

0 commit comments

Comments
 (0)