Function broot::path::path_str_from
source · Examples found in repository?
src/path/from.rs (line 74)
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
pub fn do_exec_replacement(
ec: &Captures<'_>,
replacement_map: &AHashMap<String, String>,
) -> String {
let name = ec.get(1).unwrap().as_str();
if let Some(repl) = replacement_map.get(name) {
if let Some(fmt) = ec.get(2) {
match fmt.as_str() {
"path-from-directory" => path_str_from(replacement_map.get("directory").unwrap(), repl),
"path-from-parent" => path_str_from(replacement_map.get("parent").unwrap(), repl),
_ => format!("invalid format: {:?}", fmt.as_str()),
}
} else {
repl.to_string()
}
} else {
format!("{{{}}}", name)
}
}
More examples
src/verb/execution_builder.rs (line 171)
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
fn get_raw_sel_capture_replacement(
&self,
ec: &Captures<'_>,
sel: Option<Selection<'_>>,
) -> Option<String> {
let name = ec.get(1).unwrap().as_str();
self.get_raw_sel_name_standard_replacement(name, sel)
.or_else(||{
// it's not one of the standard group names, so we'll look
// into the ones provided by the invocation pattern
self.invocation_values.as_ref()
.and_then(|map| map.get(name))
.and_then(|value| {
if let Some(fmt) = ec.get(2) {
match fmt.as_str() {
"path-from-directory" => {
sel.map(|s| path::closest_dir(s.path))
.map(|dir| path::path_str_from(dir, value))
}
"path-from-parent" => {
sel.and_then(|s| s.path.parent())
.map(|dir| path::path_str_from(dir, value))
}
_ => Some(format!("invalid format: {:?}", fmt.as_str())),
}
} else {
Some(value.to_string())
}
})
})
}