我想知道是否可以使bash自动完成突出显示自动完成建议的匹配部分。
例如, 我有包含以下文件的目录:
LSFJOB_647169535/ LSFJOB_647158534/
在这种情况下,如果我输入LSF
并点击 Tab ,那么我得到:
LSFJOB_6471
但是接下来我必须集中精力让我接下来要输入哪个角色。
我想要bash给我一些建议:
LSFJOB_647169535/ LSFJOB_647158534/
或
LSFJOB_647169535/ LSFJOB_647158534/
你知道这样做的方法吗?
答案 0 :(得分:1)
这是个好问题!
Dennis Williamson已经回答了there(超级用户)。
事实证明,有一个“ReadLine变量”就是这样做的:<!DOCTYPE html>
<html>
<head>
</head>
<body>
<input type="file">
<progress value="0" max="0" step="1"></progress>
<script>
const [url, stream, header] = ["data.php", "stream.php", "x-filename"];
const [input, progress, handleFile] = [
document.querySelector("input[type=file]")
, document.querySelector("progress")
, (event) => {
const [file] = input.files;
const [{size:filesize, name:filename}, headers, params] = [
file, new Headers(), new URLSearchParams()
];
// set `filename`, `filesize` as search parameters for `stream` URL
Object.entries({filename, filesize})
.forEach(([...props]) => params.append.apply(params, props));
// set header for `POST`
headers.append(header, filename);
// reset `progress.value` set `progress.max` to `filesize`
[progress.value, progress.max] = [0, filesize];
const [request, source] = [
new Request(url, {
method:"POST", headers:headers, body:file
})
// https://stackoverflow.com/a/42330433/
, new EventSource(`${stream}?${params.toString()}`)
];
source.addEventListener("message", (e) => {
// update `progress` here,
// call `.close()` when `e.data === filesize`
// `progress.value = e.data`, should be this simple
console.log(e.data, e.lastEventId);
}, true);
source.addEventListener("open", (e) => {
console.log("fetch upload progress open");
}, true);
source.addEventListener("error", (e) => {
console.error("fetch upload progress error");
}, true);
// sanity check for tests,
// we don't need `source` when `e.data === filesize`;
// we could call `.close()` within `message` event handler
setTimeout(() => source.close(), 30000);
// we don't need `source' to be in `Promise` chain,
// though we could resolve if `e.data === filesize`
// before `response`, then wait for `.text()`; etc.
// TODO: if and where to merge or branch `EventSource`,
// `fetch` to single or two `Promise` chains
const upload = fetch(request);
upload
.then(response => response.text())
.then(res => console.log(res))
.catch(err => console.error(err));
}
];
input.addEventListener("change", handleFile, true);
</script>
</body>
</html>
。
可悲的是,它仅适用于 Bash v4.4 :c Link to the diff
您可以使用colored-completion-prefix
我尝试使用bind -v|grep color
,但它似乎剥离了颜色/:
答案 1 :(得分:1)
您可以添加较旧的版本(Bash 4.0),而不是需要Bash 4.4的colored-completion-prefix
set completion-prefix-display-length 2
到您的~/.inputrc
(请参阅manual)。当显示补全时,这将用省略号替换任何超过2个字符的通用前缀:
$ ls
LSFJOB_647158534 LSFJOB_647169535
$ cd LSFJOB_6471<tab>
...58534/ ...69535/