2017 © Pedro Peláez
 

library bash-writer

Write quickly and easily bash scripts with PHP

image

lalbert/bash-writer

Write quickly and easily bash scripts with PHP

  • Friday, September 30, 2016
  • by lalbert
  • Repository
  • 1 Watchers
  • 1 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

php-bash-writer

Write quickly and easily bash scripts with PHP., (*1)

PHP Bash Writer is not designed to run bash script but only to facilitate writing scripts by adding styles (color, bold, ...) on the output., (*2)

Internally it uses symfony/console to manage the color and styles (see OutputFormatter)., (*3)

Installation

The best way to install PHP Bash Writer it use composer, (*4)

composer require lalbert/bash-writer

Usage

$sh = new BashWriter();

$sh->addCommand('#!/bin/bash', ['print' => false]);

$sh->newLine(); // Add new blank line only in file, not on output
$sh->newLine(true); // Add new line on output (write "echo")

$sh->addCommand('cd $HOME'); // print 'cd /home/user' and run command
$sh->addCommand('ls -la', ['print' => 'List files in <comment>`(pwd)`</comment> folder']); // print 'List files in `(pwd)` folder' whith result of pwd in yellow, and run command

$sh->addCommand('touch <bg=yellow;options=bold>file.txt</>'); // print 'touch file.txt' with 'file.txt' in yellow and bold, and run 'touch file.txt'
$sh->addCommand('echo "content file" > file.txt', ['print' => false]); // add content in file.txt, shows nothing

$sh->newLine(true);
$sh->output('<info>Done</info>'); // print "Done" in green text

// save script in script.sh file
file_put_contents('script.sh', $sh);

Now, the file script.sh contains the following script:, (*5)

#!/bin/bash

echo
echo -e "cd $HOME"
cd $HOME
echo -e "List files in ^[[33m`(pwd)`^[[39m folder"
ls -la
echo -e "touch ^[[43;1mfile.txt^[[49;22m"
touch file.txt
echo "content file" > file.txt
echo
echo -e "^[[32mDone^[[39m"

The Versions

30/09 2016

dev-master

9999999-dev

Write quickly and easily bash scripts with PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

php bash shell bash color bash style

30/09 2016

dev-develop

dev-develop

Write quickly and easily bash scripts with PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

php bash shell bash color bash style