MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / shell_words_for_platform

Function shell_words_for_platform

src/hooks/cursor_shell.rs:215–262  ·  view source on GitHub ↗
(command: &str, windows: bool)

Source from the content-addressed store, hash-verified

213}
214
215fn shell_words_for_platform(command: &str, windows: bool) -> Vec<String> {
216 let mut words = Vec::new();
217 let mut current = String::new();
218 let mut quote: Option<char> = None;
219 let mut escaped = false;
220
221 for c in command.chars() {
222 if escaped {
223 current.push(c);
224 escaped = false;
225 continue;
226 }
227
228 match quote {
229 Some('\'') => {
230 if c == '\'' {
231 quote = None;
232 } else {
233 current.push(c);
234 }
235 }
236 Some('"') => match c {
237 '"' => quote = None,
238 '\\' => escaped = true,
239 _ => current.push(c),
240 },
241 _ => match c {
242 '\'' | '"' => quote = Some(c),
243 '\\' if windows => current.push(c),
244 '\\' => escaped = true,
245 c if c.is_whitespace() => {
246 if !current.is_empty() {
247 words.push(std::mem::take(&mut current));
248 }
249 }
250 _ => current.push(c),
251 },
252 }
253 }
254
255 if escaped {
256 current.push('\\');
257 }
258 if !current.is_empty() {
259 words.push(current);
260 }
261 words
262}
263
264fn git_subcommand_pos(tokens: &[String]) -> Option<usize> {
265 if !tokens.first()?.eq_ignore_ascii_case("git") {

Callers 1

shell_wordsFunction · 0.85

Calls 2

pushMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected