Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wp-cli works in windows cmd, but not in Gitbash

I've installed the wp-cli using Git-bash, created the relevant PATH variables.

I am now able type 'wp' into the Windows CMD and it works, but Git-bash doesn't recognize the command.

What must I do get this working with Git-bash, and why doesn't it work out of the box?

like image 232
SGouws Avatar asked Jul 26 '17 10:07

SGouws


1 Answers

I run into the same issue. For example command "wp cli version" is working in cmd but not in cygwin.

Check following tutorial: https://deluxeblogtips.com/install-wp-cli-windows/

If you are using cygwin, you will need to create another wp file (without .bat) extension. Just name it wp with following content:

#!/usr/bin/env sh

dir=$(d=${0%[/\\]*}; cd "$d"; pwd)

# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
    # Cygwin paths start with /cygdrive/ which will break windows PHP,
    # so we need to translate the dir path to windows format. However
    # we could be using cygwin PHP which does not require this, so we
    # test if the path to PHP starts with /cygdrive/ rather than /usr/bin
    if [[ $(which php) == /cygdrive/* ]]; then
        dir=$(cygpath -m $dir);
    fi
fi

dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/wp-cli.phar" "$@"
like image 115
Philipp Avatar answered Oct 12 '22 15:10

Philipp