diff --git a/public/blocks/lnBlock.js b/public/blocks/lnBlock.js index b8b6a2a..c54dc6c 100644 --- a/public/blocks/lnBlock.js +++ b/public/blocks/lnBlock.js @@ -54,7 +54,24 @@ var lnBlock = { ], style: 'Filesystem Operations', tooltip: '%{BKY_LN_TOOLTIP}', - helpUrl: 'https://linux.die.net/man/1/ln' + helpUrl: 'https://linux.die.net/man/1/ln', + generateCommand: function (block) { + let lnCommand = 'ln '; + const symbolic = block.getFieldValue('symbolic') === 'TRUE'; + const force = block.getFieldValue('force') === 'TRUE'; + const interactive = block.getFieldValue('interactive') === 'TRUE'; + if (symbolic) lnCommand += ' -s '; + if (force) lnCommand += ' -f '; + if (interactive) lnCommand += ' -i '; + const sourceArgsBlock = block.getInputTargetBlock('SOURCE'); + const targetArgsBlock = block.getInputTargetBlock('TARGET'); + lnCommand += + handleArgumentsBlocks(sourceArgsBlock) + + ' ' + + handleArgumentsBlocks(targetArgsBlock); + generatedCommand = lnCommand; + return generatedCommand; + } }; Blockly.defineBlocksWithJsonArray([lnBlock]); diff --git a/public/blocks/mvBlock.js b/public/blocks/mvBlock.js index 49026d5..ec5d281 100644 --- a/public/blocks/mvBlock.js +++ b/public/blocks/mvBlock.js @@ -48,7 +48,28 @@ var mvBlock = { ], style: 'Filesystem Operations', tooltip: 'Μετακινεί ή μετονομάζει αρχεία.', - helpUrl: 'https://linux.die.net/man/1/mv' + helpUrl: 'https://linux.die.net/man/1/mv', + generateCommand: function (block) { + let mvCommand = 'mv '; // Start the mv command + // Handle options + const notPromptConfirmation = + block.getFieldValue('not_prompt_confirmation') === 'TRUE'; + const promptConfirmation = + block.getFieldValue('prompt_confirmation') === 'TRUE'; + const notOverwrite = block.getFieldValue('not_overwrite') === 'TRUE'; + if (notPromptConfirmation) mvCommand += '-f '; // Add -f for no prompt + if (promptConfirmation) mvCommand += '-i '; // Add -i for prompt + if (notOverwrite) mvCommand += '-n '; // Add -n for no overwrite + // Get source and destination blocks + const sourceArgsBlock = block.getInputTargetBlock('SOURCE'); + const targetArgsBlock = block.getInputTargetBlock('DEST'); + // Append arguments (source and destination paths) + mvCommand += + handleArgumentsBlocks(sourceArgsBlock) + + ' ' + + handleArgumentsBlocks(targetArgsBlock); + return mvCommand; // Return the generated mv command + } }; Blockly.defineBlocksWithJsonArray([mvBlock]); diff --git a/public/blocks/rmBlock.js b/public/blocks/rmBlock.js index b5192b4..710045f 100644 --- a/public/blocks/rmBlock.js +++ b/public/blocks/rmBlock.js @@ -53,7 +53,23 @@ var rmBlock = { extensions: [], style: 'Filesystem Operations', tooltip: '%{BKY_RM_TOOLTIP}', - helpUrl: 'https://linux.die.net/man/1/rm' + helpUrl: 'https://linux.die.net/man/1/rm', + generateCommand: function (block) { + let rmCommand = 'rm '; + const force = block.getFieldValue('force') === 'TRUE'; + const requestConfirmation = + block.getFieldValue('request_confirmation') === 'TRUE'; + const removeDirectory = block.getFieldValue('remove_directory') === 'TRUE'; + const recursive = block.getFieldValue('recursive') === 'TRUE'; + if (force) rmCommand += '-f '; + if (requestConfirmation) rmCommand += '-i '; + if (removeDirectory) rmCommand += '-d '; + if (recursive) rmCommand += '-R '; + const argumentBlock = block.getInputTargetBlock('ARGUMENT'); + rmCommand += ' ' + handleArgumentsBlocks(argumentBlock); + generatedCommand = rmCommand; + return generatedCommand; + } }; Blockly.defineBlocksWithJsonArray([rmBlock]); diff --git a/public/blocks/touchBlock.js b/public/blocks/touchBlock.js index d09233f..5024806 100644 --- a/public/blocks/touchBlock.js +++ b/public/blocks/touchBlock.js @@ -58,7 +58,27 @@ var touchBlock = { extensions: ['validate_touch_time_d', 'restrict_touch_to_argumentsCreate'], style: 'Filesystem Operations', tooltip: '%{BKY_TOUCH_TOOLTIP}', - helpUrl: '%{BKY_TOUCH_HELPURL}' // URL to further information or documentation. + helpUrl: '%{BKY_TOUCH_HELPURL}', // URL to further information or documentation. + generateCommand: function (block) { + let touchCommand = 'touch'; // Start with the basic touch command + // Check each option and append to the command if selected + const notCreateFile = block.getFieldValue('not_create_file') === 'TRUE'; + const changeAccessTime = block.getFieldValue('access_time') === 'TRUE'; + const changeModificationTime = + block.getFieldValue('modification_time') === 'TRUE'; + const rawTimestamp = block.getFieldValue('change_time_d'); + const argumentBlock = block.getInputTargetBlock('argument'); + if (notCreateFile) touchCommand += ' -c'; + if (changeAccessTime) touchCommand += ' -a'; + if (changeModificationTime) touchCommand += ' -m'; + if (rawTimestamp) { + const formattedTimestamp = rawTimestamp.replace(' ', 'T'); + touchCommand += ` -d ${formattedTimestamp}`; + } + generatedCommand = + touchCommand + ' ' + handleArgumentsBlocks(argumentBlock); + return generatedCommand; + } }; Blockly.defineBlocksWithJsonArray([touchBlock]);