Bash

Use Windows 10 home folder as WSL Ubuntu shell home directory

WSL-Ubuntu

As I moved on professionally and started to develop dotnet applications for Windows I had to switch my OS from MacOSX to Windows (I still use MacOSX for other stuff). So this change forced me to adapt to a new environment – or better, to go back to a previous one – anyway, I still miss my shell and all it’s features.

Fortunately, Windows 10 can run a WSL and I can use the Ubuntu shell as my main one. If you use a shell regularly you probably often use the commands: cd or the shortcut ~/Downloads for example, and that is a problem because the WSL Shell home is located, in my case, at /home/walter and my user (windows) home is at C:/Users/Walter (/mnt/c/Users/Walter) so: how can I change my default home shell so I can use the home shell directory as the same as the OS home directory?

Quite easy, open a new shell and type:

1
sudo vim /etc/passwd

Search for your username, must look something like that:

1
walter:x:1000:1000:,,,:/home/walter:/bin/bash

and change your home directory /home/walter to the one that you want to use, in my case I changed it to /mnt/c/Users/Walter

1
walter:x:1000:1000:,,,:/mnt/c/Users/Walter:/bin/bash

save and exit vim.

You can copy your user definition

1
cp /home/walter/.bash* /home/walter/.profile /mnt/c/Users/Walter/

Close and re-open the shell and you’re good to go.

Composer update creates a lack of memory

While using Symfony 2 it’s common that you have to run the command composer update. Sometimes we’re graced with the error:

1
2
3
4
5
6
7
8
9
10
The following exception is caused by a lack of memory and not having swap configured

PHP Fatal error:  Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:954
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', 'phar:///usr/loc...', 954, Array)
#1 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(954): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(754): Symfony\Component\Console\Application->getSttyColumns()
#3 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(715): Symfony\Component\Console\Application->getTerminalDimensions()
#4 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(648): Symfony\Component\Console\Application->getTerminalWidth()
#5 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(130): Symfony\Component\Console\Application->renderException(Object(ErrorException),  in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php on line 954

The easiest way to fix it it’s by creating a virtual swap partition using the following commands:

1
2
3
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1

Unix bash aliases

Well, I’m a little bored by, every time I change my system I have to update my aliases. So here it goes some alias that can be really useful. I gonna use this page to save all my aliases.

Both systems .bash_aliases:

1
2
3
4
alias duh ='du -h -d1'
alias ll  ='ls -lA --color'
alias l   ='ls -FhsSA1'
alias gpa ='for r in $(git remote); do git push $r master; done';

Linux .bash_aliases:

1
alias print ='echo -e'

MacOSX .bash_aliases:

1
alias print ='echo'

Linux .bash_colors:

1
2
3
4
RED   ='e[1;31m'
CYAN  ='e[1;36m'
GREEN ='e[1;32m'
NC    ='e[0m' # No Color

MacOSX .bash_colors:

1
2
3
4
RED   ='x1B[1;31m'
CYAN  ='x1B[1;36m'
GREEN ='x1B[1;32m'
NC    ='x1B[0m' # No Color