I would like to know the correct parameters to be passed to Kdiff3 from Intellij IDEA's external diff tools menu in order to use Kdiff3 for merging.
At some point, the correct parameters were:
%2 %1 %3 -o %4
See the accepted answer for current values.
The parameters are:
%3 %2 %1 -o %4
Parameters %2 and %1 are interchangeable. %1 is for local changes and %2 are the changes in the base branch.
Considering kdiff3 documentation
Merging 3 files:
kdiff3 file1 file2 file3 -m
kdiff3 file1 file2 file3 -o outputfile
Note that file1 will be treated as base of file2 and file3.
For Intellij, %3 is the base version. %1 are the changes in the branch you are rebasing, %2 are the changes in the new base branch.
Intellij 2016.2 Ultimate edition
With Android Studio 3.0 Canary 1 (which is based on IntelliJ 2017.1) these values work for me:
external diff parameters: %3 %1 %2
external merge parameters: %3 %1 %2 -o %4
Related
*** ADDENDUM: I use Windows10, GNUWIN32 and Cygwin64 ***
Suppose I have the following screen output:
command1
command2
command3
The desired result is each line shown above is executed as a command immediately after it is displayed on screen.
command1
command2
command2
I have read this post which explains how to insert "echo" before each line of screen output.
How to apply shell command to each line of a command output?
It does this:
ls -1 | xargs -L1 echo
What I have done for the time being is insert "run.bat" infront of each line. The result is the following lines are executed:
run.bat command1
run.bat command2
run.bat command3
The content of run.bat is this:
%1 %2 %3 %4 %5 %6 %7 %8 %9
It works. But this work-around seems unncessarily long.
How do I use xarg (or awk or sed) to take each line of screen output as an individual command, and run it immediately and exactly as it is displayed on screen please?
PS: I also do not want to redirect & save all screen output into a separate batchfile first, and then execute all lines that way. I would like each line of screen output to be execute exactly as a command, exactly as it is displayed and immediately after the line is displayed (I do not need to add any prefix or suffixed to the lines; just execute each line exactly as displayed on screen).
Thanks.
You can pipe your output to this xargs command line:
... | xargs -n1 bash -c 'echo "$#"; "$#"' _
This xargs calles bash -c script that echoes each line on stdout and then executes it.
Context
I had a SO question successfully answered at https://stackoverflow.com/a/59244265/80353
I have successfully used the command that was given.
cap()(cd /tmp;rm -f *.vtt;youtube-dl --skip-download --write-auto-sub "$1";\
sed '1,/^$/d' *.vtt|sed 's/<[^>]*>//g'|awk -F. 'NR%8==1{printf"%s ",$1}NR%8==3'\
|tee -a "$2")
What does this command do?
This command will download captions for a youtube video as a .vtt file from $1 parameter
then print out the simplified version of the .vtt file into another file that's stated as parameter $2
This works as advertised.
How to call the command
In the terminal I will run the above command once and then run cap $youtube_url $full_path_to_output_file
What changes I would like
Currently, the $2 parameter must be a full path. Also currently, if the $2 parameter doesn't exist, an actual file will be created. What I would like is this behavior remains even for relative path. So hopefully for relative path, this behavior of creating a new empty file still works.
Update
I see that comments are such that there's nothing wrong with the command.
However, I did try running
cap $youtube_url $relative_path_to_a_text_file and it definitely did not work for me in macOS
Perhaps I am missing something else?
Update 2
This is a video of me running the awk sed command . First I did it with just a relative path. No output file shows up in the current working directory. The second shows me typing the full path and it works.
https://www.loom.com/share/1c179506fa5b48b4a3d62c81a9d2a411
I hope this clarifies the question i am raising and the commenters would kindly update their comments based on this video.
EDIT: Adding a solution after OP's comment which do checks inside OP's function itself, warning not tested it though.
cap()(
user_path=$(echo "$path_details" | awk 'match($0,/.*\//){print substr($0,RSTART,RLENGTH)}')
path_details="$2"
PWD=`pwd`
cd "$PWD"
user_path=$(echo "$path_details" | awk 'match($0,/.*\//){print substr($0,RSTART,RLENGTH)}')
if [[ -d "$user_path" ]]
then
echo "Present path $user_path."
##Call your program here....##
cd /tmp;rm -f *.vtt;youtube-dl --skip-download --write-auto-sub "$1";\
sed '1,/^$/d' *.vtt|sed 's/<[^>]*>//g'|awk -F. 'NR%8==1{printf"%s ",$1}NR%8==3'\
|tee -a "$2"
else
echo "NOT present path $user_path."
##Can exit from here. if needed.##
fi
)
I believe OP wants to check directory of relative path passed as 2nd argument, is present or not, if this is the case then one could try following.
cat file.ksh
path_details="$2"
PWD=`pwd`
##Why I am going to your path is, in case you are running this from cron, so in that case you can mention complete path here, rather than pwd as mentioned above.
cd "$PWD"
user_path=$(echo "$path_details" | awk 'match($0,/.*\//){print substr($0,RSTART,RLENGTH)}')
if [[ -d "$user_path" ]]
then
echo "Present path $user_path."
##Call your program here....##
else
echo "NOT present path $user_path."
##Can exit from here. if needed.##
fi
Explanation: Adding detailed explanation for above code.
cat file.ksh ##For OP reference to show content I am using cat script_name here.
path_details="$2" ##Creating variable path_details whose value is $2(2nd argument passed to script)
PWD=`pwd` ##Creating variable PWD whose value is pwd(current working directory).
##Why I am going to your path is, in case you are running this from cron, so in that case you can mention complete path here, rather than pwd as mentioned above.
cd "$PWD" ##Going to current directory, why I did is you can set PWD above variable value as per your need and navigate to that path, this will help in case of script is running from Cron.
user_path=$(echo "$path_details" | awk 'match($0,/.*\//){print substr($0,RSTART,RLENGTH)}') ##Now getting path details from passed 2nd argument for script.
if [[ -d "$user_path" ]] ##Checking if user_path(path value is existing on system)
then
echo "Present path $user_path."
##Call your program here....## ##If path existing then call your program.
else ##If path NOT existing then exit from program or print message up to you :)
echo "NOT present path $user_path."
##Can exit from here. if needed.##
fi ##Closing if condition here.
i am writting a script and i need to get a number out of the shell command output. The command & its return is
$ git branch -a -v --no-abbrev --contains $(git rev-parse HEAD)
* (HEAD detached at c5246b6) c5246b6907e46795741853852462914e7a5f60de Merge pull request 1166 from testPR into dev
remotes/origin-pull/1166/merge c5246b6907e46795741853852462914e7a5f60de Merge pull request 1166 from testPR into dev
i am trying to extract the 1166 out of the result by using sed over the piped result. Something like
$ git branch -a -v --no-abbrev --contains $(git rev-parse HEAD) | sed <pattern>
to get the 1166
My patterns so far doesn't seem to get the number i am expecting.
I seems that you're trying to extract the part of your remote branch name between last 2 slashes. And you may use grep with perl interpreted pattern to achieve that, here you are,
$ git branch ... | grep -oP '[^\/]+(?=\/[^\/]+$)'
1166
Brief explanation,
-o: Print only the matched (non-empty) parts
[^\/]+ : grep command would print this part, non-slash pattern
(?=\/[^\/]+$) : matches words ahead of the las slash of the line [^\/]+$
Not the answer to my exact question, but i am able to get what i want by modifying my bash command.
git branch -r -v --no-abbrev --contains $(git rev-parse HEAD) | awk '{print $1}'
This returns: origin-pull/1166/merge , which is what i want
notice the -r in the command, -a will return both local and remote git branch info. This way, i can cheat on the sed pattern again.
I have a config file with this format
foo=bar
fie=boo
..
..
and there is a Makefile, I want to extract a line of config file that have a string 'disk_size' then extract value that is assigned to the variable
this is the line I've used in Makefile
fallocate -l $(shell awk -F= '/disk_size/ { print $2 }' $(conf)) $#
but I receive this error, (the whole line was extracted.)
fallocate -l disk_size=268435456 disk.img
fallocate: invalid length value specified
the awk command work in terminal but it doesn't work in Makefile, why?
tnx
You probably just need to escape the $:
fallocate -l $(shell awk -F= '/disk_size/ { print $$2 }' $(conf)) $#
Make is trying to use the variable $2 rather than passing the string $2 to awk.
If your config file is really this format:
foo = bar
disk_size = 1234
You can directly include it in the Makefile:
# Include configuration file
include $(conf)
target:
fallocate -l $(disk_size)
You can also use the - operator to ignore error of the include command and assign default value if there is no config file.
# Include configuration file
-include $(conf)
# Set default size
disk_size ?= 5678
target:
fallocate -l $(disk_size)
I'm using Ghostscript library API (wrapping from C#) to print PDF documents from my application.
With the '-dFirstPage' and '-dLastPage' parameters I'm able to select an range of pages to be printed, but how about the total number of a PDF's pages?
It is not very nice to allow a user to select a page interval from 2 to 10 when, let me say, the PDF document has only 4 pages.
Consider that I'm using Ghostscript library through the gsapi_init_with_args API library call.
Ghostscript can count and display the number of pages of a PDF on stdout. The commandline is
gswin32c ^
-q ^
-dNODISPLAY ^
-c "(input.pdf) (r) file runpdfbegin pdfpagecount = quit"
Here all the -c "..." stuff is a PostScript commandline snippet (using a few GS internal command extensions). And input.pdf is the PDF filename (could also be a full path like (c:/path/to/my.pdf)).
However, a better and faster tool for this kind of job would be to use pdfinfo (part of the XPDF-utilities, also available on Windows).
Update:
#ebyrob wants to know if one can modify my example command line so that it also displays the PDF in a single operation. Try this:
gswin32c ^
-q ^
-c "(input.pdf) (r) file runpdfbegin pdfpagecount =" ^
-f input.pdf
Well, it's not a single operation -- it's just two different operations in a single commandline.
For people having issues in ghostscript >9.50 add --permit-file-read=input.pdf
I tried to make this script:
gswin32c ^
-q ^
-c "(input.pdf) (r) file runpdfbegin pdfpagecount =" ^
-f input.pdf
work in a c# wrapped solution and kept getting error "/undefinedfilename". In this case ensure that your filepath has Slashes "/" as DirectorySeperator and not Backslashes "\". I know Kurt Pfeifle already wrote it, but it happened to me i just overlooked it.
In Windows systems:
"path to gs exec" -q -dNODISPLAY -dNOSAFER --permit-file-read="path to
your file" -c "(""path to your file"") (r) file runpdfbegin
pdfpagecount = quit"
Remarks:
Just change where is 'path to...' with your path, leave the rest as is.
On the -c path you must use double slashes or unix like ones. Ex: C:\\youfile.pdf (good), C:/youfile.pdf (good), C:\yourfile.pdf (bad).
Example:
path: C:\Temp\Some Folder\myFile.pdf
gs path: C:\Temp\Some Folder\gs\bin\gswin64c.exe
path -c 1: C:\\Temp\\Some Folder\\myFile.pdf
path -c 2: C:/Temp/Some Folder/myFile.pdf
Commands:
"C:\Temp\Some Folder\gs\bin\gswin64c.exe" -q -dNODISPLAY -dNOSAFER --permit-file-read="C:\Temp\Some Folder\myFile.pdf" -c "(""C:\\Temp\\Some Folder\\myFile.pdf"") (r) file runpdfbegin pdfpagecount = quit"
"C:\Temp\Some Folder\gs\bin\gswin64c.exe" -q -dNODISPLAY -dNOSAFER --permit-file-read="C:\Temp\Some Folder\myFile.pdf" -c "(""C:/Temp/Some Folder/myFile.pdf"") (r) file runpdfbegin pdfpagecount = quit"
To sum up some of the above separate comments for windows users to avoid needing to alter between / and \\ , to show the total number of pages can be set as a shortcut for drag and drop or "sendTo", by first switching to a working directory.
#echo off & cd /d "%~dp1" & "C:\path to gs\bin\gs.exe" -q --permit-file-read="%~nx1" -c "(%~nx1) (r) file runpdfbegin pdfpagecount = quit" & pause
where gs.exe is one of the windows c(onsole) variants gswin32c.exe or gswin64c.exe
The cd /c "%~dp1" will switch console to quoted file drive path
The full quoted path to "GSwin..c.exe" calls it safely and remotely
-q will suppress (not show) the start message
since version 9.5+ the --permit-file-read="file name" is advised / required
-c "(%~nx1) does not need the quotes for name.xtension
if running a cmd as a shortcut, pause is required to see the result
beware only use on files you trust as your overriding GS -dSAFER restrictions.