MCPcopy Create free account
hub / github.com/codeaashu/claude-code / isSearchOrReadBashCommand

Function isSearchOrReadBashCommand

src/tools/BashTool/BashTool.tsx:95–172  ·  view source on GitHub ↗
(command: string)

Source from the content-addressed store, hash-verified

93 * nature of the pipeline (e.g. `ls dir && echo "---" && ls dir2` is still a read).
94 */
95export function isSearchOrReadBashCommand(command: string): {
96 isSearch: boolean;
97 isRead: boolean;
98 isList: boolean;
99} {
100 let partsWithOperators: string[];
101 try {
102 partsWithOperators = splitCommandWithOperators(command);
103 } catch {
104 // If we can't parse the command due to malformed syntax,
105 // it's not a search/read command
106 return {
107 isSearch: false,
108 isRead: false,
109 isList: false
110 };
111 }
112 if (partsWithOperators.length === 0) {
113 return {
114 isSearch: false,
115 isRead: false,
116 isList: false
117 };
118 }
119 let hasSearch = false;
120 let hasRead = false;
121 let hasList = false;
122 let hasNonNeutralCommand = false;
123 let skipNextAsRedirectTarget = false;
124 for (const part of partsWithOperators) {
125 if (skipNextAsRedirectTarget) {
126 skipNextAsRedirectTarget = false;
127 continue;
128 }
129 if (part === '>' || part === '>>' || part === '>&') {
130 skipNextAsRedirectTarget = true;
131 continue;
132 }
133 if (part === '||' || part === '&&' || part === '|' || part === ';') {
134 continue;
135 }
136 const baseCommand = part.trim().split(/\s+/)[0];
137 if (!baseCommand) {
138 continue;
139 }
140 if (BASH_SEMANTIC_NEUTRAL_COMMANDS.has(baseCommand)) {
141 continue;
142 }
143 hasNonNeutralCommand = true;
144 const isPartSearch = BASH_SEARCH_COMMANDS.has(baseCommand);
145 const isPartRead = BASH_READ_COMMANDS.has(baseCommand);
146 const isPartList = BASH_LIST_COMMANDS.has(baseCommand);
147 if (!isPartSearch && !isPartRead && !isPartList) {
148 return {
149 isSearch: false,
150 isRead: false,
151 isList: false
152 };

Callers 1

isSearchOrReadCommandFunction · 0.85

Calls 2

hasMethod · 0.45

Tested by

no test coverage detected