Skip to content

Commit 1fcba78

Browse files
committed
Simplify
1 parent c6f6af7 commit 1fcba78

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

src/core/builtins/completion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//SPDX-FileCopyrightText: 2023 Ryuichi Ueda <ryuichiueda@gmail.com>
22
//SPDX-License-Identifier: BSD-3-Clause
33

4-
use crate::{ShellCore, Feeder};
4+
use crate::{file_check, ShellCore, Feeder};
55
use crate::elements::word::Word;
66
use crate::utils;
77
use crate::utils::directory;
@@ -138,7 +138,7 @@ pub fn compgen_c(core: &mut ShellCore, args: &mut Vec<String>) -> Vec<String> {
138138
if args.len() > 2 {
139139
commands.extend(compgen_f(core, args));
140140
}
141-
commands.retain(|p| Path::new(p).executable() || Path::new(p).is_dir());
141+
commands.retain(|p| Path::new(p).executable() || file_check::is_dir(p));
142142

143143
let mut aliases: Vec<String> = core.data.aliases.clone().into_keys().collect();
144144
commands.append(&mut aliases);
@@ -158,7 +158,7 @@ pub fn compgen_c(core: &mut ShellCore, args: &mut Vec<String>) -> Vec<String> {
158158

159159
fn compgen_d(core: &mut ShellCore, args: &mut Vec<String>) -> Vec<String> {
160160
let mut paths = compgen_f(core, args);
161-
paths.retain(|p| Path::new(p).is_dir());
161+
paths.retain(|p| file_check::is_dir(&p));
162162
paths
163163
}
164164

src/core/builtins/source.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
//SPDX-FileCopyrightText: 2024 Ryuichi Ueda <ryuichiueda@gmail.com>
22
//SPDX-License-Identifier: BSD-3-Clause
33

4-
use crate::{Script, ShellCore, Feeder};
4+
use crate::{file_check, Script, ShellCore, Feeder};
55
use crate::elements::io;
66
use std::fs::File;
77
use std::os::fd::IntoRawFd;
8-
use std::path::Path;
98

109
pub fn source(core: &mut ShellCore, args: &mut Vec<String>) -> i32 {
1110
if args.len() < 2 {
@@ -14,7 +13,7 @@ pub fn source(core: &mut ShellCore, args: &mut Vec<String>) -> i32 {
1413
return 2;
1514
}
1615

17-
if Path::new(&args[1]).is_dir() {
16+
if file_check::is_dir(&args[1]) {
1817
eprintln!("bash: source: {}: is a directory", &args[1]);
1918
return 1;
2019
}

src/feeder/terminal/completion.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
//SPDX-FileCopyrightText: 2024 Ryuichi Ueda ryuichiueda@gmail.com
22
//SPDX-License-Identifier: BSD-3-Clause
33

4-
use crate::{error_message, Feeder, ShellCore, utils};
4+
use crate::{error_message, file_check, Feeder, ShellCore, utils};
55
use crate::core::builtins::completion;
66
use crate::elements::command::simple::SimpleCommand;
77
use crate::elements::command::Command;
88
use crate::elements::io::pipe::Pipe;
99
use crate::feeder::terminal::Terminal;
10-
use std::path::Path;
1110
use termion::cursor::DetectCursorPos;
1211
use unicode_width::UnicodeWidthStr;
1312

@@ -45,7 +44,7 @@ fn is_dir(s: &str, core: &mut ShellCore) -> bool {
4544
let tilde_prefix = "~/".to_string();
4645
let tilde_path = core.data.get_param("HOME").to_string() + "/";
4746

48-
Path::new(&s.replace(&tilde_prefix, &tilde_path)).is_dir()
47+
file_check::is_dir(&s.replace(&tilde_prefix, &tilde_path))
4948
}
5049

5150
impl Terminal {

0 commit comments

Comments
 (0)