gistya / expandr Goto Github PK
View Code? Open in Web Editor NEWa cool shell script for git keyword expansion.
a cool shell script for git keyword expansion.
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:
sed
/grep
to select only relevant SECTION ranges in config file.sed
which translates its input into working sed
scriptsed
reads it as a script and performs file edits as necessary.A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.