Code Monkey home page Code Monkey logo

expandr's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

expandr's Issues

possible direction?

So, we talked about this the other day. I actually got back in the chat room last night, though I don't think you've seen it - (your profile indicates you haven't logged in since)...

Anyway, here is a really rough 1/4 way there sed implementation - (updated):

tab='       ' nl='
'; LC_ALL=C \
sed '/^#####/,/^#####/d
    /["#@]/!d
    /^###[^#]/,/^#['"$tab"' ]*$/!d
    /^#/{   /^###[^#]/!d
};  s/[]|\\$^*[]/\\&/g
    s/\([^ '"$tab#].*[^ $tab"'"#]\).*/\1/
    /^#[ '"$tab"'#]*\(.*\)/{ 
        s//\1/;h;d
};  s/^[^"]*"\(.*\)/"|\1|/
    //!G
    s/@\(.*\)\n\(.*\)/\2\1@|/
    s/^[^"]/@|@&/
'

I read your updated notes this morning - and I think I'm beginning to understand better. I'll be honest about this - my hope is that doing this would help me to learn to use git. I don't know how - and I'd really like to. This is probably obvious considering I posted this as an issue. While that may be true - it's not your issue but mine. Yours works - this doesn't... yet. I'm hoping we can help each other - because I really am very good with sed and portable shell-script, but not much else.

This update actually does less than before. It does not print working sed script. It parses a config file and prints something very near to sed script that should be easily transformable depending on intended action. Given the following input:

###LIVE_###
@AWS_ACC$ESS_KEY_ID
        "fi|ll* in with real value"
@AWS_SECRET_ACCESS_KEY
        "fill in with real value"
@MERCHANT_ID
        "fill in with real value"
@APPLICATION_NAME
        "fill in with real value"
#^this is the AWS application name^#
;lkj;lkj
#LIVE_APPLICATION_NAME[2]="/fill in walue/!"

#
###SANDBOX_###
@AWS_ACCESS_KEY_ID
        "fill in with real value"
@AWS_SECRET_ACCESS_KEY
        "fill in with real value"
@APPLICATION_NAME
        "fill in with real value"
@MERCHANT_ID
        "fill in with real value"
#

It prints...

@|@LIVE_AWS_ACC\$ESS_KEY_ID@|
"|fi\|ll\* in with real value|
@|@LIVE_AWS_SECRET_ACCESS_KEY@|
"|fill in with real value|
@|@LIVE_MERCHANT_ID@|
"|fill in with real value|
@|@LIVE_APPLICATION_NAME@|
"|fill in with real value|
@|@SANDBOX_AWS_ACCESS_KEY_ID@|
"|fill in with real value|
@|@SANDBOX_AWS_SECRET_ACCESS_KEY@|
"|fill in with real value|
@|@SANDBOX_APPLICATION_NAME@|
"|fill in with real value|
@|@SANDBOX_MERCHANT_ID@|
"|fill in with real value|

Basically it wants input like:

  ###SECTION###
  @SEARCH_VALUE1
     "replace value1"
  @SEARCH_VALUE2
       "replace value2"
  #

where SECTION replaces the first @ character on any SEARCH_VALUE line.
On ###SECTION### and SEARCH_VALUE lines all whitespace is removed.
There can be multiple "replace value" lines per SEARCH_VALUE.
On "replace value" lines all characters before the first and following the last " are removed
So the leading whitespace there doesn't matter. Blank lines are ignored.
In fact, all lines not beginning w/ 3 hashes, or containing a @ or at least two " are ignored.
All lines, that is, but a line beginning with a single # and containing any amount of trailing whitespace.
Those lines serve to delimit each SECTION
Oh, and for SECTION lines the trailing hashes are optional - they don't matter.
Any line not within a ###SECTION through ^#$ range is ignored - even if it happens to match one of those 3 types of lines that aren't ignored.
And any lines within that range that begin with a hash are ignored as well - even if they contain two or more quotes and/or a @.

Probably you can see where my fatal flaw was though with the (SEARCH/replace) labels - those need to be interchangeable. I believe I am working toward that.

I am very interested to know what you think though - as, again, my understanding it admittedly limited. Do you think it could be a workable direction?

My roughly imagined workflow looks like:

  1. shell accepts args and calls first sed/grep to select only relevant SECTION ranges in config file.
  2. those config lines are passed to this sed which translates its input into working sed script
  3. last sed reads it as a script and performs file edits as necessary.

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.