Friday, September 29, 2017

Useful Bash scripts/tools

Sometimes, we may get new environment to work with, and we may feel some lack of tools, or we would like to make some installations faster than we usually do. That's tools like Docker, Vagrant so developed.

I work in command line on my work laptop in Git Bash for Windows or on servers. From time to time, I make some scripts to optimize some actions.

Bash scrips

Install PS1 colorization for Bash (Windows/Unix)

Sources: https://gist.github.com/andkirby/389f18642fc08d1b0711d17978445f2b
Installation:
$ curl -Ls bit.ly/bash-ps1 | bash
$ . ~/.bashrc

.bashrc file initial content

Sources: https://gist.github.com/andkirby/0e2982bee321aa611bc66385dee5f399
Installation:
$  curl -Ls https://bit.ly/bash-init | bash
$ . ~/.bashrc

Install PHP binaries on Windows in Bash

Sources: https://gist.github.com/andkirby/67e87e319c376b8676d559edb759e3fe
Installation:
$ curl -Ls bit.ly/php-bash-win | bash

Install NodeJs and npm binaries in Bash for Windows

Sources: https://gist.github.com/andkirby/3f65c5a6499739c842e25fb7f6d5e682
Installation:
$ curl -Ls https://gist.github.com/andkirby/3f65c5a6499739c842e25fb7f6d5e682/raw/node-npm-git-bash-win.sh | bash

Slack Message Sender

Sources: https://gist.github.com/andkirby/67a774513215d7ba06384186dd441d9e
Installation:
$ curl -s https://gist.githubusercontent.com/andkirby/67a774513215d7ba06384186dd441d9e/raw --output /usr/bin/slack
$ chmod +x /usr/bin/slack

Install colors for nano editor

Sources: https://gist.github.com/andkirby/65607ce983c3a732ff94cc2ce4220b6d
Installation:
$ curl -Ls https://gist.githubusercontent.com/andkirby/65607ce983c3a732ff94cc2ce4220b6d/raw | bash -s -- $(cd; pwd)

SemVer sorting using Bash

Sources: https://github.com/rikby/semversort
Installation:
$ curl -Ls https://raw.github.com/rikby/semversort/master/download | bash

sscp - some wrap for scp tool

Sources: https://github.com/rikby/sscp
Installation:
$ curl -Ls https://raw.github.com/rikby/sscp/master/download | bash

xd_swi - PHP Xdebug library switcher

Sources: https://github.com/rikby/xdebug-switcher
Installation:
$ curl -Ls https://raw.github.com/rikby/xdebug-switcher/master/download | bash

Binaries Downloader - tool to download released binaries from GitHub

Sources: https://github.com/rikby/bin-downloader
Lots of my scripts use this tool to make downloading onto a target environment.

Saturday, September 12, 2015

Highlighting bash prompt and adding GIT branch

I like colors in command line. I like any colors! :)
I would like to share my own setting for bash prompt. There is comments that's why you will understand how it works.

But before you start I'd suggest to try this fast way to make it.
You just need to run this online script:

$ curl -L bit.ly/bash-ps1 | bash
$ . ~/.bashrc

That's how it will look like:








Thursday, August 14, 2014

Nginx - Simple dynamic sitemap rewrite configuration

A little note to remember...
The main goal is to create dynamic loading sitemap.xml file from some directory.
At the begining we have locale code. And sitemap file can requested from some directory.
Files should be placed to a particular directory.


location ~ /sitemap.xml|/([a-z][a-z]|[a-z][a-z]-[a-z][a-z])/(.*)sitemap.xml {
    root   /usr/local/www/apache22/data/project/;
    index /sitemap/sitemap.xml;
    try_files /sitemap/$1/$2/sitemap.xml /sitemap/$1/sitemap.xml;
}

Monday, June 23, 2014

Shell - Set GIT command output to variable

Just small note... I tried to make some shell script which works with GIT commands. So, I need to set shell output to some variable.
var=$(git pull)

I cannot do that with such approach. It always show me result.
The answer I found by link.
So we need to add a little change:
var=$(git pull 2>&1)

# or
var=$(git pull > /dev/null 2>&1)
Works!

Tuesday, May 14, 2013

PhpStorm - File - Convert line endings for files inside folder (recursive)

In the past time I've tried find any converter to convert line endings of files (it means a lot of files with one operation). There is plug-in for PhpStorm but it doesn't proper work. I've found one tool which has resolved this issue.
So, website for Swiss File Knife and some tricks related to this topic.

Update for PhpStorm (v6.0.2)

PhpStorm has possibility for batch convert line endings:
Choose folder inside navigator -> Manu File -> Line Separators

Seems in the previous versions this feature wasn't added.

Wednesday, April 17, 2013

GIT - Use global hooks / templates

There is an opportunity to use global hooks. So how you set up it? The configuration option init.templatedir will help us in that.

At first you can check exist value:
git config --global --get-all init.templatedir

If there is exist some you can check it. But if it's empty you can set up it by your path:
git config --global init.templatedir 'c:\Program Files (x86)\Git\share\git-core\templates\'
You may have another path from non-Windows system and in this way this link might help you.
It remains only put you hooks files into hooks directory:
c:\Program Files (x86)\Git\share\git-core\templates\hooks
and run command:
git init
Don't forget you have set up only templates. This templates don't used directly. By the last one command templates will copied to your .git directory. Also exist files cannot be overwritten.  So when you've created new project for copy hooks you have to run git init.

That's all.

Monday, April 8, 2013

PHPStorm - Supporting Factory methods in Magento

I'm pleased to present a new feature in new PhpStorm 6.0.1 EAP build 129.177/196 which supports generic Factory Method pattern.

How to use

So, all is ok but how to generate file .phpstorm.meta.php? We have good tool n98-magerun which can generate our needed file for Magento in the environment of PHPStorm.
So all we need that this command with expected result:

# php n98-magerun.phar dev:ide:phpstorm:meta
Generating definitions for blocks group
Generating definitions for helpers group
Generating definitions for models group
Generating definitions for resource helpers group
Generating definitions for resource models group
File .phpstorm.meta.php generated


That's all. Your IDE is supporting Magento Factory methods now. Also, in theory, this feature works for other libraries.