add command g to switch shell quickly (#4014)

Signed-off-by: Tw <tw19881113@gmail.com>
This commit is contained in:
Tw
2021-09-17 17:39:14 +08:00
committed by GitHub
parent bd0baa961c
commit 1297499d7a
6 changed files with 70 additions and 0 deletions

View File

@ -177,6 +177,9 @@ impl Iterator for InternalIterator {
CommandAction::NextShell => {
self.context.shell_manager().next();
}
CommandAction::GotoShell(i) => {
self.context.shell_manager().goto(i);
}
CommandAction::LeaveShell(code) => {
self.context.shell_manager().remove_at_current();
if self.context.shell_manager().is_empty() {

View File

@ -136,6 +136,16 @@ impl ShellManager {
self.set_path(self.path())
}
pub fn goto(&self, i: usize) {
{
let shell_len = self.shells.lock().len();
if i < shell_len {
self.current_shell.store(i, Ordering::SeqCst);
}
}
self.set_path(self.path())
}
pub fn homedir(&self) -> Option<PathBuf> {
let env = self.shells.lock();