wp cli output format with –porcelain

wp db export

Will output something like Succes: Exported to 'dbname-2018-09-16-2790c11.sql'
Often you need the filename.

--porcelain flag to the rescue!

wp db export --porcelain
dbname-2018-09-16-2790c11.sql

This will work on a lot of commands that have one item output.
Stuff like wp post create ....
Here is a complete list of commands that have the –porcelain flag

Commands that output more items usually have a --format flag to handle output.

Copy files/folders over ssh

Sometimes you just want to copy files from a remote server, and you want it often and quick. Stuff like a DB dump.
You could startup your (s)ftp client and browse to it. Or you could just grap it with ssh.

Download one file

scp -user@hostname.com:/full/path/to/dump.xml /local/path/to/Downloads

Download a whole folder

scp -r user@hostname.com:/full/path/to/folder /local/path/to/Downloads

Bash edit command

I like doing a lot in one command. Downside it that stuff can get messy. One big line. you can’t easily edit it.
A shortcut to make it easier is ctrl-x e That will open the current command in an editor.

Few thinks to keep in mind.

  • Multiple lines will work, but it will execute it as separate commands.
  • using && at the end of lines will fix that.
  • Which of course means you get it in the history at full.
    My main use to chain commands.

Bash argument set

Check if a bash argument is set in a script

File varcheck.sh

#!/usr/bin/env bash

if [ ! -z ${1+x} ]; then
    echo "var is set to '$1'";
else
    echo "var is unset";
fi

varcheck.sh will output: var is unset varcheck.sh TADA will output: var is set to 'TADA'

Nginx change default user

Default nginx runs on the user www, www-data of something alike.

You can change it. Be sure that you are aware of the security risks!
Don’t change it to a user that has access to sudo!

In /etc/nginx/nginx.conf on line #1 change the user.

#user www-data;
user deployment;

And change the user for php-fpm (If you’re using php-fpm đŸ˜‰)

Create a file in /etc/php/7.2/fpm/pool.d/ (check the php version)
I suggest something like zzz-custom-user.conf so it’s loaded last. To that file add.

user = deployment
group = deployment
listen.owner = deployment
listen.group = deployment

Next reload everything, agian check php version.

sudo nginx -t && sudo service php7.2-fpm restart && sudo service nginx restart

Finally change the owner of the webfiles

sudo chown pi:pi /var/www/ -R

All done.

reapplying a reverted commit

So I made a booboo and already pushed a merge commit.
The merged branch had a few commits that where not ready for develop.
After reverting the merge one commit needed to be reapplied.
But a merge wont work, because it already is merged (and reverted).
What you can do is a cherry pick.

How I created the problem

git merge branch
git push origin develop

Here there was no way back, accept rebasing but that’s also not very easy.

How I solved it.

git revert eaf8c471 -m2
git cherry-pick fa9a6b0

Cherry pick just straight up applies the changes made in the files.
Where a merge applies the git changes.

Keep in mind this will only help if you need a handfull of commits reapplied. Otherwise you will need to find an otherway.
Or cherry pick a lot…