write shellscript in a powful way!
IMPORTANT: a brand NEW powscript beta-version is available here, come see!
$ wget "https://raw.githubusercontent.com/coderofsalvation/powscript/master/powscript" -O /usr/local/bin/powscript && chmod 755 /usr/local/bin/powscript
$ powscript myscript.pow # run directly
$ powscript --compile myscript.pow > myscript # output bashscript
$ powscript --compile --sh myscript.pow > myscript.sh # output sh-script (experimental)
#!/usr/bin/env powscript
require 'json'
require_env 'URL'
require_cmd 'curl'
usage(app)
echo "$app <jsonkey>"
version()
data={}
json=$(curl -s "$URL")
json_parse data "$json"
echo data.version
run(cmd)
if empty? cmd
help=$(usage myapp)
echo "Usage: $help" && exit
$cmd
run $@
Output:
$ URL=https://raw.githubusercontent.com/coderofsalvation/powscript/master/package.json ./foo.bash version
1.0.26
Check here for more examples
- indentbased, memorizable, coffeescript-inspired syntax
- removes semantic noise like { ! [[ @ ]] || ~=
- safetynets: automatic quoting, halt on error or missing dependencies (
require_cmd
,require_env
) - comfort: json, easy arrays, easy async, functional programming, named variables instead of positionals
- Modules / bundling
- remote/local packages & dependencies
- written/generated for bash >= 4.x, 'zero'-dependency solution for embedded devices e.g.
- hasslefree: easy installation without gcc compilation/3rd party software
Put this line in your .inputrc
:
"\C-p" "powscript --interactive\n"
Then hitting ctrl-p in your console will enter powscript mode:
hit ctrl-c to exit powscript, type 'edit' to launch editor, and 'help' for help
> each(line)
> echo line=$line
> run()
> tail -2 ~/.kanban.csv | mappipe each
> run
line=1,foo,bar,flop
line=2,foo2,bar2,flop2
>
Powscript can produce 'kindof' POSIX /bin/sh
-compatible output by removing bashisms, by introducing the --sh
flag:
$ powscript --compile foo.pow > foo.bash
$ powscript --sh --compile foo.pow > foo.sh
This however, is experimental, as well as the standalone bash2sh converter:
$ cat foo.bash | powscript --tosh > foo.sh
NOTE: remove bashisms manually using docs/tools like bashism guide or checkbashisms The general rule for POSIX sh-output is:
don't write bashfeatures in powscript
See FAQ
HINT: use live expansion inside vim. Put the lines below in .vimrc and hit 'p>' in normal/visual mode to expand powscript
vmap p> :!PIPE=2 powscript --compile<CR>
nmap p> ggVG:!PIPE=2 powscript --compile<CR>
OSX might protest since it isn't quite GNU focused. Please run these commands after installing:
$ brew install bash
$ brew install coreutils gnu-sed grep gawk --default-names
$ echo 'export PATH=/usr/local/opt/coreutils/libexec/gnubin:$PATH' >> ~/.bashrc
$ sed -i 's|#!/bin/bash|#!/usr/local/bin/bash|g' powscript