MCPcopy
hub / github.com/codeaashu/claude-code / getUserSnapshotContent

Function getUserSnapshotContent

src/utils/bash/ShellSnapshot.ts:197–263  ·  view source on GitHub ↗

* Generates user-specific snapshot content (functions, options, aliases) * This content is derived from the user's shell configuration file

(configFile: string)

Source from the content-addressed store, hash-verified

195 * This content is derived from the user's shell configuration file
196 */
197function getUserSnapshotContent(configFile: string): string {
198 const isZsh = configFile.endsWith('.zshrc')
199
200 let content = ''
201
202 // User functions
203 if (isZsh) {
204 content += `
205 echo "# Functions" >> "$SNAPSHOT_FILE"
206
207 # Force autoload all functions first
208 typeset -f > /dev/null 2>&1
209
210 # Now get user function names - filter completion functions (single underscore prefix)
211 # but keep double-underscore helpers (e.g. __zsh_like_cd from mise, __pyenv_init)
212 typeset +f | grep -vE '^_[^_]' | while read func; do
213 typeset -f "$func" >> "$SNAPSHOT_FILE"
214 done
215 `
216 } else {
217 content += `
218 echo "# Functions" >> "$SNAPSHOT_FILE"
219
220 # Force autoload all functions first
221 declare -f > /dev/null 2>&1
222
223 # Now get user function names - filter completion functions (single underscore prefix)
224 # but keep double-underscore helpers (e.g. __zsh_like_cd from mise, __pyenv_init)
225 declare -F | cut -d' ' -f3 | grep -vE '^_[^_]' | while read func; do
226 # Encode the function to base64, preserving all special characters
227 encoded_func=$(declare -f "$func" | base64 )
228 # Write the function definition to the snapshot
229 echo "eval ${LITERAL_BACKSLASH}"${LITERAL_BACKSLASH}$(echo '$encoded_func' | base64 -d)${LITERAL_BACKSLASH}" > /dev/null 2>&1" >> "$SNAPSHOT_FILE"
230 done
231 `
232 }
233
234 // Shell options
235 if (isZsh) {
236 content += `
237 echo "# Shell Options" >> "$SNAPSHOT_FILE"
238 setopt | sed 's/^/setopt /' | head -n 1000 >> "$SNAPSHOT_FILE"
239 `
240 } else {
241 content += `
242 echo "# Shell Options" >> "$SNAPSHOT_FILE"
243 shopt -p | head -n 1000 >> "$SNAPSHOT_FILE"
244 set -o | grep "on" | awk '{print "set -o " $1}' | head -n 1000 >> "$SNAPSHOT_FILE"
245 echo "shopt -s expand_aliases" >> "$SNAPSHOT_FILE"
246 `
247 }
248
249 // User aliases
250 content += `
251 echo "# Aliases" >> "$SNAPSHOT_FILE"
252 # Filter out winpty aliases on Windows to avoid "stdin is not a tty" errors
253 # Git Bash automatically creates aliases like "alias node='winpty node.exe'" for
254 # programs that need Win32 Console in mintty, but winpty fails when there's no TTY

Callers 1

getSnapshotScriptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected