Saturday, September 12, 2015

Highlighting bash prompt and adding GIT branch

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

At the beginning we need to get git-prompt.sh script to be able to paste GIT branch name of current GIT directory.

curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -o ~/.git-prompt.sh

Now we are ready to colorize out prompt and add GIT branch.

# -- Set up prompt --
# load GIT-Prompt scripts
. /home/vagrant/git-prompt.sh

PS1=''
# show '>>' in RED to unsuccessful commands
PS1=${PS1}'\[`[ $? = 0 ] && F=2 || F=1; tput setaf $F`\]>>'
# show username and hostname, show in RED for ROOT user
PS1=${PS1}'\[`[ \u = 'root' ] && X=1 || X=2; tput setaf $X; echo $F`\]\u\[`tput setaf 2`\]@\h\[`tput sgr0`\]:'
# show current path
PS1=${PS1}'\[`tput setaf 3`\]$PWD\[`tput sgr0`\]'
# add GIT branch
PS1=${PS1}'\[`tput setaf 6`\]'"\$(__git_ps1)"'\[`tput sgr0`\]'
# tail, make command line on the next line and symbol $
PS1=${PS1}'\n\$ '

export PS1 # Share PS1 for sudo mode

For now, we need to load .git-prompt.sh also for root user because it will try to load GIT branchAdd new line 
    . /home/vagrant/.git-prompt.sh 
into /root/.bashrc.

$ sudo nano /root/.bashrc

Result:
>>vagrant@redbox:/web/opal.cc (develop)
$ badcommand
-bash: badcommand: command not found
>>vagrant@redbox:/web/opal.cc (develop)
$

In sudo -s mode:
>>root@redbox:/web/opal.cc (develop)
# badcommand
-bash: badcommand: command not found
>>root@redbox:/web/opal.cc (develop)
#

I have vagrant user. You may have different name that's why you will have different path like /home/vagrant.

Possibly you will be interested in to consider more dynamic GIT prompt scripts by link:
https://github.com/magicmonty/bash-git-prompt

References:
How to: Change / Setup bash custom prompt (PS1)
Example on stackoverflow
Put Your Git Branch in Your Bash Prompt

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.

Thursday, December 6, 2012

FreeBSD - Upgrade PHP version. Trouble with install pkgconf-0.8.9 from pkg-config-0.25_1

I got an error when try update PHP from 5.3.6 to latest 5.3.x.
===> Installing for pkgconf-0.8.9

 ===> pkgconf-0.8.9 conflicts with installed package(s):
 pkg-config-0.25_1

 They install files into the same place.
 Please remove them first with pkg_delete(1).
 *** Error code 1

 Stop in /usr/ports/devel/pkgconf.
 *** Error code 1

 Stop in /usr/ports/lang/php5.

In previous time I updated ports.
So, it happens because port got some updates which you can see in /usr/ports/UPDATING
It say:
AFFECTS: users of devel/pkg-config
  AUTHOR: bapt@FreeBSD.org

  devel/pkg-config has been replaced by devel/pkgconf

  # portmaster -o devel/pkgconf devel/pkg-config
  or
  # portupgrade -fo devel/pkgconf pkg-config-\*

  pkgng:
  # pkg set -o devel/pkg-config:devel/pkgconf
  # pkg install -f devel/pkgconf
I chose portmaster -o devel/pkgconf devel/pkg-config and updated relation. Further it try to install PHP again.

I found this solution from forum.