Skip to content

Commit c4c86c9

Browse files
committed
refactor(utils): remove unused functions
1 parent 44bc24a commit c4c86c9

File tree

1 file changed

+0
-77
lines changed

1 file changed

+0
-77
lines changed

src/utils/shells.rs

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -9,80 +9,3 @@ pub fn is_autojump_sourced() -> bool {
99
Err(_) => false,
1010
}
1111
}
12-
13-
14-
pub fn surround_quotes(s: String) -> String {
15-
if in_bash() {
16-
let mut result = String::with_capacity(s.len() + 2);
17-
result.push('"');
18-
result.push_str(&s);
19-
result.push('"');
20-
result
21-
} else {
22-
s
23-
}
24-
}
25-
26-
27-
fn in_bash() -> bool {
28-
in_bash_internal(env::var("SHELL"))
29-
}
30-
31-
32-
fn in_bash_internal(r: Result<String, env::VarError>) -> bool {
33-
match r {
34-
Ok(v) => v.contains("bash"),
35-
Err(e) => {
36-
match e {
37-
env::VarError::NotPresent => false,
38-
env::VarError::NotUnicode(s) => {
39-
let s = s.to_string_lossy();
40-
s.contains("bash")
41-
}
42-
}
43-
}
44-
}
45-
}
46-
47-
48-
#[cfg(test)]
49-
mod tests {
50-
use super::*;
51-
52-
53-
#[test]
54-
fn test_in_bash_internal_ok() {
55-
assert_eq!(in_bash_internal(Ok(String::from("/bin/bash"))), true);
56-
assert_eq!(in_bash_internal(Ok(String::from("/bin/zsh"))), false);
57-
}
58-
59-
60-
#[test]
61-
fn test_in_bash_internal_err_absent() {
62-
assert_eq!(in_bash_internal(Err(env::VarError::NotPresent)), false);
63-
}
64-
65-
66-
#[cfg(unix)]
67-
#[test]
68-
fn test_in_bash_internal_err_invalid_unicode() {
69-
use std::ffi;
70-
use std::os::unix::ffi::OsStrExt;
71-
72-
let invalid_unicode_factory = |s| {
73-
let mut tmp = ffi::OsString::new();
74-
tmp.push("/some/");
75-
// "测试" (test) is "\xe6\xb5\x8b\xe8\xaf\x95"
76-
// here \xaf is mutated to \xfa to simulate invalid OS strings
77-
tmp.push(ffi::OsStr::from_bytes(&[0xe6, 0xb5, 0x8b, 0xe8, 0xfa, 0x95]));
78-
tmp.push("/prefix/bin/");
79-
tmp.push(s);
80-
Err(env::VarError::NotUnicode(tmp))
81-
};
82-
83-
let invalid_unicode_bash = invalid_unicode_factory("bash");
84-
assert_eq!(in_bash_internal(invalid_unicode_bash), true);
85-
let invalid_unicode_zsh = invalid_unicode_factory("zsh");
86-
assert_eq!(in_bash_internal(invalid_unicode_zsh), false);
87-
}
88-
}

0 commit comments

Comments
 (0)