SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Bash script which adds a line before every curly brackets

  1. #1
    SitePoint Enthusiast laresistance2's Avatar
    Join Date
    May 2011
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Bash script which adds a line before every curly brackets

    Hello,
    I need to create a bash script that adds a row before every curly bracket for functions, classes (classes and methods) and try/catch blocks in PHP code.

    I think using the program in conjunction with sed
    E.G. : find . -type f \( -name "*.php \) -exec sed .......

    For example:

    PHP Code:
    <?php
    function my_function() {

    }
    Becomes:

    PHP Code:
    <?php
    function my_function() 
    {

    }
    Can you help me so that I can achieve this, please?

    Thank you!

  2. #2
    Grüße aus'm Pott
    SitePoint Award Recipient Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    2,422
    Mentioned
    39 Post(s)
    Tagged
    1 Thread(s)
    Hi,
    Not much good at Bash, but this would be quite simple in Ruby.
    Do you have access to Ruby?
    How well do you know your JavaScript from your jQuery?
    Check out SitePoint's latest JavaScript challenge


    My blog

  3. #3
    Community Advisor silver trophy
    SitePoint Award Recipient
    Join Date
    Nov 2006
    Location
    UK
    Posts
    2,341
    Mentioned
    21 Post(s)
    Tagged
    1 Thread(s)
    Might be worth looking at this http://phptidy.berlios.de/
    or php beautifier

  4. #4
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    1,863
    Mentioned
    28 Post(s)
    Tagged
    0 Thread(s)
    There's several IDEs out there that have code formatting scripts. I believe Eclipse is one of them, though I'm not sure if you can customize it to what you want.
    <?php
    //Kyle Wolfe
    echo devBlog("My Dev Notes");

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •