With Brunch is it possible during production build not to minimize certain js files (may be they are already minimised, or else) whilst still packing theses files along with the others ?
Thanks in advance
It certainly is possible. Quoting the docs of uglify-js-brunch,
Joined files can be ignored and be passed-through, using 'ignored' option:
config =
plugins:
uglify:
ignored: /non_minimize\.js/
(https://github.com/brunch/uglify-js-brunch)
The only requirement is that ignored be a regexp, so, for example, if you wanted to ignore several files, e.g. vendor/a.js and vendor/b.js, you'd go about it like this:
ignored: /^venodor\/a\.js|^vendor\/b\.js/
(You have to escape / to treat it as a slash because otherwise it'd be the regexp literal bounds marker, and . to interpret it as a dot and not a placeholder for any one character.)
Related
I'm trying to write a simple cronjob that recurses through the folders & files nested in /OneDrive and replaces file or folder name characters that are not A-Z, a-z, 0-9, or . with an _. (This strikes me as the easiest way to resolve syncing errors.)
Building off this StackExchange post I've managed to get most of the way there using:
zmv '**/*' '$f:h${${f:t}//[^A-Za-z0-9]/_}'
This regex expression, however, does not exclude .'s, which results in all of the file extensions in all of my folders being changed to _s (e.g. file.txt becomes file_txt).
I'm far from an advanced regex user, and all of the various permutations of this command I've used have thrown errors, including:
zmv '**/*' '$f:h${${f:t}//[^\.A-Za-z0-9]/_}'
zmv '**/*' '$f:h${${f:t}//[^.A-Za-z0-9]/_}'
zmv '**/*' '$f:h${${f:t}//[^A-Za-z0-9\.]/_}'
I'm sure the correct regex expression is obvious; I'm afraid it's just not obvious to me.
If anyone could provide some guidance here, along with a brief explanation of why my previous attempts didn't work, I'd be grateful for the small contribution to my understanding of regex.
The :h modifier stripped out a slash; this has it added back in:
zmv '**/*' '$f:h/${${f:t}//[^\.A-Za-z0-9]/_}'
I'm not sure why that was missing from the original answer you referenced.
Some notes / caveats:
the -n option for zmv can be very helpful in tracking down issues like this.
a single call to zmv may not be able to rename both file names and directory names; multiple passes could be needed.
zmv uses file globbing patterns. Globbing patterns are similar to regular expressions, but there are a number of significant differences, so a lot of documentation for regexes will not apply here.
I want to create a build system for my app where it will open a url to the target file. For example, if I run the build on a project file components/flower.html, it should run
open http://localhost:8080/app/components/flower.html
The list of variables for ST don't have relative path. so the closest I get is
http://localhost:8080/app//dev/myproject/components/flower.html
It contains the full path. Perhaps there is an easy way to remove the /dev/myproject part?
This is the build setting I want to further customise:
"cmd": ["open", "http://localhost:8080/app/${file_path}"]
If we look at the documentation on Build Systems, we see that we can use snippet substitution in the variables used in the build system. This is really handy when the built in variables don't quite meet our needs.
Therefore, we can replace the project dir with nothing to get a relative path.
I find the easiest way to test substitutions is using a snippet for $SELECTION, so you can just change the selected text and try a different test case, without needing to worry about saving the file with different names or running the build system and waiting for the results.
The substitution is done with regular expressions, where forward slashes need to be escaped, as they have special meaning. One slash after the variable name, one slash after the find regex pattern, one slash after that, followed by the replacement pattern, followed by a slash to indicate the end of the replacement pattern and optionally followed by some regex flags. Therefore, the snippet I'm using is:
<snippet>
<content><![CDATA[
${SELECTION/^\/dev\/myproject\///}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>
This just matches from the beginning of the string (^), then the literal /dev/myproject/ (unfortunately variables can't be used in regex patterns, otherwise we could maybe use $project_path) and replaces it with nothing. As we are only expecting one match, we don't need to use the global regex modifier flag.
The output we get from that with a selection of /dev/myproject/components/flower.html is:
components/flower.html
Which seems to be what we want, because with http://localhost:8080/app/ preceding it, it becomes http://localhost:8080/app/components/flower.html.
So, now we can just take the variable part out the snippet, and replace SELECTION with file_path, so it will operate on the current file's path instead of the selection, just like you had originally, and plug that into your build system:
"cmd": ["open", "http://localhost:8080/app/${file_path/^\/dev\/myproject\///}"]
Directory workspace contains like 5 projects:
project-1
project-2
project-3
project-4
project-5
I want to match all folders in this directory, but the array does not get populated when I use a variable:
workspace="~/workspace";
myDirectories=(${workspace}/project-*/);
If I pass it in manually it picks up the directories without a problem.
myDirectories=(~/workspace/project-*/);
I know it is something simple I am missing, but it is bugging me!
You have used quotes in workspace variable declaration like:
workspace="~/workspace"
So the ~ won't be expanded as the home directory, but would be treated literally.
You can:
Leave ~ outside quotes (note that, quotes are not strictly necessary in this case):
workspace=~/"workspace"
Or use $HOME instead of ~:
workspace="$HOME"/workspace
Or use absolute paths starting with / e.g. /home/username/workspace
The ~ won't work correctly (expand to user home directory) unless it is unquoted.
As an * also needs to be unquoted to expand.
You could define the directory as a fixed string (remove the leading ~):
workspace="workingdirectory" # or just workspace=workingdirectory
And leave all the expansions to the array definition (both work):
myDirectories=( ~/"${workspace}/"project-*/ );
myDirectories=( "${HOME}/${workspace}/"project-*/ );
You may use fixed directories like: "/home/user/$workspace/"project-*/ but in this case you lose the adaptability to any current user running the script without any real gain.
It is also possible to use the ~/ at the time of defining the variable workspace but that would also fix the user to the user running that part of the script, which may not be the same as the one doing the directory expansions.
All considered, expanding at the time of creating the array seems to b ethe best solution, and both solutions above work well.
In Linux how do I use find and regular expressions or a similar way without writing a script to search for files with multiple "dots" but IGNORE extension.
For e.g search through the following files will only return the second file. In this example ".ext" is the extension.
testing1234hellothisisafile.ext
testing.1234.hello.this.is.a.file.ext
The solution should work with one or more dots in the file name (ignoring the extension dot). This should also work for any files i.e. with any file extension
Thanks in advance
So if I understand correctly, you want to get the filenames with at least two additional dots in the name. This would do:
$ find -regex ".*\.+[^.]*\.+[^.]*\.+.*"
./testing.1234.hello.this.is.a.file.ext
./testing1234.hellothisisafile.ext
$ find -regex ".*\.+[^.]*\.+[^.]*\.+[^.]*\.+.*"
./testing.1234.hello.this.is.a.file.ext
The key dot detecting part is \.+ (at least one dot), coupled with the separating anything (but a dot, but the previous part covers it already; a safety measure against greedy matching) [^.]*. Together they make the core part of the regex - we don't care what is before or after, just that somewhere there are three dots. Three since also the one from the current dir matters — if you'll be searching from elsewhere, remove one \.+[^.]* group:
$ find delme/ -regex ".*\.+[^.]*\.+[^.]*\.+[^.]*\.+.*"
delme/testing.1234.hello.this.is.a.file.ext
$ find delme/ -regex ".*\.+[^.]*\.+[^.]*\.+.*"
delme/testing.1234.hello.this.is.a.file.ext
In this case the result is the same, since the name contains a lot of dots, but the second regex is the correct one.
I am getting files like .log and _log in a folder ,i am able to pick .log files with /*.log$/ but unable to find files which are _log .
need a regex pattern which will take both type of files from a specified folder.
Your question is tagged both 'perl' and 'linux'. I'll assume here that you're talking about Perl style regular expressions, as it looks like that's what you are showing in your example snippet.
The *. sequence is a mistake.
Let's focus on what you want to match. You want to match any filename that ends in a dot followed by the literal characters 'log'. You also want to match any filename that ends in an underscore, followed by the literal characters 'log'. You really shouldn't concern yourself with the "anything at all" that can come before the final dot or underscore. So the regexp would probably be better written as this:
/[._]log$/
Notice we don't even bother with the dot-star. It isn't helpful in this situation.
If you want for your pattern to also match files where the literal characters 'log' may optionally be followed by an integer sequence (not mentioned in your question, but discussed in one of your followup comments), you could write it like this:
/[._]log\d*$/
Here the 'star' is helpful; it allows for zero or more digits sandwiched between the 'g' and the end of the string.
I totally agree (by upvoting) with DavidO's solution but it usually makes more sense, and increase readability, to use glob() to get a list of files from a particular directory
my $dir = "/path/here";
my #log_files = grep { /[\._]log\d*$/ } glob("$dir/*");
print join "\n", #log_files;
This will catch
foo.log
foo_log
foo.log1
foo_log22
Use the regexp /.*[._]log$/.
I'm surprised your first case worked -- /*.log$/ isn't legal regexp (since the * doesn't say what it is supposed to match zero-or-more of). Double-check your current results.