fn complete_bin(sh: &shell::Shell, path: &str) -> Vec<Completion> {
    let mut res = Vec::new();
    let (_, fname) = split_path(path);
    let env_path;
    match env::var("PATH") {
        Ok(x) => env_path = x,
        Err(e) => {
            println_stderr!("cicada: env error when complete_bin: {:?}", e);
            return res;
        }
    }

    let mut checker: HashSet<String> = HashSet::new();

    // handle alias, builtins, and functions
    for func in sh.funcs.keys() {
        if !func.starts_with(fname) {
            continue;
        }
        if checker.contains(func) {
            continue;
        }
        checker.insert(func.clone());
        res.push(Completion {
            completion: func.to_owned(),
            display: None,
            suffix: Suffix::Default,
        });
    }
    for alias in sh.alias.keys() {
        if !alias.starts_with(fname) {
            continue;
        }
        if checker.contains(alias) {
            continue;
        }
        checker.insert(alias.clone());
        res.push(Completion {
            completion: alias.to_owned(),
            display: None,
            suffix: Suffix::Default,
        });
    }

    let builtins = vec![
        "alias", "bg", "cd", "cinfo", "exec", "exit", "export", "fg",
        "history", "jobs", "read", "source", "ulimit", "unalias", "vox",
        "minfd", "set",
    ];
    for item in &builtins {
        if !item.starts_with(fname) {
            continue;
        }
        if checker.contains(item.clone()) {
            continue;
        }
        checker.insert(item.to_string());
        res.push(Completion {
            completion: item.to_string(),
            display: None,
            suffix: Suffix::Default,
        });
    }

    let vec_path: Vec<&str> = env_path.split(':').collect();
    let path_list: HashSet<&str> = HashSet::from_iter(vec_path.iter().cloned());

    for p in &path_list {
        if let Ok(list) = read_dir(p) {
            for entry in list {
                if let Ok(entry) = entry {
                    if let Ok(name) = entry.file_name().into_string() {
                        if name.starts_with(fname) {
                            let _mode;
                            match entry.metadata() {
                                Ok(x) => _mode = x,
                                Err(e) => {
                                    println_stderr!("cicada: metadata error: {:?}", e);
                                    continue;
                                }
                            }
                            let mode = _mode.permissions().mode();
                            if mode & 0o111 == 0 {
                                // not binary
                                continue;
                            }
                            if checker.contains(&name) {
                                continue;
                            }

                            let display = None;
                            let suffix = Suffix::Default;
                            checker.insert(name.clone());
                            // TODO: need to handle quoted: `$ "foo#bar"`
                            let name_e = tools::escape_path(&name);
                            res.push(Completion {
                                completion: name_e,
                                display,
                                suffix,
                            });
                        }
                    }
                }
            }
        }
    }
    res
}
/// Returns a sorted list of paths whose prefix matches the given path.
Returns a sorted list of paths whose prefix matches the given path.
Returns a sorted list of paths whose prefix matches the given path .
fn complete_bin(sh: &shell::Shell, path: &str) -> Vec<Completion> {
    let mut res = Vec::new();
    let (_, fname) = split_path(path);
    let env_path;
    match env::var("PATH") {
        Ok(x) => env_path = x,
        Err(e) => {
            println_stderr!("cicada: env error when complete_bin: {:?}", e);
            return res;
        }
    }
    let mut checker: HashSet<String> = HashSet::new();
    // handle alias, builtins, and functions
    for func in sh.funcs.keys() {
        if !func.starts_with(fname) {
            continue;
        }
        if checker.contains(func) {
            continue;
        }
        checker.insert(func.clone());
        res.push(Completion {
            completion: func.to_owned(),
            display: None,
            suffix: Suffix::Default,
        });
    }
    for alias in sh.alias.keys() {
        if !alias.starts_with(fname) {
            continue;
        }
        if checker.contains(alias) {
            continue;
        }
        checker.insert(alias.clone());
        res.push(Completion {
            completion: alias.to_owned(),
            display: None,
            suffix: Suffix::Default,
        });
    }
    let builtins = vec![
        "alias", "bg", "cd", "cinfo", "exec", "exit", "export", "fg",
        "history", "jobs", "read", "source", "ulimit", "unalias", "vox",
        "minfd", "set",
    ];
    for item in &builtins {
        if !item.starts_with(fname) {
            continue;
        }
        if checker.contains(item.clone()) {
            continue;
        }
        checker.insert(item.to_string());
        res.push(Completion {
            completion: item.to_string(),
            display: None,
            suffix: Suffix::Default,
        });
    }
    let vec_path: Vec<&str> = env_path.split(':').collect();
    let path_list: HashSet<&str> = HashSet::from_iter(vec_path.iter().cloned());
    for p in &path_list {
        if let Ok(list) = read_dir(p) {
            for entry in list {
                if let Ok(entry) = entry {
                    if let Ok(name) = entry.file_name().into_string() {
                        if name.starts_with(fname) {
                            let _mode;
                            match entry.metadata() {
                                Ok(x) => _mode = x,
                                Err(e) => {
                                    println_stderr!("cicada: metadata error: {:?}", e);
                                    continue;
                                }
                            }
                            let mode = _mode.permissions().mode();
                            if mode & 0o111 == 0 {
                                // not binary
                                continue;
                            }
                            if checker.contains(&name) {
                                continue;
                            }
                            let display = None;
                            let suffix = Suffix::Default;
                            checker.insert(name.clone());
                            // TODO: need to handle quoted: `$ "foo#bar"`
                            let name_e = tools::escape_path(&name);
                            res.push(Completion {
                                completion: name_e,
                                display,
                                suffix,
                            });
                        }
                    }
                }
            }
        }
    }
    res
}
fn complete_bin ( sh : & shell :: Shell , path : & str ) -> Vec < Completion > { let mut res = Vec :: new ( ) ; let ( _ , fname ) = split_path ( path ) ; let env_path ; match env :: var ( " " ) { Ok ( x ) => env_path = x , Err ( e ) => { println_stderr ! ( " " e ) ; return res ; } } let mut checker : HashSet < String > = HashSet :: new ( ) ; // handle alias, builtins, and functions for func in sh . funcs . keys ( ) { if ! func . starts_with ( fname ) { continue ; } if checker . contains ( func ) { continue ; } checker . insert ( func . clone ( ) ) ; res . push ( Completion { completion : func . to_owned ( ) , display : None , suffix : Suffix :: Default , } ) ; } for alias in sh . alias . keys ( ) { if ! alias . starts_with ( fname ) { continue ; } if checker . contains ( alias ) { continue ; } checker . insert ( alias . clone ( ) ) ; res . push ( Completion { completion : alias . to_owned ( ) , display : None , suffix : Suffix :: Default , } ) ; } let builtins = vec ! [ " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " ] ; for item in & builtins { if ! item . starts_with ( fname ) { continue ; } if checker . contains ( item . clone ( ) ) { continue ; } checker . insert ( item . to_string ( ) ) ; res . push ( Completion { completion : item . to_string ( ) , display : None , suffix : Suffix :: Default , } ) ; } let vec_path : Vec < & str > = env_path . split ( ':' ) . collect ( ) ; let path_list : HashSet < & str > = HashSet :: from_iter ( vec_path . iter ( ) . cloned ( ) ) ; for p in & path_list { if let Ok ( list ) = read_dir ( p ) { for entry in list { if let Ok ( entry ) = entry { if let Ok ( name ) = entry . file_name ( ) . into_string ( ) { if name . starts_with ( fname ) { let _mode ; match entry . metadata ( ) { Ok ( x ) => _mode = x , Err ( e ) => { println_stderr ! ( " " e ) ; continue ; } } let mode = _mode . permissions ( ) . mode ( ) ; if mode & 0o111 == 0 { // not binary continue ; } if checker . contains ( & name ) { continue ; } let display = None ; let suffix = Suffix :: Default ; checker . insert ( name . clone ( ) ) ; // TODO: need to handle quoted: `$ "foo#bar"` let name_e = tools :: escape_path ( & name ) ; res . push ( Completion { completion : name_e , display , suffix , } ) ; } } } } } } res }
Returns a sorted list of paths whose prefix matches the given path.
Returns a sorted list of paths whose prefix matches the given path .
sh
&shell::Shell
path
&str
sh
&shell::Shell
path
&str