8000 GitHub - coderofsalvation/powscript at feat/semicolon-functions
[go: up one dir, main page]

Skip to content

transpiler written in bash: painless shellscript, indentbased, coffee for the shell with hipster-sparkles v1 BETA LANDED πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰ thanks fcard!

License

Notifications You must be signed in to change notification settings

coderofsalvation/powscript

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

86 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

[![Travis build status](https://travis-ci.org/coderofsalvation/powscript.svg?branch=master)](https://travis-ci.org/coderofsalvation/powscript.svg?branch=master) write shellscript in a powful way!

Usage

$ 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

Wiki

Example

#!/usr/bin/env powscript
require 'foo'

usage(app)
  echo "$app <number>"
  
switch $1
  case [0-9]*
    echo "arg 1 is a number"
  case *
    if empty $1
      help=$(usage myapp)
      echo "Usage: $help" && exit

Check here for more examples

Features

  • indentbased, memorizable, coffeescript-inspired syntax
  • more human-like, less semantic noise like { ! [[ @ ]] || ~=
  • safetynets: automatic quoting, halt on error
  • comfort: easy arrays, easy async, functional programming, named variables instead of positionals
  • Modules / bundling
  • written in bash 4, 'zero'-dependency solution
  • hasslefree: easy installation without gcc compilation/3rd party software

Examples

Interactive mode (experimental)

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
> 

POSIX /bin/sh compatibility

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 not 100% tested, so please remove bashisms manually using docs/tools like bashism guide or https://linux.die.net/man/1/checkbashisms The general rule for POSIX sh-output is: don't write bashfeatures in powscript

Live expansion inside editor

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 users

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

About

transpiler written in bash: painless shellscript, indentbased, coffee for the shell with hipster-sparkles v1 BETA LANDED πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰ thanks fcard!

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages

0