MCPcopy Create free account
hub / github.com/LibertyOS-Development/kernel / shcomp

Function shcomp

src/user/shell.rs:249–304  ·  view source on GitHub ↗

Shell completion

(ln: &str)

Source from the content-addressed store, hash-verified

247
248// Shell completion
249pub fn shcomp(ln: &str) -> Vec<String>
250{
251 let mut items = Vec::new();
252
253 let args = splargs(ln);
254 let i = args.len() - 1;
255
256 // Autocomplete command
257 if args.len() == 1
258 {
259 for &cmd in &AUTOCMD
260 {
261 if let Some(item) = cmd.strip_prefix(args[i])
262 {
263 items.push(item.into());
264 }
265 }
266 }
267 // Autocomplete path
268 else
269 {
270 let pname = crate::fs::rpath(args[i]);
271 let dname = crate::fs::dname(&pname);
272 let fname = crate::fs::fname(&pname);
273 let sep = if dname.ends_with('/')
274 {
275 ""
276 }
277 else
278 {
279 "/"
280 };
281
282 if let Some(directory) = crate::fs::directory::Directory::open(dname)
283 {
284 for item in directory.items()
285 {
286 let name = item.name();
287 if name.starts_with(fname)
288 {
289 let end = if item.isdir()
290 {
291 "/"
292 }
293 else
294 {
295 ""
296 };
297 let path = format!("{}{}{}{}", dname, sep, name, end);
298 items.push(path[pname.len()..].into());
299 }
300 }
301 }
302 }
303 items
304}
305
306

Callers

nothing calls this directly

Calls 10

splargsFunction · 0.85
rpathFunction · 0.85
dnameFunction · 0.85
fnameFunction · 0.85
intoMethod · 0.80
itemsMethod · 0.80
isdirMethod · 0.80
openFunction · 0.50
lenMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected