Shell completion
(ln: &str)
| 247 | |
| 248 | // Shell completion |
| 249 | pub 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 |