@@ -50,17 +50,21 @@ async function writeToShellConfig(
5050 ? await readFile ( configPath , "utf-8" )
5151 : "" ;
5252
53- for ( const [ key , value ] of Object . entries ( vars ) ) {
54- const pattern = getExportPattern ( shell , key ) ;
55- const exportLine = formatExportLine ( shell , key , value ) ;
56-
57- if ( pattern . test ( content ) ) {
58- content = content . replace ( pattern , exportLine ) ;
59- } else {
60- if ( content . length > 0 && ! content . endsWith ( "\n" ) ) content += "\n" ;
61- content += `${ exportLine } \n` ;
62- }
53+ // Remove any existing AnythingLLM variable lines and comment header
54+ for ( const key of Object . keys ( vars ) ) {
55+ content = content . replace ( getExportPattern ( shell , key ) , "" ) ;
6356 }
57+ content = content . replace ( / ^ # A n y t h i n g L L M C L I $ / m, "" ) ;
58+
59+ // Clean up excessive blank lines left by removals, then trim end
60+ content = content . replace ( / \n { 3 , } / g, "\n\n" ) . trimEnd ( ) ;
61+
62+ // Build grouped block with comment header
63+ const exportLines = Object . entries ( vars )
64+ . map ( ( [ key , value ] ) => formatExportLine ( shell , key , value ) )
65+ . join ( "\n" ) ;
66+
67+ content += `\n\n# AnythingLLM CLI\n${ exportLines } \n` ;
6468
6569 await writeFile ( configPath , content , "utf-8" ) ;
6670}
0 commit comments