Run code formatter from the command line with PhpStorm open - intellij-idea

If I go to my PhpStorm\bin folder I can run the format.bat command to format files from the command line e.g.
phpstorm format -r C:\path\to\my\code -r -s c:\path\to\my\settings.xml
and that works great. However I cannot run the command if PhpStorm is open, I get an error:
Only one instance of PhpStorm can be run at a time
Not ideal to have to close my IDE or have to use a 3rd party code formatter. Is there any workaround? Without installing another copy of PhpStorm.

It's a known issue, please see: https://youtrack.jetbrains.com/issue/IDEA-160462

The link from y.bedrov led me to here https://confluence.jetbrains.com/display/IDEADEV/Command-Line+Source+Code+Formatter with a potential solution.
Unfortunately I don't seem to be able to get it to work, I had to resort to copying my PhpStorm directory and using the copy instead. But I add it here in hopes that it helps others
Running Command-Line Formatter when the IDE is Running
On Linux/MacOS
Go to /bin directory where is a directory where Intellij IDEA or Intellij IDEA-based product is installed.
Copy idea.properties to some other file, for example, format.properties
Modify format.properties as follows:
Uncomment the lines:
# idea.config.path=${user.home}/.IntelliJIdea/config
# idea.system.path=${user.home}/.IntelliJIdea/system
Change them to point to some directories which differ from defaults, for example:
idea.config.path=${user.home}/.IntelliJIdea/format/config
idea.system.path=${user.home}/.IntelliJIdea/format/system
Modify format.sh by adding the line with IDEA_PROPERTIES variable:
\#!/bin/sh
\# ------------------------------------------------------
\# IntelliJ IDEA formatting script.
\# ------------------------------------------------------
IDE_BIN_HOME="${0%/*}"
export IDEA_PROPERTIES=$IDE_BIN_HOME/format.properties
exec "$IDE_BIN_HOME/idea.sh" format "$#"
Run format.sh without closing the IDE, it should give the following output:
IntelliJ IDEA ..., build ... Formatter
Usage: format [-h] [-r|-R] [-s|-settings settingsPath] path1 path2...
-h|-help Show a help message and exit.
-s|-settings A path to Intellij IDEA code style settings .xml file.
-r|-R Scan directories recursively.
-m|-mask A comma-separated list of file masks.
path.. A path to a file or a directory.
On Windows
You have to create a separate format.properties file as described above for Linux/MacOS.
Change format.bat file by adding a line with IDEA_PROPERTIES variable as follows:
#ECHO OFF
::----------------------------------------------------------------------
:: IntelliJ IDEA formatting script.
::----------------------------------------------------------------------
SET IDE_BIN_DIR=%~dp0
SET IDEA_PROPERTIES=%IDE_BIN_DIR%\format.properties
CALL "%IDE_BIN_DIR%\idea.bat" format %*
Run format.bat, it will list the command-line formatter options.

This guide works for me. But ensure use PHPSTORM_PROPERTIES instead of IDEA_PROPERTIES when export environment variable as described in the article:
export IDEA_PROPERTIES=$IDE_BIN_HOME/format.properties
And what's more, from version 2022.1, IntelliJ IDEA supports dry run which is very useful for format validation based pre-commit git hook.

Related

Error in running trace32 with command line

