Skip to content
Snippets Groups Projects
Commit 14308c1e authored by stratact's avatar stratact
Browse files

Iterative improvements

parent 615d7b8c
No related branches found
No related tags found
No related merge requests found
...@@ -229,37 +229,28 @@ impl DirectoryStack { ...@@ -229,37 +229,28 @@ impl DirectoryStack {
) )
} }
pub(crate) fn cd<I: IntoIterator>( pub(crate) fn cd(
&mut self, &mut self,
args: I, args: &[small::String],
variables: &Variables, variables: &Variables,
) -> Result<(), Cow<'static, str>> ) -> Result<(), Cow<'static, str>> {
where match args.get(1) {
I::Item: AsRef<str>,
{
match args.into_iter().nth(1) {
Some(dir) => { Some(dir) => {
if let Some(Value::Array(cdpath)) = variables.get_ref("CDPATH") { if let Some(Value::Array(cdpath)) = variables.get_ref("CDPATH") {
let dir = dir.as_ref(); let dir = dir.as_ref();
if dir == "-" { if dir == "-" {
self.switch_to_previous_directory(variables) self.switch_to_previous_directory(variables)
} else { } else {
if !cdpath.is_empty() { let check_cdpath_first = cdpath
for path in cdpath { .iter()
let mut path = path.to_string(); .map(|path| {
path.push('/'); let path_dir = [path, "/", dir].concat();
path.push_str(dir); self.change_and_push_dir(&path_dir, variables)
let res = self.change_and_push_dir(&path, variables); })
if res.is_ok() { .find(Result::is_ok)
self.dirs.remove(1); .unwrap_or_else(|| self.change_and_push_dir(dir, variables));
return res;
}
}
}
let res = self.change_and_push_dir(dir, variables);
self.dirs.remove(1); self.dirs.remove(1);
res check_cdpath_first
} }
} else { } else {
unreachable!(); unreachable!();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment