COOKIES! This blog uses cookies!
I am completely out of control of cookies here, otherwise I would have disabled them (it is controlled by the platform).
If you don't like cookies and being tracked please leave this blog immediately.

Showing posts with label command line. Show all posts
Showing posts with label command line. Show all posts

Monday, 30 May 2016

Produce html diff with diff2html-cli

It is handy to do with one nice JavaScript tool, which works on any platform:
https://www.npmjs.com/package/diff2html-cli

> npm install diff2html-cli
> diff -u fileA.txt fileB.txt | diff2html -F diff.html -i stdin


It is important to have -u option for diff command you pipe into diff2html, because it produces unified diff and diff2html expects unified diff.

It is also possible to do these two commands separatedly, without piping:

Write diff of a and b into a-b.diff file:
> diff -u a.txt b.txt > a-b.diff

Produce HTML file from the diff file:
> diff2html -F a-b.html -i file -- a-b.diff

Tuesday, 24 November 2015

Decrypting and encrypting messages with gpg in linux (ubuntu)

Encrypting and decrypting files with gpg tool is quite easy:
>gpg --recipient Ben --encrypt test.txt
>gpg --decrypt test.txt.gpg

But if you don't want to create a file and just need to encrypt or decrypt a message quickly?

This workflow will work

Encrypt with your gpg key for some known recipient:
>gpg --armor --encrypt --recipient bend
It might prompt you to type a password for your key at this stage.
Now type your message in and here goes the tick: press CTRL+D, which means the end of a input!
After that it will print your encrypted message into standard output.
Shortcut for the command above:
>gpg --aer bend

Encrypt symmetrically with some passphrase:
>gpg --armor --symmetric
It will prompt you to type a passphrase for symmetric encryption
Now type your message in and press CTRL+D
Shortcut:
>gpg -ac

Decrypt some pgp message:
>gpg --decrypt
Paste your pgp message, for example:
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1

jA0EAwMC1c4w0+3hgT9gySDDFx7lNx0Jwf3aGOwQ8yQc6KKWjnew6LkdtEg3mhOS
bQ==
=7kxT
-----END PGP MESSAGE-----
Type your passphrase (for example 123 for this symmetric message) or a password to your gpg key if it is encrypted for you as a recipient.
And again press CTRL+D to see decrypted message.

Friday, 16 May 2014

copy all GIT diff files on windows

Windows CMD one-line command to copy difference of two GIT commits into specific directory preserving directories hierarchy:

git diff --name-only yrc0m1 yrc0m2|sed s:/:\\:g > report.txt && for /F %F in ('cat report.txt') do xcopy %F c:\m1m2diff\%F && del report.txt

*xcopy will ask you to confirm wither the path is file or directory for each of your changed files. As far as diff returns only files changed, you can just do long F button press :-) Unfortunately I did not succeed to find a flag to suppress this warning with F option.

It consists of following subcommands:
1. git diff --name-only yrc0m1 yrc0m2 - returns list of changed files between commits yrc0m1 and yrc0m2;
2. sed s:/:\\:g - piped with | after previous one, converting Linux slashes to windows slashes;
3. > report.txt - oputput of previous two commands: all relative filepaths are saved in report.txt;
4. for /F %F in ('cat report.txt') do xcopy %F c:\m1m2diff\%F - iterates through lines in report.txt and copying file creating all not-existing directories from it's relative path (we suppose that c:\m1m2diff\ directory already exists)
5. del report.txt - simply deletes report.txt file.