danielixir
I was really annoyed by the Terminate batch job (Y/N)? prompt after hitting CTRL-C, that is caused due to elixir.bat and mix.bat being legacy batch scripts. Batch scripts do that, but it’s unintuitive.
I ported both to PowerShell scripts and the problem went away. I’m sharing this for anyone who is annoyed in the same way.
Just in case this may be interesting to package into elixir by default, I’d be happy to clean this up a little and work with someone who uses both commands more often to make it stable. It works for me, but I only use mix phx.new and mix phx.server, so I’m unable to test other arguments at the moment.
elixir.ps1
$elixirVersion = "1.14.0"
if (!$args -or $args[0] -cin ("--help", "-h", "/h", "/?") ) {
@'
Usage: elixir.ps1 [options] [.exs file] [data]
## General options
-e "COMMAND" Evaluates the given command (*)
-h, --help Prints this message (standalone)
-r "FILE" Requires the given files/patterns (*)
-S SCRIPT Finds and executes the given script in $env:PATH
-pr "FILE" Requires the given files/patterns in parallel (*)
-pa "PATH" Prepends the given path to Erlang code path (*)
-pz "PATH" Appends the given path to Erlang code path (*)
-v, --version Prints Erlang/OTP and Elixir versions (standalone)
--app APP Starts the given app and its dependencies (*)
--erl "SWITCHES" Switches to be passed down to Erlang (*)
--eval "COMMAND" Evaluates the given command, same as -e (*)
--logger-otp-reports BOOL Enables or disables OTP reporting
--logger-sasl-reports BOOL Enables or disables SASL reporting
--no-halt Does not halt the Erlang VM after execution
--short-version Prints Elixir version (standalone)
--werl Uses Erlang's Windows shell GUI (Windows only)
Options given after the .exs file or -- are passed down to the executed code.
Options can be passed to the Erlang runtime using $env:ELIXIR_ERL_OPTIONS or --erl.
## Distribution options
The following options are related to node distribution.
--cookie COOKIE Sets a cookie for this distributed node
--hidden Makes a hidden node
--name NAME Makes and assigns a name to the distributed node
--rpc-eval NODE "COMMAND" Evaluates the given command on the given remote node (*)
--sname NAME Makes and assigns a short name to the distributed node
## Release options
The following options are generally used under releases.
--boot "FILE" Uses the given FILE.boot to start the system
--boot-var VAR "VALUE" Makes $VAR available as VALUE to FILE.boot (*)
--erl-config "FILE" Loads configuration in FILE.config written in Erlang (*)
--vm-args "FILE" Passes the contents in file as arguments to the VM
--pipe-to is not supported on Windows. If set, Elixir won't boot.
** Options marked with (*) can be given more than once.
** Standalone options can't be combined with other options.
'@
exit
}
if ($args[0] -eq "--short-version") {
$ElixirVersion
exit
}
# Arguments for Elixir
$elixirArgs = @()
# Arguments for Erlang
$erlangArgs = @()
# Optional arguments before the "-extra" parameter
$beforeExtra = @()
# Designates which mode / Elixir component to run as
$runMode = "elixir"
:argparseloop for ($i = 0; $i -lt $args.Count; $i++) {
switch ($args[$i]) {
# Execution Options
"--werl" {
$useWerl = $true
break
}
"+iex" {
$elixirArgs += "+iex"
$runMode = "iex"
break
}
"+elixirc" {
$elixirArgs += "+elixirc"
$runMode = "elixirc"
break
}
# Elixir Arguments
{ $_ -in "-e", "--eval", "-r", "-pr", "-pa", "-pz", "-app", "-remsh", "-dot-iex" } {
$elixirArgs += "{0} {1}" -f $args[$i], $args[++$i]
break
}
"--rpc-eval" {
$elixirArgs += "--rpc-eval {0} {1}" -f $args[++$i], $args[++$i]
break
}
# Erlang Arguments
"--boot" {
$erlangArgs += "-boot {0}" -f $args[++$i]
break
}
"--name" {
$erlangArgs += "-name {0}" -f $args[++$i]
break
}
"--sname" {
$erlangArgs += "-sname {0}" -f $args[++$i]
break
}
"--erl-config" {
$erlangArgs += "-config {0}" -f $args[++$i]
break
}
"--cookie" {
$erlangArgs += "-setcookie {0}" -f $args[++$i]
break
}
"--vm-args" {
$erlangArgs += "-args_file {0}" -f $args[++$i]
break
}
"--boot-var" {
$erlangArgs += ("-boot_var {0} {1}" -f $args[++$i], $args[++$i])
break
}
"--hidden" {
$erlangArgs += "-hidden"
break
}
"--detached" {
$erlangArgs += "-detached"
Write-Warning "The --detached option is deprecated!"
break
}
"--logger-otp-reports" {
$erlangArgs += "-logger handle_otp_reports {0}" -f $args[++$i]
break
}
"--logger-sasl-reports" {
$erlangArgs += "-logger handle_sasl_reports {0}" -f $args[++$i]
break
}
"--erl" {
$beforeExtra += "{0}" -f $args[++$i]
break
}
"--pipe-to" {
Write-Warning "Option --pipe-to is not supported on Windows!"
break
}
# [.exs file] and [data]
Default {
$elixirArgs += $args[$i..$args.GetUpperBound(0)]
break argparseloop
}
}
}
$extraPaths = @("-pa") + (Get-Item "$PSScriptRoot\..\lib\*\ebin").FullName
if ($useWerl) {
$erlExecutable = "werl.exe"
} else {
$erlExecutable = "erl.exe"
}
if ($env:ERTS_BIN) {
$erlExecutable = Join-Path $env:ERTS_BIN $erlExecutable
}
# Enable colors if console host is Windows Terminal
if ($env:WT_PROFILE_ID -or $env:WT_SESSION) {
$beforeExtra = "-elixir ansi_enabled true".split() + $beforeExtra
}
if ($runMode -ne "iex") {
$beforeExtra = "-noshell -s elixir start_cli".split() + $beforeExtra
}
& $erlExecutable $extraPaths $env:ELIXIR_ERL_OPTIONS $erlangArgs $beforeExtra "-extra" $elixirArgs
mix.ps1
& $PSScriptRoot\elixir.ps1 $PSScriptRoot\mix @args
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
Hey there,
It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Quite interesting article Google brought me. Didn’t find any mentions about it here.
What do you think in general? Would you use togethe...
New
:warning: Security advisory: Decimal DoS vulnerability
A vulnerability has been published for decimal where very large exponents can cau...
New
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
Other Trending Topics
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming









