Categories
OSX

Git Completion with Terminal/iTerm output theme

Install Git Completion:

Save the git-completion.bash file in your home directory:

Installation

Open your .bash_profile

nano ~/.bash_profile

Paste the following at the top of the file, make sure not to overwrite any other settings you may have put in the file.

###### GIT COMPLETION - START ######
parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/'
}

# Colour Variables
BLACK="\[\033[0;30m\]"
BLACKBOLD="\[\033[1;30m\]"
RED="\[\033[0;31m\]"
REDBOLD="\[\033[1;31m\]"
GREEN="\[\033[0;32m\]"
GREENBOLD="\[\033[1;32m\]"
YELLOW="\[\033[0;33m\]"
YELLOWBOLD="\[\033[1;33m\]"
BLUE="\[\033[0;34m\]"
BLUEBOLD="\[\033[1;34m\]"
PURPLE="\[\033[0;35m\]"
PURPLEBOLD="\[\033[1;35m\]"
CYAN="\[\033[0;36m\]"
CYANBOLD="\[\033[1;36m\]"
WHITE="\[\033[0;37m\]"
WHITEBOLD="\[\033[1;37m\]"
RESETCOLOR="\[\e[00m\]"
LIME_YELLOW=$(tput setaf 190)
POWDER_BLUE=$(tput setaf 153)


# Define the terminal output string: username in path - branch
export PS1="${REDBOLD}\u ${RESETCOLOR}in ${CYANBOLD}\w ${GREEN}-\$(parse_git_branch)${RESETCOLOR} $ "


# Include the git completion file (must be saved in your home directory for this to work)
# Source: https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
if [ -f ~/.git-completion.bash ]; then
 . ~/.git-completion.bash


 # Add git completion to aliases
 __git_complete gco _git_checkout
 __git_complete gb _git_branch
 __git_complete gc _git_commit
fi
###### GIT COMPLETION - END ######

Reload .bash_profile

source ~/.bash_profile
Categories
OSX Web Development

Simpler way of adding intl.so for CakePHP3 on OSX with Mamp

In a Nutshell we just need to do get the full binary package of PHP and install it on OSX, this version comes with intl.so, and we will copy it out of its install directory and drop it into our PHP version.

Get & Install the Binary Package

This website provides the packages so we just pick the version we want to use and run their install script: https://php-osx.liip.ch/

curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6

This would install php 5.6 and we we can copy the intl.so file out of the install directory and drop it in our PHP folder.

PHP 5.6.31:

cp /usr/local/php5-5.6.31-20170817-164511/lib/php/extensions/no-debug-non-zts-20131226/intl.so /Applications/MAMP/bin/php/php5.6.31/lib/php/extensions/no-debug-non-zts-20131226

In this example I am using Mamp so I should drop it into the extensions/no-debug-non-zts-20131226 folder of my PHP version.  These are the same version of PHP so the path should be the same, its just that Mamp holds its PHP binary files in the MAMP app.

PHP 7.3.8:

cp /usr/local/php5-7.3.8-20190811-205217/lib/php/extensions/no-debug-non-zts-20180731/intl.so /Applications/MAMP/bin/php/php7.3.8/lib/php/extensions/no-debug-non-zts-20180731/

 

Enable the extension

Find the php.ini file for the version of php you want to use in my case I was using php5.6.31 (you can tell from copy/paste terminal line), and under “Extensions” add the line:

extension=intl.so

And restart Mamp, and your extension should now be installed!

Set PHP version for Terminal – Required for CakePHP / Composer based installs

Frustratingly, terminal often runs a different version of PHP when installing with composer, so for example, CakePHP refuses to install because its running a version of PHP that doesn’t have intl.so. installed.  Check your version of PHP in terminal by typing:

php -v

if it is a different version that the one you want, set the correct one by using an alias in your .bashrc file.

sudo nano ~/.bashrc

Add the line (Replace php path with your path):

alias php="/Applications/MAMP/bin/php/php5.6.31/bin/php"

Then finally reload your bashrc file with:

source ~/.bashrc

You also may need to use this guide to include the php version to terminal if the above doesn’t work: https://stackoverflow.com/questions/30941506/sqlstate-hy000-2002-while-running-bake-command

Sources:

Categories
OSX Web Development

Install ext-intl on Mac OSX using homebrew and XAMPP

This was a painful process for me, it took quite a while to figure out why such a simple implementation when using ubuntu, can be so much work in a Mac.

We can’t just install the extension with apt-get like ubuntu, and its not already waiting to be uncommented like in windows, we have to install the the shared object intl.so our selves.  and the easiest way of doing this is by using homebrew and pecl.

Step 1 – Install Homebrew

Homebrew Website: http://brew.sh

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Step 2 – Install Install icu4c

ICU4C Website: http://site.icu-project.org

brew install icu4c

Step 3 – Install Autoconf

More about Autoconf: http://brewformulas.org/Autoconf

brew install autoconf

Step 4 – Install Intl via PECL

PECL Website: https://pecl.php.net

sudo pecl update-channels
sudo pecl install intl

Step 5 – Enable intl.so in php.ini

Go to your php.ini file and at the end, add the following line:

extension=intl.so

This will enable the extension that we have just installed.

Step 6 – Restart your server

Use XAMPP to restart your server, this will reload the php.ini file with the new configuration.

Step 7 – Check it worked!

You can check if Intl was installed successfully by using the following command to list the loaded php modules.  If ‘intl‘ it is listed then it has been successfully loaded.

php -m

I am running php via Terminal and it didn’t work?

One common problem is that terminal is using the the wrong version of php, sometimes a system default is loaded rather than the php version you are using in XAMPP.  First lets check what version we are using:

which php

If you are using XAMPP correctly it should return:

  • /Applications/XAMPP/xamppfiles/bin/php 

If not and it loads from:

  • /usr/bin/php

Then we can temporarily change the path of the default php version to the XAMPP version by running the following in terminal:

PATH="/Applications/XAMPP/xamppfiles/bin:${PATH}"

Now if you run “which php” in terminal again you should get the correct path.