MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / getSnapshotScript

Function getSnapshotScript

source code/utils/bash/ShellSnapshot.ts:347–388  ·  view source on GitHub ↗

* Creates the appropriate shell script for capturing environment

(
  shellPath: string,
  snapshotFilePath: string,
  configFileExists: boolean,
)

Source from the content-addressed store, hash-verified

345 * Creates the appropriate shell script for capturing environment
346 */
347async function getSnapshotScript(
348 shellPath: string,
349 snapshotFilePath: string,
350 configFileExists: boolean,
351): Promise<string> {
352 const configFile = getConfigFile(shellPath)
353 const isZsh = configFile.endsWith('.zshrc')
354
355 // Generate the user content and Claude Code content
356 const userContent = configFileExists
357 ? getUserSnapshotContent(configFile)
358 : !isZsh
359 ? // we need to manually force alias expansion in bash - normally `getUserSnapshotContent` takes care of this
360 'echo "shopt -s expand_aliases" >> "$SNAPSHOT_FILE"'
361 : ''
362 const claudeCodeContent = await getClaudeCodeSnapshotContent()
363
364 const script = `SNAPSHOT_FILE=${quote([snapshotFilePath])}
365 ${configFileExists ? `source "${configFile}" < /dev/null` : '# No user config file to source'}
366
367 # First, create/clear the snapshot file
368 echo "# Snapshot file" >| "$SNAPSHOT_FILE"
369
370 # When this file is sourced, we first unalias to avoid conflicts
371 # This is necessary because aliases get "frozen" inside function definitions at definition time,
372 # which can cause unexpected behavior when functions use commands that conflict with aliases
373 echo "# Unset all aliases to avoid conflicts with functions" >> "$SNAPSHOT_FILE"
374 echo "unalias -a 2>/dev/null || true" >> "$SNAPSHOT_FILE"
375
376 ${userContent}
377
378 ${claudeCodeContent}
379
380 # Exit silently on success, only report errors
381 if [ ! -f "$SNAPSHOT_FILE" ]; then
382 echo "Error: Snapshot file was not created at $SNAPSHOT_FILE" >&2
383 exit 1
384 fi
385 `
386
387 return script
388}
389
390/**
391 * Creates and saves the shell environment snapshot by loading the user's shell configuration

Callers 1

createAndSaveSnapshotFunction · 0.85

Calls 4

getConfigFileFunction · 0.85
getUserSnapshotContentFunction · 0.85
quoteFunction · 0.85

Tested by

no test coverage detected