Skip to content

Instantly share code, notes, and snippets.

@RiceBen
Last active December 25, 2023 13:57
Show Gist options
  • Save RiceBen/7cb029cbb568552db20c9290bf9faaa6 to your computer and use it in GitHub Desktop.
Save RiceBen/7cb029cbb568552db20c9290bf9faaa6 to your computer and use it in GitHub Desktop.
Demo Taskfile
version: '3'
silent: true
tasks:
default:
desc: 'Default command will list all tasks'
cmds:
- task --list-all
rm-clean-all:
summary: |
Will invoke tasks below to cleanup storage:
- rm-teams-cache: Which will cleanup Teams cache in local machine
- rm-clean-localTemp: Which will cleanup the Temp folder in AppData
- rm-disk-space: Will invoke cleanmgr tool with verylowdisk parameter
desc: 'Remove all temperary data'
cmds:
- task: rm-teams-cache
- task: rm-clean-localTemp
- task: rm-disk-space
rm-clean-localTemp:
desc: 'Remove AppData Local Temp files'
platforms: [windows]
dir: '~\AppData\Local\Temp'
cmds:
- |
pwsh -Command "ls -Path '*.*' -Recurse |
Where{\$_.LastWriteTime -lt (Get-Date).AddDays(-5)} |
Remove-Item -r"
- cmd: echo "Task rm-clean-localTemp finished"
rm-teams-cache:
desc: 'Remove MS Teams cache files'
platforms: [windows]
dir: '~\AppData\Roaming\Microsoft\Teams'
cmds:
- |
pwsh -Command "Get-ChildItem -Path . -Recurse | rm -r"
- cmd: echo "Task rm-teams-cache finished"
rm-disk-space:
desc: 'Remove disk space in c drive'
platforms: [windows]
cmds:
- cleanmgr /verylowdisk
- cmd: echo "Task rm-disk-space finished"
get-files-recursive:
summary: |
Usage: task get-files-recursive PATH=<Directory name>
desc: 'Recursively get files in the floder'
internal: true
vars:
PATH: '{{default "." .PATH}}'
cmds:
- cmd: pwsh -Command "Get-ChildItem -Path {{.PATH}} -Recurse"
- echo "This value pass via other task, {{.Result}}"
demo-internal-task:
desc: 'A sample to show how internal task use.'
cmds:
- task: get-files-recursive
vars:
Result:
sh: pwd
demo-no-desc-task:
cmds:
- cmd: echo 'This is demo task w/o desc'
demo-dynamic-vary-task:
desc: 'A sample for dynamic variable, using curl and jq to generate content.'
cmds:
- echo '{{.CURRENT_TIME}}'
vars:
CURRENT_TIME:
sh: "curl 'https://api.github.com/repos/jqlang/jq/commits?per_page=5' | jq '.[0]'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment