Giter Club home page Giter Club logo

powscript's Introduction

[![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 (experimental)

Wiki

Example

#!/usr/bin/env powscript
require_cmd 'curl'

usage(app)
  echo "$app <jsonkey>"

print_json(key)
  json={}      
  curl "https://raw.githubusercontent.com/coderofsalvation/powscript/master/package.json" | json_decode json 
  echo $json[$key]

run()
  if empty $1
    help=$(usage myapp)
    echo "Usage: $help" && exit
  print_json $1

run $@

Output:

$ ./myapp version
1.0.26

Check here for more examples

Features

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 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

Debug your powscript syntax

See FAQ

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.