I have a .cmm file which helps in debugging of Qcomm chipsets.
This file has a line : cd ../../../../../modem_proc
When I run this same cmm file using T32 GUI, it runs fine and does the work. But when I am trying to run the same file using windows command line using,
C:\T32\bin\windows64>t32mqdsp6.exe -c C:\T32\config.t32 -s D:\path\to\xxx.cmm
Following error is thrown in T32: syntax error in B::cd ../../../../../modem_proc
What am I missing here? I have no hands-on experience with T32 what-so-ever.
The problem probably results from different working directories. Type
PRINT OS.PWD()
in the GUI and add it to the top of the script. I'd suspect they are different.
Don't use working directory relative paths, instead use paths relative to the script, e.g.
CD ~~~~/../../../../modem_proc
The four tilde (~) symbols mean "directory of the currently executed script". There's still a possible issue with this solution when using multiple GUIs and the intercom, but for most use-cases this should be OK.
When starting TRACE32 (up to build 99518) without option "-s", it starts a default script t32.cmm form your TRACE32 installation directory. But t32.cmm is not executed, when "-s" is used.
So probably your t32.cmm is changing your working directory. If so you can fix the issue by adding the line
DO ~~/t32.cmm
to the top of your script xxx.cmm.
See also https://www.lauterbach.com/frames.html?help_autostart.html
The default working path is also set by the TRACE32 configuration file. That is the file passed with "-c". So if your are using a different configuration file than C:\T32\config.t32 when starting your TRACE32 GUI the normal way, then you should use that configuration file also when starting TRACE32 from the command line.
To get the path of the configuration file usually used, start TRACE32, execute command AREAand then command PRINT OS.PCF()
Furthermore dev15 is probably right here https://stackoverflow.com/a/53671657/4727717:
Use paths relative to the PRACTICE script (cmm-file) by starting each path with four tildes.

How to specify the file encoding in IntelliJ's command line formatter

