MCPcopy Index your code
hub / github.com/Noumena-Network/code / getSnapshotScript

Function getSnapshotScript

src/utils/bash/ShellSnapshot.ts:346–387  ·  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

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