From 48e18b869cc0ca939a52cea3f917d2678e4d7955 Mon Sep 17 00:00:00 2001 From: "hugues.verlin" Date: Thu, 12 Dec 2024 08:41:00 -0700 Subject: [PATCH 1/2] docs: add explanation about shebang --- docs/tasks/toml-tasks.md | 42 +++++++++++++++++++++++++++++++++++----- docs/tips-and-tricks.md | 4 +++- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/docs/tasks/toml-tasks.md b/docs/tasks/toml-tasks.md index 2c436953b..658e42e40 100644 --- a/docs/tasks/toml-tasks.md +++ b/docs/tasks/toml-tasks.md @@ -137,7 +137,13 @@ You can hide a task from the list of available tasks by setting `hide = true`: ```toml [tasks.cleancache] run = "rm -rf .cache" -hide = true # hide this task from the list +hide = true # hide this task from mise tasks / mise run +``` + +Note that if you want to see hidden tasks, you can use the `--hidden` flag: + +```shell +mise tasks ls --hidden ``` ## alias @@ -180,12 +186,21 @@ outputs = ['target/debug/mycli'] You can use `sources` alone if with [`mise watch`](/cli/watch.html) to run the task when the sources change. -## Shell / Shebang +## shell / shebang Tasks are executed with `set -e` (`set -o erropt`) if the shell is `sh`, `bash`, or `zsh`. This means that the script will exit if any command fails. You can disable this by running `set +e` in the script. -You can specify a shell command to run the script with (default is [`sh -c`](/configuration/settings.html#unix_default_inline_shell_args) or [`cmd /c`](/configuration/settings.html#windows_default_inline_shell_args)) or use a shebang: +```toml +[tasks.echo] +run = ''' +set +e +cd /nonexistent +echo "This will not fail the task" +''' +``` + +You can specify a `shell` command to run the script with (default is [`sh -c`](/configuration/settings.html#unix_default_inline_shell_args) or [`cmd /c`](/configuration/settings.html#windows_default_inline_shell_args)): ```toml [tasks.lint] @@ -193,7 +208,7 @@ shell = 'bash -c' run = "cargo clippy" ``` -or use a shebang: +or use a `shebang`: ```toml [tasks.lint] @@ -236,9 +251,10 @@ run = [ bun = 'latest' [tasks.bun_shell] -shell = "bun -e" description = "https://bun.sh/docs/runtime/shell" run = """ +#!/usr/bin/env bun + import { $ } from "bun"; const response = await fetch("https://example.com"); await $`cat < ${response} | wc -c`; // 1256 @@ -282,12 +298,28 @@ ruby = 'latest' [tasks.ruby_task] run = """ +#!/usr/bin/env ruby puts 'Hello, ruby!' """ ``` ::: +::: details What's a shebang? What's the difference between `#!/usr/bin/env` and `#!/usr/bin/env -S` + +A shebang is the character sequence `#!` at the beginning of a script file that tells the system which program should be used to interpret/execute the script. +The [env command](https://manpages.ubuntu.com/manpages/jammy/man1/env.1.html) comes from GNU Coreutils. + +For example, `#!/usr/bin/env python` will run the script with the Python interpreter found in the `PATH`. + +The `-S` flag allows passing multiple arguments to the interpreter. +It treats the rest of the line as a single argument string to be split. + +This is useful when you need to specify interpreter flags or options. +Example: `#!/usr/bin/env -S python -u` will run Python with unbuffered output + +::: + ## file You can specify a file to run as a task: diff --git a/docs/tips-and-tricks.md b/docs/tips-and-tricks.md index e70052cf6..8bfab1be9 100644 --- a/docs/tips-and-tricks.md +++ b/docs/tips-and-tricks.md @@ -44,7 +44,9 @@ console.log(`Running node: ${process.version}`); This can also be useful in environments where mise isn't activated (such as a non-interactive session). -You can also download the script to use in a project bootstrap script: +## Bootstrap script + +You can download the script to use in a project bootstrap script: ```sh curl https://mise.run > setup-mise.sh From bc93e8d5d707ad756dc3c07b5eaa951a0cf8c48b Mon Sep 17 00:00:00 2001 From: "hugues.verlin" Date: Fri, 13 Dec 2024 07:06:11 -0700 Subject: [PATCH 2/2] update --- docs/tasks/toml-tasks.md | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/docs/tasks/toml-tasks.md b/docs/tasks/toml-tasks.md index 658e42e40..4a91a15b1 100644 --- a/docs/tasks/toml-tasks.md +++ b/docs/tasks/toml-tasks.md @@ -137,13 +137,7 @@ You can hide a task from the list of available tasks by setting `hide = true`: ```toml [tasks.cleancache] run = "rm -rf .cache" -hide = true # hide this task from mise tasks / mise run -``` - -Note that if you want to see hidden tasks, you can use the `--hidden` flag: - -```shell -mise tasks ls --hidden +hide = true # hide this task from mise tasks ls / mise run ``` ## alias @@ -208,7 +202,7 @@ shell = 'bash -c' run = "cargo clippy" ``` -or use a `shebang`: +or use a shebang: ```toml [tasks.lint] @@ -308,7 +302,7 @@ puts 'Hello, ruby!' ::: details What's a shebang? What's the difference between `#!/usr/bin/env` and `#!/usr/bin/env -S` A shebang is the character sequence `#!` at the beginning of a script file that tells the system which program should be used to interpret/execute the script. -The [env command](https://manpages.ubuntu.com/manpages/jammy/man1/env.1.html) comes from GNU Coreutils. +The [env command](https://manpages.ubuntu.com/manpages/jammy/man1/env.1.html) comes from GNU Coreutils. `mise` does not use `env` but will behave similarly. For example, `#!/usr/bin/env python` will run the script with the Python interpreter found in the `PATH`. @@ -316,7 +310,7 @@ The `-S` flag allows passing multiple arguments to the interpreter. It treats the rest of the line as a single argument string to be split. This is useful when you need to specify interpreter flags or options. -Example: `#!/usr/bin/env -S python -u` will run Python with unbuffered output +Example: `#!/usr/bin/env -S python -u` will run Python with unbuffered output. :::