Supports overview

# overview.txt

# command
echo command

# nested command
echo nested $(echo command)

# arguments
echo argc=$# args="$@"

# built-in commands
@set ENV=builtin_set_environment
echo %ENV%

CD
@pushd ..
CD
@popd
CD

# mruby as glue code
```ruby
# this is mruby comment
puts "mruby code"
def add(a, b)
  a + b
end

msg = `echo hi`
puts "shell command on mruby : #{msg}"
```

# nested mruby
echo 2 + 3 = <%= add(2, 3) %>
echo shell command on nested mruby : <%= `echo hi!` %>
> overview hoge foo "hello world"
command
nested command
argc=3 args=hoge foo "hello world"
builtin_set_environment
C:\path\to
C:\path
C:\path\to
mruby code
shell command on mruby : hi
2 + 3 = 5
shell command on nested mruby : hi!

Command

Execute command via command prompt, but with a few differences.


For this argument: "hello world" foo "bar"
  1. Split the argument tokens
  2. to [hello world] [foo] [bar]
  3. Enclose arguments containing spaces with "
  4. to ["hello world"] [foo] [bar]
  5. Join to space separator
  6. to "hello world" foo bar
For example: command-sample alias
# command-sample.txt
echo "$@"
> command-sample "hello world" foo "bar"
"hello world" foo bar

Nested command

Execute nested command ($( ... )) via bash-like, but unlike bash, this is sequential execution.


For example: nested-command-sample alias
# nested-command-sample.txt
echo $( ^
  echo $( ^
    echo $( ^
      echo 1 >> o.txt ^
    ) $( ^
      echo $( ^
        echo 2 >> o.txt ^
      ) 3 >> o.txt ^
    ) 4 >> o.txt ^
  ) 5 >> o.txt ^
) 6 >> o.txt
> nested-command-sample
> cat o.txt
1
2
3
4
5
6

Arguments

via bash-like, but with a few differences.


Support list:
  • $0
  • $1,$2,$3,...,$9
  • $#,"$@","$+"
$*, $@, "$*" is not supported.

"$+" is unique arguments, expands arguments on a single line, like "$*", but keeps asterisks it.


For example: arguments-sample alias
# arguments-sample.txt
echo alias_name=$0
echo argc=$# args="$@"
echo $1 world
echo hello $2
echo "$+"
> arguments-sample hello world "fo* bar"
alias_name=arguments-sample
argc=3 args=hello world "foo bar"
hello world
hello world
"hello world fo* bar"

Built-in command

Commands are executed internally by cmd / c one by one, so some commands have no meaning.

For example: CD, SET.
Use the built-in command instead.

Support list:
  • @set <key>=<value>
  • @pushd <path>
  • @popd
For example: builtin-command-sample alias
# builtin-command-sample.txt
@set ENV=builtin_set_environment
echo %ENV%

# direct execute
D:/tools/saytool/bin/say
# set path environment, and execute
@set PATH=D:/tools/saytool/bin;%PATH%
say

CD
@pushd ..
CD
@pushd D:/dev
CD
@popd
CD
@popd
CD
> builtin-command-sample
builtin_set_environment
hello!
hello!
C:\path\to
C:\path
D:\dev
C:\path
C:\path\to

mruby

version 2.1.0

mruby is run as gluecode.

Write the mruby code between the code blocks ```ruby and ```, this code block can be written multiple times.

There are also some missing features, there is implemented and called by Rust.


Implemented list by Rust:
A minimal implementation
  • ARGV
  • Array
    • to_cmd See below "Nested mruby"
    • to_cmd_deep See below "Nested mruby"
    • self.from_cmd(cmd_args_string)
    • from_cmd!(cmd_args_string)
    • from_cmd(cmd_args_string)
to_cmd and from_cmd implemented in Array are unique functions to exchange arrays with command prompt.
to_cmd converts an array into a command prompt argument list.
from_cmd converts the command prompt argument list into an array.

mruby native:
  • STDIN
  • STDOUT
  • STDERR
  • call shell command: `echo from shell command`

For example: mruby-sample alias
# mruby-sample.txt
echo 1 cmd
```ruby
puts '2 mruby'
print 'ARGV='
puts ARGV
puts 'gets=' + STDIN.gets
```
echo 3 cmd
```ruby
puts '4 mruby'
a = [].from_cmd %q( "hello world" foo bar 1 3.14 )
puts a
STDERR.puts a
puts `echo from shell command`
```
echo 5 cmd
> echo from_stdin | mruby-sample hoge piyo
1 cmd
2 mruby
ARGV=["hoge", "piyo"]
gets=from_stdin
3 cmd
4 mruby
["hello world", "foo", "bar", 1, 3.14]
["hello world", "foo", "bar", 1, 3.14]
from shell command
5 cmd

Nested mruby

Execute nested mruby (<%= ... %>) via Rails template(ERB)-like, However, this can be multi-stage nested.


to_cmd converts an array into a command prompt argument list.
to_cmd_deep converts an nested array into a command prompt argument list.

For example: nested-mruby-sample alias
# nested-mruby-sample.txt
```ruby
def say_str
  "hello!"
end

a = [5, 'hello world', 7, 'foo', 'bar', 11]
b = [5, 'hello world', 7, [['foo', 'bar'], 11]]
```
echo <%= say_str %>
echo <%= `echo world!` %>
echo 2 + 3 = <%= 2 + <%= 3 %>%>
echo 3 + 5 = <%= "3" + <%= 5 %>.to_s %>
echo <%= a.to_cmd %>
echo <%= b.to_cmd_deep %>
> nested-mruby-sample
hello!
world!
2 + 3 = 5
3 + 5 = 35
5 "hello world" 7 foo bar 11
5 "hello world" 7 foo bar 11

Nested combine

Let's try, combine nested command and nested mruby.


For example: nested-combine-sample alias
# nested-combine-sample.txt
```ruby
underscore = "_"
hello_world = "success!"
```

# $1: hello, $2: world
# need sed command installed, for example, msys2
echo <%= $(echo $(echo $1)<%= underscore %>XXX | sed 's/XXX/$(echo $2)/g') %>
> nested-combine-sample hello world
success!