Skip to content

Commit

Permalink
Use --show-current for the git branch element
Browse files Browse the repository at this point in the history
The --show-current option has been introduced in git 2.22.0.
https://www.git-scm.com/docs/git-branch#Documentation/git-branch.txt---show-current
  • Loading branch information
Scriptim committed Apr 8, 2024
1 parent 4b3cec5 commit 81a507c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
11 changes: 1 addition & 10 deletions src/lib/enum/promptElementType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,7 @@ export const PROMPT_ELEMENT_TYPES = [
new PromptElementType('Jobs', '\\j', [], true, false, 'The number of jobs currently managed by the shell.', '2'),
new PromptElementType('Prompt Sign', '\\$', [], true, false, 'If the effective uid is 0, #, otherwise $.', '$'),
new PromptElementType('Exit Status', '$?', [], true, false, 'Exit status ($?).', '0'),
new PromptElementType(
'Git Branch',
// eslint-disable-next-line quotes
"git branch 2>/dev/null | grep '*' | colrm 1 2",
[],
true,
true,
'Git branch.',
'master',
),
new PromptElementType('Git Branch', 'git branch --show-current 2>/dev/null', [], true, true, 'Git branch.', 'master'),
new PromptElementType(
'Advanced Git Prompt',
(args) => `__git_ps1 "${args.format ?? ''}"`,
Expand Down
7 changes: 6 additions & 1 deletion src/lib/promptParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,12 @@ function applyPromptCommand(ps1: PromptElement[], promptCommand: string): Prompt
}

// use the predefined command elements (e. g. 'Git branch') if possible
const predefinedCommand = PROMPT_ELEMENT_TYPES.find((e) => e.command && e.char({}) === command);
let predefinedCommand = PROMPT_ELEMENT_TYPES.find((e) => e.command && e.char({}) === command);
// backwards compatibility for the git branch command (replaces the old command with the new one)
// eslint-disable-next-line quotes
if (command === "git branch 2>/dev/null | grep '*' | colrm 1 2") {
predefinedCommand = getPromptElementTypeByNameUnsafe('Git Branch');
}
let newElement: PromptElement;
if (predefinedCommand !== undefined) {
newElement = new PromptElement(predefinedCommand);
Expand Down

0 comments on commit 81a507c

Please sign in to comment.