How to rename a batch of files with webstorm 10 - webstorm

I want to change in a project from javascript to typescript.
Therefore i want to change the extensions of all files from *.js to *.ts recursively.
How do i accomplish it with webstorm?

There's no way to rename multiple files in the project in WebStorm, unfortunately.
You can vote for the related issue on JetBrains issue tracker.

Do it outside of Webstorm on linux (or Windows git bash) with ..
cd my-folder
find . -name "*.t1" -exec bash -c 'mv "$1" "${1%.t1}".t2' - '{}' \;
courtesy of Recursively change file extensions in Bash
This works recursively, make sure you cd to the correct folder first (typically your project root folder).

Related

Can git rm take a regex or can I pipe the contents of a file to git rm?

I'm trying to remove all of the folder meta files from a unity project in the git repo my team is using. Other members don't delete the meta file associated to the folder they deleted/emptied and it's propagating to everyone else. It's a minor annoyance that shouldn't need to be seen so I've added this to the .gitignore:
*.meta
!*.*.meta
and now need to remove only the folder metas. I'd rather remove the metas now than wait for them to appear and have git remove them later. I'm using git bash on Windows and have tried the following commands to find just the folder metas:
find . -name '*.meta' > test.txt #returns folders and files
find . -regex '.*\.meta' > test.txt #again folders and files
find . -regex '\.[^\.]{0,}\.meta' > test.txt #nothing
find . -regex '\.[^.]{0,}\.meta' > test.txt #nothing
find . -regex '\.{2}' > test.txt #nothing
find . -regex '(\..*){2}' > test.txt #nothing
I know regex is interpreted differently per program/language but the following will produce the results I want in Notepad++ and I'm not sure how to translate it for git or git bash:
^.*/[^.]{0,}\.meta$
by capturing the lines (file paths from root of repo) that end with a /<foldername>.meta since I realized some folders contained a '.' in their name.
Once this is figured out I need to go line by line and git rm the files.
NOTE
I can also run:
^.*/.*?\..*?\.meta$\n
and replace with nothing to delete all of the file metas from the folders and files result, and use that result to get all of the folder metas, but I'd also like to know how to avoid needing Notepad++ as an extra step.
To confine the results only to indexed files use git ls-files, the swiss-army knife of index-aware file listing. git update-index is the core-command index munger,
git ls-files -i -x '*.meta' -x '!*.*.meta' | git update-index --force-remove --stdin
which will remove the files from your index but leave them in the work tree.
It's easier to express with two conditions just like in .gitignore. Match *.meta but exclude *.*.meta:
find . -name '*.meta' ! -name '*.*.meta'
Use -exec to run the command of your choice on the matched files. {} is a placeholder for the file names and ';' signifies the end of the -exec command (weird syntax but it's useful if you append other things after the -exec ... ';').
find . -name '*.meta' ! -name '*.*.meta' -exec git rm {} ';'

Dojo build - get rid of *.consoleStripped.js files

I recently upgraded our dojo build from dojo 1.9.1 to 1.9.10, and for some reason now I am seeing *.consoleStripped.js files left over from the optimizer. It's great that it's removing the console statements, but I would expect these would be intermediate files not included in the final build product. When I look at util/build/transforms/optimizer/closure.js, I don't see any code to remove the files. I can manually remove them with a find blah blah | xargs rm, but is there a setting to remove these files after they are used to create the final minimized files? I can't seem to find one. Or is there some reason that I am missing to deploy these "consoleStripped" files alongside the other files (mimized, uncompressed, and map)?
You can use:
stripConsole: "normal"
to strip from your build all console.
Use:
layerOptimize: "closure"
to switch to closure if you need too.
Full documentation related to Dojo Build Optimization can be found here:
https://dojotoolkit.org/documentation/tutorials/1.10/build/
Edit:
Dojo build cannot delete you *.consoleStripped.js for that you need to use grunt, gulp or another external tool.
I believe that dojo-build uses ShrinkSafe by default, and not Google Closure (ref).
Either way, both have their codes hidden away in Java .jar files.
I remove these files by adding the below to the very end of my build script - ensuring that I have 'cd' to the distribution folder first.
find . -regextype posix-extended -regex "(.*\.bak|.*\.consoleStripped\.js|.*\.uncompressed\.js|.*\.map)$" -type f -delete

Change the name of many files

How can I rename many files. Remove the digits at the beginning.
I have a Mac. All the files are in the same folder.
The pattern is:
1, 2 or 3 digits - any name.php
With Regular Expression, I think it would be:
\d*-(.*).php
For example:
1-marketing.php
2-3D.php
3-without.php
I want to remove the numbers and the dash at the beginning.
In the example it would be:
marketing.php
3D.php
without.php
What I have explored two ways:
Select the files > ctrl click > rename items. This is a fantastic method to change the name of files. But I think it cannot be used in this case. If I understand, it does not support Regex. Am I right?
Terminal. I am not very familiar with terminal. I tried mv 1-marketing.php marketing.php It works for 1 file, but how can I do the same for many? I am new with the terminal. If it can be done, please explain the basic.
Open the terminal app in Mac OS X and navigate to the folder containing the .php files
cd /my/path/to-php-files/
and run the below command on the command-line.
for file in *.php; do mv -v "$file" "${file#*-}"; done
The bash parameter expansion syntax ${file#*-} removes the characters before - from the beginning, so ideally 3-number-without.php becomes number-without.php
(or) use the perl rename utility not available by default in Mac OS, you can download and install it with homebrew 🍺:
brew install rename
and do
rename -n 's/^(\d+)-(.*)/$2/' *.php
The -n is just for a dry-run to see how the files are to be renamed, remove it as
rename 's/^(\d+)-(.*)/$2/' *.php
for the actual renaming.

Execute gradle build task from any location

I´m trying to build my gradle projects from other locations than the project folder itself, but it always says it couldn´t find build task.
What I´ve tried so far:
sudo ./myprojects/myapp/gradlew build
sudo ./myprojects/myapp/gradlew ./myprojects/myapp/build
How can I execute a gradle build task from any location?
Various people have written (and published) scripts to execute gradlew from any subproject directory (in a multi-project build). To reliably execute Gradle from any subdirectory, it is necessary to set the "current project directory" via -p. It would be nice to have this restriction lifted (this would make a good feature request).
You may try this script, which is 90-lines long: https://github.com/dougborg/gdub
Or use this straightforward one-liner I use myself:
function lookupgradle() {
find . .. ../.. ../../.. ../../../.. ../../../../.. ../../../../../.. -maxdepth 1 -name 'gradlew' -executable -print -quit
}
alias g='$(lookupgradle)'
If you'll find out that it is still required to specify project directory, add -p .:
alias g='$(lookupgradle) -p .'
./usmobile-microservice/gradlew -p ./usmobile-microservice clean buildUI
./project_directory/gradlew -p ./project_directory clean build
worked for me

Bash script to change file extension using regex

I have a lot of files i've copied over from my iphone file system, to start with they were mp3 files, but app on iphone changed their names to some random staff which looks like:
1c03e04cc1bbfcb0c1237f57f1d0ae2e.mp3?extra=f7NhT68pNkmEbGA_I1WbVShXQ2E2gJAGBKSEyh3hf0hsbLB1cqnXDuepYA5ubcFm_B3KSsrXDuKVtWVAUh_MAPeFiEHXVdg
I only need to remove part of file name after mp3. Please give me a script - there are more than 600 files, and manually it is impossible.
you can use rename command:
rename "s/mp3\?.*/mp3/" *.mp3*
#!/bin/bash
shopt -s nullglob
for F in *.mp3\?*; do
echo mv -v -- "$F" "${F%%.mp3\?*}.mp3"
done
Save it to a script like script.sh then run as bash /path/to/script.sh in the directory where the files exist.
Remove echo when you find it correct already.