const SETTINGS_PATH = "~/.fig/tools/all-settings.json" ; interface Settings { settingName : string ; description : string ; type : "boolean" | "text" | "single_select" | "multiselect" ; options ? : Array < string | { name : string ; description : string ; } > ; default ? : string ; } const devCompletionsFolderGenerator = { script : 'ls -d -1 "$PWD/"**/' , postProcess : ( out ) => out . split ( "\n" ) . map ( ( folder ) => { const paths = folder . split ( "/" ) ; paths . pop ( ) ; return { name : paths . pop ( ) , insertValue : folder , icon : `fig://${ folder }` , } ; } ) , } ; const disableForCommandsGenerator = { script : "fig settings autocomplete.disableForCommands" , postProcess : ( out ) => { const existing = out . split ( "\n" ) . filter ( ( item ) => item . length > 0 ) ; const append = { name : "Disable new CLI..." , description : `You must pass a valid JSON array of CLI tools contained within single quotes. e.g. '["npm","cd","ls"]'` , icon : "fig://icon?type=box" , insertValue : JSON . stringify ( existing . concat ( [ "{cursor}" ] ) ) , } ; const enabledAll = { name : "Enable all commands" , icon : "fig://icon?type=box" , insertValue : "'[]'" , } ; return [ append , enabledAll ] . concat ( existing . map ( ( disabledCommand ) => { return { name : `Enable ${ disabledCommand }` , icon : "fig://icon?type=box" , insertValue : JSON . stringify ( existing . filter ( ( cmd ) => cmd != disabledCommand ) ) , } ; } ) ) ; } , } ; export const themesGenerator = { script : "ls -1 ~/.fig/themes" , postProcess : ( output ) => { const builtinThemes = [ { name : "light" , icon : "fig://template?color=ffffff&badge=☀️" , priority : 51 , } , { name : "dark" , icon : "fig://template?color=000000&badge=🌙" , priority : 51 , } , ] ; return output . split ( "\n" ) . map ( ( theme ) => ( { name : theme . replace ( ".json" , "" ) } ) ) . concat ( builtinThemes ) ; } , } ; export const SETTINGS_GENERATOR = { "autocomplete.devCompletionsFolder" : devCompletionsFolderGenerator , "autocomplete.disableForCommands" : disableForCommandsGenerator , "autocomplete.theme" : themesGenerator , } ; export const subsystemsGenerator = { script : "ls ~/.fig/logs" , trigger : ( curr , prev ) => { return curr . length == 0 && prev . length > 0 ; } , postProcess : ( out , tokens ) => { const pivot = tokens . indexOf ( "logs" ) ; const insertedLogFiles = tokens . slice ( pivot ) ; return out . split ( "\n" ) . map ( ( log ) => { return { name : log . replace ( ".log" , "" ) } ; } ) . filter ( ( suggestion ) => ! insertedLogFiles . includes ( suggestion . name ) ) ; } , } ; export const settingsSpecGenerator = async ( _ , executeShellCommand ) => { const settings = JSON . parse ( await executeShellCommand ( `\cat ${ SETTINGS_PATH }` ) ) ; return { name : "settings" , subcommands : settings . map ( ( { settingName : name , description , type , options , default : defaultValue , } ) => { const suggestions = type === "boolean" ? [ "true" , "false" ] : options ?. map ( ( option ) => ( { name : option [ "name" ] || option , description : option [ "description" ] || "" , } ) ) ; const generators = SETTINGS_GENERATOR [ name ] ; return { name , description , icon : "fig://icon?type=commandkey" , args : { name : type , default : defaultValue , suggestions : generators ? [ ] : suggestions , generators , } , } ; } ) , } ; } ; export default { } ;