@@ -5,7 +5,6 @@ local make_entry = require('telescope.make_entry')
5
5
local pickers = require (' telescope.pickers' )
6
6
local previewers = require (' telescope.previewers' )
7
7
local utils = require (' telescope.utils' )
8
- local entry_display = require (' telescope.pickers.entry_display' )
9
8
10
9
local conf = require (' telescope.config' ).values
11
10
@@ -78,81 +77,32 @@ git.bcommits = function(opts)
78
77
end
79
78
80
79
git .branches = function (opts )
81
- local format = ' {'
82
- .. ' "head":%(if:equals=*)%(HEAD)%(then)true%(else)false%(end)'
83
- .. ' ,"refname":"%(refname)"'
84
- .. ' ,"authorname":"%(authorname)"'
85
- .. ' %(if)%(upstream)%(then)'
86
- .. ' ,"upstream":"%(upstream:lstrip=2)"'
87
- .. ' %(else)'
88
- .. ' ,"upstream":""'
89
- .. ' %(end)'
90
- .. ' ,"committerdate":"%(committerdate:format-local:%Y/%m/%d %H:%M:%S)"'
91
- .. ' }'
92
- local output = utils .get_os_command_output ({ ' git' , ' for-each-ref' , ' --format' , format }, opts .cwd )
80
+ local output = utils .get_os_command_output ({ ' git' , ' branch' , ' --all' }, opts .cwd )
93
81
94
82
local results = {}
95
- local widths = {
96
- name = 0 ,
97
- authorname = 0 ,
98
- upstream = 0 ,
99
- committerdate = 0 ,
100
- }
101
- local register_entry = function (entry , trim_refname_prefix )
102
- entry .name = string.sub (entry .refname , string.len (trim_refname_prefix )+ 1 )
103
- for key , value in pairs (widths ) do
104
- widths [key ] = math.max (value , vim .fn .strdisplaywidth (entry [key ]))
105
- end
106
- if string.len (entry .upstream ) > 0 then
107
- widths .upstream_indicator = 2
108
- end
109
- table.insert (results , entry )
110
- end
111
83
for _ , v in ipairs (output ) do
112
- local entry = vim .fn .json_decode (v )
113
- if entry .head then
114
- goto continue
115
- elseif vim .startswith (entry .refname , ' refs/remotes/' ) then
116
- register_entry (entry , ' refs/remotes/' )
117
- elseif vim .startswith (entry .refname , ' refs/heads/' ) then
118
- register_entry (entry , ' refs/heads/' )
84
+ if not string.match (v , ' HEAD' ) and v ~= ' ' then
85
+ if vim .startswith (v , ' *' ) then
86
+ table.insert (results , 1 , v )
87
+ else
88
+ table.insert (results , v )
89
+ end
119
90
end
120
- :: continue::
121
- end
122
- if # results == 0 then
123
- return
124
- end
125
-
126
- local displayer = entry_display .create {
127
- separator = " " ,
128
- items = {
129
- { width = widths .name },
130
- { width = widths .authorname },
131
- { width = widths .upstream_indicator },
132
- { width = widths .upstream },
133
- { width = widths .committerdate },
134
- }
135
- }
136
-
137
- local make_display = function (entry )
138
- return displayer {
139
- {entry .name , ' TelescopeResultsIdentifier' },
140
- {entry .authorname },
141
- {string.len (entry .upstream ) > 0 and ' =>' or ' ' },
142
- {entry .upstream , ' TelescopeResultsIdentifier' },
143
- {entry .committerdate }
144
- }
145
91
end
146
92
147
93
pickers .new (opts , {
148
94
prompt_title = ' Git Branches' ,
149
95
finder = finders .new_table {
150
96
results = results ,
151
97
entry_maker = function (entry )
152
- entry .value = entry .name
153
- entry .ordinal = entry .name
154
- entry .display = make_display
155
- return entry
98
+ local addition = vim .startswith (entry , ' *' ) and ' * ' or ' '
99
+ entry = entry :gsub (' [* ] ' , ' ' )
100
+ entry = entry :gsub (' ^remotes/' , ' ' )
101
+ return {
102
+ value = entry ,
103
+ ordinal = addition .. entry ,
104
+ display = addition .. entry
105
+ }
156
106
end
157
107
},
158
108
previewer = previewers .git_branch_log .new (opts ),
0 commit comments