@@ -29,7 +29,7 @@ const postProcessTrackedFiles: Fig.Generator["postProcess"] = (
29
29
30
30
try {
31
31
ext = file . split ( "." ) . slice ( - 1 ) [ 0 ] ;
32
- } catch ( e ) { }
32
+ } catch ( e ) { }
33
33
34
34
if ( file . endsWith ( "/" ) ) {
35
35
ext = "folder" ;
@@ -53,67 +53,67 @@ interface PostProcessBranchesOptions {
53
53
54
54
const postProcessBranches =
55
55
( options : PostProcessBranchesOptions = { } ) : Fig . Generator [ "postProcess" ] =>
56
- ( out ) => {
57
- const { insertWithoutRemotes = false } = options ;
56
+ ( out ) => {
57
+ const { insertWithoutRemotes = false } = options ;
58
58
59
- const output = filterMessages ( out ) ;
59
+ const output = filterMessages ( out ) ;
60
60
61
- if ( output . startsWith ( "fatal:" ) ) {
62
- return [ ] ;
63
- }
61
+ if ( output . startsWith ( "fatal:" ) ) {
62
+ return [ ] ;
63
+ }
64
64
65
- const seen = new Set < string > ( ) ;
66
- return output
67
- . split ( "\n" )
68
- . filter ( ( line ) => ! line . trim ( ) . startsWith ( "HEAD" ) )
69
- . map ( ( branch ) => {
70
- let name = branch . trim ( ) ;
71
- const parts = branch . match ( / \S + / g) ;
72
- if ( parts && parts . length > 1 ) {
73
- if ( parts [ 0 ] === "*" ) {
74
- // We are in a detached HEAD state
75
- if ( branch . includes ( "HEAD detached" ) ) {
76
- return null ;
65
+ const seen = new Set < string > ( ) ;
66
+ return output
67
+ . split ( "\n" )
68
+ . filter ( ( line ) => ! line . trim ( ) . startsWith ( "HEAD" ) )
69
+ . map ( ( branch ) => {
70
+ let name = branch . trim ( ) ;
71
+ const parts = branch . match ( / \S + / g) ;
72
+ if ( parts && parts . length > 1 ) {
73
+ if ( parts [ 0 ] === "*" ) {
74
+ // We are in a detached HEAD state
75
+ if ( branch . includes ( "HEAD detached" ) ) {
76
+ return null ;
77
+ }
78
+ // Current branch
79
+ return {
80
+ name : branch . replace ( "*" , "" ) . trim ( ) ,
81
+ description : "Current branch" ,
82
+ priority : 100 ,
83
+ icon : "⭐️" ,
84
+ } ;
85
+ } else if ( parts [ 0 ] === "+" ) {
86
+ // Branch checked out in another worktree.
87
+ name = branch . replace ( "+" , "" ) . trim ( ) ;
77
88
}
78
- // Current branch
79
- return {
80
- name : branch . replace ( "*" , "" ) . trim ( ) ,
81
- description : "Current branch" ,
82
- priority : 100 ,
83
- icon : "⭐️" ,
84
- } ;
85
- } else if ( parts [ 0 ] === "+" ) {
86
- // Branch checked out in another worktree.
87
- name = branch . replace ( "+" , "" ) . trim ( ) ;
88
89
}
89
- }
90
90
91
- let description = "Branch" ;
91
+ let description = "Branch" ;
92
92
93
- if ( insertWithoutRemotes && name . startsWith ( "remotes/" ) ) {
94
- name = name . slice ( name . indexOf ( "/" , 8 ) + 1 ) ;
95
- description = "Remote branch" ;
96
- }
93
+ if ( insertWithoutRemotes && name . startsWith ( "remotes/" ) ) {
94
+ name = name . slice ( name . indexOf ( "/" , 8 ) + 1 ) ;
95
+ description = "Remote branch" ;
96
+ }
97
97
98
- const space = name . indexOf ( " " ) ;
99
- if ( space !== - 1 ) {
100
- name = name . slice ( 0 , space ) ;
101
- }
98
+ const space = name . indexOf ( " " ) ;
99
+ if ( space !== - 1 ) {
100
+ name = name . slice ( 0 , space ) ;
101
+ }
102
102
103
- return {
104
- name,
105
- description,
106
- icon : "fig://icon?type=git" ,
107
- priority : 75 ,
108
- } ;
109
- } )
110
- . filter ( ( suggestion ) => {
111
- if ( ! suggestion ) return false ;
112
- if ( seen . has ( suggestion . name ) ) return false ;
113
- seen . add ( suggestion . name ) ;
114
- return true ;
115
- } ) ;
116
- } ;
103
+ return {
104
+ name,
105
+ description,
106
+ icon : "fig://icon?type=git" ,
107
+ priority : 75 ,
108
+ } ;
109
+ } )
110
+ . filter ( ( suggestion ) => {
111
+ if ( ! suggestion ) return false ;
112
+ if ( seen . has ( suggestion . name ) ) return false ;
113
+ seen . add ( suggestion . name ) ;
114
+ return true ;
115
+ } ) ;
116
+ } ;
117
117
118
118
export const gitGenerators : Record < string , Fig . Generator > = {
119
119
// Commit history
@@ -126,11 +126,17 @@ export const gitGenerators: Record<string, Fig.Generator> = {
126
126
return [ ] ;
127
127
}
128
128
129
- return output . split ( "\n" ) . map ( ( line ) => {
129
+ const lines = output . split ( "\n" ) ;
130
+ const firstLine = lines . length > 0 ? lines [ 0 ] : undefined ;
131
+ const hashLength =
132
+ firstLine && firstLine . length > 0 ? firstLine . indexOf ( " " ) : 7 ;
133
+ const descriptionStart = hashLength + 1 ;
134
+
135
+ return lines . map ( ( line ) => {
130
136
return {
131
- name : line . substring ( 0 , 7 ) ,
137
+ name : line . substring ( 0 , hashLength ) ,
132
138
icon : "fig://icon?type=node" ,
133
- description : line . substring ( 7 ) ,
139
+ description : line . substring ( descriptionStart ) ,
134
140
} ;
135
141
} ) ;
136
142
} ,
@@ -426,7 +432,7 @@ export const gitGenerators: Record<string, Fig.Generator> = {
426
432
let ext = "" ;
427
433
try {
428
434
ext = file . split ( "." ) . slice ( - 1 ) [ 0 ] ;
429
- } catch ( e ) { }
435
+ } catch ( e ) { }
430
436
431
437
if ( file . endsWith ( "/" ) ) {
432
438
ext = "folder" ;
0 commit comments