MCPcopy Create free account
hub / github.com/Noumena-Network/code / getUserSnapshotContent

Function getUserSnapshotContent

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

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