blob: ad6db26194b0624aeafbb596c6f0c033e2d5d40e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
use std::path;
use crate::commands::reload;
use crate::context::AppContext;
use crate::error::JoshutoResult;
use crate::history::DirectoryHistory;
// ChangeDirectory command
pub fn cd(path: &path::Path, context: &mut AppContext) -> std::io::Result<()> {
std::env::set_current_dir(path)?;
context.tab_context_mut().curr_tab_mut().set_cwd(path);
Ok(())
}
pub fn change_directory(context: &mut AppContext, path: &path::Path) -> JoshutoResult {
let new_cwd = if path.is_absolute() {
path.canonicalize()?
} else {
let mut new_cwd = std::env::current_dir()?;
new_cwd.push(path.canonicalize()?);
new_cwd
};
cd(new_cwd.as_path(), context)?;
let options = context.config_ref().display_options_ref().clone();
let ui_context = context.ui_context_ref().clone();
context
.tab_context_mut()
.curr_tab_mut()
.history_mut()
.populate_to_root(new_cwd.as_path(), &ui_context, &options)?;
Ok(())
}
// ParentDirectory command
pub fn parent_directory(context: &mut AppContext) -> JoshutoResult {
if let Some(parent) = context
.tab_context_ref()
.curr_tab_ref()
.cwd()
.parent()
.map(|p| p.to_path_buf())
{
std::env::set_current_dir(&parent)?;
context
.tab_context_mut()
.curr_tab_mut()
.set_cwd(parent.as_path());
reload::soft_reload(context.tab_context_ref().index, context)?;
}
Ok(())
}
// PreviousDirectory command
pub fn previous_directory(context: &mut AppContext) -> JoshutoResult {
if let Some(path) = context.tab_context_ref().curr_tab_ref().previous_dir() {
let path = path.to_path_buf();
std::env::set_current_dir(&path)?;
context
.tab_context_mut()
.curr_tab_mut()
.set_cwd(path.as_path());
reload::soft_reload(context.tab_context_ref().index, context)?;
}
Ok(())
}
|