Description
Cross-platform file operations like cp, mv, mkdir are inconsistent between Unix and Windows systems. This forces us to either:
- Write platform-specific shell commands
- Use external tools like
shx or cross-env
- Implement annoying conditional logic in taskfiles
This creates maintenance overhead and reduces portability of Taskfiles.
Proposal
Add native file system operations implemented in Go, using the fs: prefix to distinguish them from shell commands:
Core Operations
fs:copy - Copy files or directories with recursive support
fs:move - Move/rename files or directories
fs:mkdir - Create directories (with parent creation support)
fs:remove - Remove files or directories
fs:exists - Check if file/directory exists (useful for conditionals)
fs:chmod - Change file permissions (Unix-style, no-op on Windows)
Benefits
- True cross-platform compatibility - No need for platform-specific commands
- Consistent behavior - Same semantics across Windows, macOS, and Linux
- No external dependencies - Everything built into Task itself
- Familiar syntax - Mirrors common shell operations developers already know
Backwards Compatibility
If a task with the same name (e.g., fs:copy) exists in the taskfile, it overrides the built-in command, preserving existing functionality.
Usage Examples
Task-based Syntax
build:
cmds:
- go build -o ./bin/app
- task: fs:copy
vars:
SRC: ./bin/app
DEST: ./dist/app
RECURSIVE: true
- task: fs:mkdir
vars:
DIR: ./dist/config
PARENTS: true
Inline Syntax (Alternative)
build:
cmds:
- go build -o ./bin/app
- fs:copy ./bin/app ./dist/app
- fs:mkdir -p ./dist/config
- fs:remove ./temp/*
Error Handling
safe-copy:
cmds:
- task: fs:copy
vars:
SRC: ./source
DEST: ./backup
FAIL_FAST: true
PRESERVE_PERMISSIONS: true
Description
Cross-platform file operations like
cp,mv,mkdirare inconsistent between Unix and Windows systems. This forces us to either:shxorcross-envThis creates maintenance overhead and reduces portability of Taskfiles.
Proposal
Add native file system operations implemented in Go, using the
fs:prefix to distinguish them from shell commands:Core Operations
fs:copy- Copy files or directories with recursive supportfs:move- Move/rename files or directoriesfs:mkdir- Create directories (with parent creation support)fs:remove- Remove files or directoriesfs:exists- Check if file/directory exists (useful for conditionals)fs:chmod- Change file permissions (Unix-style, no-op on Windows)Benefits
Backwards Compatibility
If a task with the same name (e.g.,
fs:copy) exists in the taskfile, it overrides the built-in command, preserving existing functionality.Usage Examples
Task-based Syntax
Inline Syntax (Alternative)
Error Handling