Skip to content

Commit 00a2c84

Browse files
committedMay 28, 2019
Support case-insensitive completion
1 parent 00c04b9 commit 00a2c84

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed
 

‎myinputrc

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ set output-meta on
55
### Don't suggest hidden files unless the dot(.) is provided
66
set match-hidden-files off
77

8-
### TODO:
9-
### set completion-ignore-case on
8+
set completion-ignore-case on
109

1110
### Don't show Display all XXX possibilities? (y or n)
1211
### OTHERWISE sometimes the command will be executed by pybcompgen, which can be very wrong... (eg: 'rm -rf /' !?)
@@ -16,4 +15,8 @@ set completion-query-items 0
1615

1716
set show-all-if-ambiguous on
1817

18+
set completion-display-width 0
19+
20+
# set skip-completed-text on
21+
1922
### Others?

‎pybcompgen.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,15 @@
8787
def remove_control_characters(s):
8888
s = ansi_escape.sub('', s)
8989
s = s.replace('[1@#', '')
90-
return "".join(ch for ch in s if unicodedata.category(ch)[0] != "C")
90+
tmp = "".join(ch for ch in s if ch == '\x08' or unicodedata.category(ch)[0] != "C")
91+
ret = ""
92+
for ch in tmp:
93+
if ch == '\x08':
94+
# NOTE: very inefficient
95+
ret = ret[:-1]
96+
else:
97+
ret += ch
98+
return ret
9199

92100
# NOTE: by adding the void here,
93101
# if bash-completion package is not installed, `complete` won't suggest commands
@@ -170,6 +178,7 @@ def complete(to_complete, cwd=None):
170178

171179
err = err.decode('utf-8')
172180

181+
# import bpdb; bpdb.set_trace()
173182
# print(err)
174183
lines = err.split('\n')
175184
for i in range(len(lines)):
@@ -200,7 +209,7 @@ def complete(to_complete, cwd=None):
200209
# Pagination indicators like '--More--'must be removed
201210
lines = [line for line in lines if not line.startswith('--More')]
202211
last_marker = len(lines) - 3
203-
first_marker+=1
212+
# first_marker+=1
204213

205214
complete_lines = lines[first_marker+2:last_marker-1]
206215

@@ -219,6 +228,13 @@ def complete(to_complete, cwd=None):
219228
return []
220229

221230
the_line = remove_control_characters(the_line)
231+
232+
i1 = the_line.lower().rfind(to_complete.lower())
233+
subs = the_line[i1:i1+len(to_complete)]
234+
if subs.lower() == to_complete.lower():
235+
# print("yes")
236+
to_complete = subs
237+
222238
tmp = the_line[the_line.rfind(to_complete)+len(to_complete):]
223239
if to_complete.endswith(' '):
224240
# result = to_complete.split()[-1] + ' ' + tmp

‎static/app.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ var updateCompleter = function(suggestions, prefix, reupdateCompleter, addSpaceA
2626
c.innerHTML = ''
2727
c.innerHTML = s.join('')
2828
c.scrollLeft = 0
29-
var lastInput = ''
29+
var lastInput = prefix
3030
$('.suggestion').on('click', function (evt) {
3131
var word = evt.currentTarget.dataset.value
3232
if(lastInput) {
3333
Terminal.backspaceNTimes(lastInput.length)
3434
}
35-
lastInput = word.slice(prefix.length, word.length)
35+
lastInput = word
3636
if(addSpaceAtEnd) {
3737
lastInput += ' ' // input an extra space at the end
3838
}

‎static/worker.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,18 @@ _getCompletionsAtLoc['bash'] = function(cb) {
156156
if(prevSpacePos > -1) {
157157
var prevToken = json.line.slice(prevSpacePos+1, json.point)
158158
}
159+
159160
if(json2.data.length > 1) {
160-
var prefix = sharedStart(json2.data)
161+
var prefix = sharedStart(json2.data.map(function(s) { return s.toLowerCase() }))
161162
if (prevToken) {
162163
var prevSlashPos = prevToken.lastIndexOf('/')
163164
if (prevSlashPos > -1) {
164-
prefix = sharedStart([prefix, prevToken.slice(prevSlashPos+1)])
165+
prefix = sharedStart([prefix, prevToken.slice(prevSlashPos+1).toLowerCase()])
165166
} else {
166-
prefix = sharedStart([prefix, prevToken])
167+
prefix = sharedStart([prefix, prevToken.toLowerCase()])
167168
}
169+
} else {
170+
prefix = ''
168171
}
169172
var reupdateCompleter = true
170173
} else if(json2.data.length === 0) {
@@ -177,6 +180,7 @@ _getCompletionsAtLoc['bash'] = function(cb) {
177180
prefix = ''
178181
}
179182
}
183+
180184
console.log("prefix 2", prefix)
181185
var data = {
182186
completions: json2.data,

0 commit comments

Comments
 (0)
Please sign in to comment.