+44
-7
src/cmd/ls.rs
+44
-7
src/cmd/ls.rs
···
80
80
let is_absolute = path_str.starts_with('/');
81
81
let base_path: Arc<vfs::VfsPath> = if is_absolute { get_vfs() } else { pwd.clone() };
82
82
83
-
let options = GlobOptions {
84
-
max_depth: None,
85
-
no_dirs: false,
86
-
no_files: false,
87
-
};
83
+
// Check if it's a glob pattern
84
+
let is_glob = path_str.contains('*')
85
+
|| path_str.contains('?')
86
+
|| path_str.contains('[')
87
+
|| path_str.contains("**");
88
88
89
-
let matches = expand_path(path_str, base_path.clone(), options)?;
90
-
(matches, base_path)
89
+
if is_glob {
90
+
// Glob pattern: expand and list matching paths
91
+
let options = GlobOptions {
92
+
max_depth: None,
93
+
no_dirs: false,
94
+
no_files: false,
95
+
};
96
+
let matches = expand_path(path_str, base_path.clone(), options)?;
97
+
(matches, base_path)
98
+
} else {
99
+
// Non-glob path: check if it's a directory and list its contents
100
+
let normalized_path = path_str.trim_start_matches('/').trim_end_matches('/');
101
+
let target_path = base_path.join(normalized_path)
102
+
.map_err(to_shell_err(call.arguments_span()))?;
103
+
104
+
let metadata = target_path.metadata().map_err(to_shell_err(span))?;
105
+
match metadata.file_type {
106
+
vfs::VfsFileType::Directory => {
107
+
// List directory contents
108
+
let entries = target_path.read_dir().map_err(to_shell_err(span))?;
109
+
let matches: Vec<String> = entries
110
+
.map(|e| {
111
+
// Build relative path from base_path
112
+
let entry_name = e.filename();
113
+
if normalized_path.is_empty() || normalized_path == "." {
114
+
entry_name
115
+
} else {
116
+
format!("{}/{}", normalized_path, entry_name)
117
+
}
118
+
})
119
+
.collect();
120
+
(matches, base_path)
121
+
}
122
+
vfs::VfsFileType::File => {
123
+
// Single file: return just this file (normalized, relative to base_path)
124
+
(vec![normalized_path.to_string()], base_path)
125
+
}
126
+
}
127
+
}
91
128
} else {
92
129
// No path: list current directory entries
93
130
let entries = pwd.read_dir().map_err(to_shell_err(span))?;