After running IntelliJ's command line code formatter on a set of Java source files the German characters in the source are replaced with "garbage".
How can I configure the input and output encoding of the formatter?
I tried adding -encoding iso-8859-15 -docencoding iso-8859-15 as an option to the formatter command line but those options are not recognized.
I also tried creating an idea.properties file with the following content:
-Dfile.encoding=ISO-8859-15
And running the formatter with the environment variable IDEA_PROPERTIES set pointing to this file:
C:\>set IDEA_PROPERTIES="E:\project\config-files\idea.properties"
I also tried inserting the option -Dfile.encoding=ISO-8859-15 directly in the idea.bat file (which is called by the format.bat.
None of these worked.
How can I ensure that the formatter respects the encoding of these source files?
Command line used now is like
C:\>"C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.2.4\bin\format.bat" -r E:\project\java style -m *.java -s e:\project\config-files\CodeStyleSettings.xml
Note: If I convert the source file to UTF-8 before running the formatter the formatting works as expected (the German characters are preserved).
Another note: If the format code is run within the IDE GUI it is possible to set the file encoding in the project options. The command line formatter does not make use of a project so these settings are not respected.
The goal is to turn this into a step in our automated process that can be run by any of a number of users. So I'd like to avoid changes to config files in a user's specific directory like the IDE configuration directory.

how to use CAM::PDF to find + replace from command line

Sorry for the noob question. I just downloaded CAM::PDF along with Strawberry for Windows, and trying to do find/replace from the command line. Ran buidinstalldeps to get all needed prereqs.
I'm trying to run changepagestring.pl from command line. But idk how to reference the file location and have it put the output file for me in a specified location:
changepagestring.pl master-exch-manual.pdf "as shown in Figure" figure output.pdf
My goal is to replace "see above figure" with "figure" in this file. But it's in a different directory than the one I'm in, C:\Users\Me\Doc\CAM-PDF-1.60\
So how do I run and do all this from the command line. I've seen the help file with example, but I get this:
CAM::PDF from command shell with PL file not recognized
There are a few possible solutions. The easiest one from the directory you mentioned is:
perl -Ilib bin/changepagestring.pl ...
Alternatively, if you run the usual Perl install commands from that folder, then changepagestring.pl should be included in your usual path
perl Makefile.PL
make install
Alternatively^2, you can use the "cpan" tool to automate the download, build, test and install steps in one go:
cpan install CAM::PDF

How to use gitbash instead of windows cmd.exe with meteor Release 0.7.0.1-win2

I am getting started with Meteorjs. I'm a windows user so I downloaded the windows installer package Release 0.7.0.1-win2. I use gitbash for my command line interface and can't get it to recognize meteor. I get the error "sh.exe": meteor: command not found". It works fine in windows command line but I prefer gitbash.
How do I get meteor to work with gitbash?
I have the perfect answer for you since I literally just solved the issue myself.
First of all make sure meteor works in the default windows command prompt. Next open git bash and check if the following command works:
cmd //c meteor
This runs the command meteor as if you were in the command prompt.
Next step is to set up an alias in git bash so you don't have to type that out each time.
Open git bash and enter the following:
vim ~/.bashrc
this will open/create the bashrc file in VIM, press i to insert and type the following:
alias meteor="cmd //c meteor"
Save and exit vim by first pressing the Esc key then press the ":" key. Now you should be able to enter commands in VIM. Type "wq" and press enter which will write into your .bashrc file and exit vim.
Almost there! Now that you are back in git bash, all you need to do is point to your .bashrc file by entering the following:
source ~/.bashrc
Now you will be able to run meteor commands straight from git bash! Hope that helped!
Here's the fix:
The problem is because of .bat files not being handled properly by
MinGW
Go to this directory - C:\Users[your username]\AppData\Local\.meteor
You should see a meteor.bat file there. Create a new file called "meteor" (without any extension and ""). Open it with notepad and paste the following:
#!/bin/sh
cmd //c "$0.bat" "$#"
save the file and now run git bash. You should be able to use meteor command in git bash.
Details
To run a *.bat command from MinGW's MSYS shell, you must redirect the execution to cmd.exe, thus:
cmd //c foo.bat [args ...]
The foo.bat command file must be in a directory within $PATH, (or you must specify the full path name ... using slashes, not backslashes unless you use two of them for each path name separator). Also, note the double slash to inform cmd.exe that you are using its /C option, (since it doesn't accept the -c form preferred by the MSYS shell.
If you'd like to make the foo.bat file directly executable from the MSYS shell, you may create a two line Bourne shell wrapper script called simply foo alongside it, (in the same directory as foo.bat), thus:
#!/bin/sh
cmd //c "$0.bat" "$#"
(so in your case, you'd create script file meteor alongside meteor.bat).
In fact, since this wrapper script is entirely generic, provided your file system supports hard file links, (as NTFS does for files on one single disk partition), you may create one wrapper script, and link it to as many command file names as you have *.bat files you'd like to invoke in this manner; (hint: use the MSYS ln command to link the files).
Credits to: Keith Marshall on SO and rakibul on Meteor Forums
It shouldn't be too hard - you just need to make sure that the meteor.bat file is in your executable. Check with echo $PATH from the bash console if it is already there.
For me, the meteor 0.7.0.1-win installer appended meteor's folder to the path automatically. However, you can add it manually with:
export PATH=$PATH:/path/to/user/folder/AppData/Local/.meteor
(On CygWin my user folder is at /cygdrive/c/Users/adam - I'm not sure what the equivalent path would be on git bash).
If you like, append that line to your ~/.profile to make sure meteor gets added to the path when the console opens.
Finally, on Windows the executable file is meteor.bat. I made a symbolic link to the filename meteor, just so I wouldn't have to type the .bat:
cd /path/to/user/folder/AppData/Local/.meteor
ln -s meteor.bat meteor.
Please have a look at the issue https://github.com/sdarnell/meteor/issues/18
I would suggest maybe creating a trivial wrapper script or alias that invokes LaunchMeteor.exe with the original arguments.
After more research on google I see that there isn't an implemented way to do this yet. The guys at meteor are working on it and accepting pull requests if you have a solution. The conclusion I came to is to use Vagrant and virtualbox to set up a ubuntu vm for meteor development. You can find info at this site: http://win.meteor.com/ on how to install virtual machines and provision to work with meteor.

Change Code Signing of Project from command line

I made a script to copy,rename and change Bundle Id of a project from command line, after that process, my next step is to change the code signing of the project to point to the new certificates.
Is there any way of doing this from command line?
Edit: I just saw that that info is stored on the .pbxproj, how can I change that file?
You can re-sign a build using the following:
export CODESIGN_ALLOCATE=`xcode-select -print-path`/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
codesign -f -s "iPhone Developer" -vv Example.app/Example
If all you have is an IPA, just unzip it, it's a normal zip file with a single Payload directory containing your application.
Edit:
If you need to change an Xcode project itself, an Xcode project is just a bundle, change into the directory and open the project.pbxproj file. You should be able to simply use sed to find and replace the developer identity.
There may be better options, such as supplying the setting on the command-line to xcodebuild. If you give more background on what it is you are trying to do, you may get better suggestions.