Docker completion for Zsh with Prezto

I am currently using Prezto as the configuration framework for Zsh. Having completion while working with Docker on Terminal can boost our productivity a little bit to focus on what’s more important. So let’s get it configured.

~/.z/m/c/e/src  curl -fLo ~/.zprezto/modules/completion/external/src/_docker https://raw.githubusercontent.com/docker/cli/master/contrib/completion/zsh/_docker
~/.z/m/c/e/src  curl -fLo ~/.zprezto/modules/completion/external/src/_docker-compose https://raw.githubusercontent.com/docker/compose/master/contrib/completion/zsh/_docker-compose
~/.z/m/c/e/src  exec $SHELL -l

Now check if it works.

2017-08-28_101501

Advertisements

zsh cannot execute global npm packages

Today, I installed an npm package globally, no problem here.

Screen Shot 2017-03-11 at 2.01.37 PM.png

But, when I execute the package, there comes an error:

~  yo
zsh: command not found: yo

So, it means that the system doesn’t realize the path to my package. I confirm by using:

~/W/C/htnmaruko  echo $PATH
/Users/duchoang/.rbenv/shims:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin

So that, we need to export the path to where my package is lying in.

Because I installed by -g parameter, so it is lying in global npm. In my case, it is being in ~/.npm-global.

Steps:

1. Export your path in ~/.zshrc (in case of using zsh, otherwise using ~/.bashrc) by  print it to your ~/.zshrc or ~/.bashrc (in case of not using zsh) file:

~/.n/bin  printf "\nexport PATH=\"\$PATH\":%s\n" ~/.npm-global/bin >> ~/.zshrc

Or just editing with vi:

~  vi /Users/duchoang/.zshrc

2. Now, fire up the changes:

~  . ~/.zshrc

3. And finally, the problem gets solved, the result we have:

Screen Shot 2017-03-11 at 2.03.28 PM

Now we can get back to our work.

What to do if your Rails application cannot connect to Mysql?

When I use my Mac to continue developing my Rails application using Mysql as the database system. It first initialized and developed in Ubuntu.

After bundling tasks, I move to rake db:create to initialize my databases for development and test environment. But the problem comes out:

Mysql2::Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

Ok, cd to the

/var/run/mysqld/

Oh, there’s no mysqld.sock there. Ok, so there must be the error as above error message.

So, I was wondering where mysqld.sock is in my computer? I was installed Mysql through brew and able to connect to Mysql by Mysql Workbench with no problem. So let’s see some variables. Enter to the terminal:

mysqladmin -p variables | grep socket

Provide the password, and then you will see something like:

screen-shot-2016-09-24-at-10-16-58-pm

| performance_schema_max_socket_classes                    | 10

| performance_schema_max_socket_instances                  | -1

| socket                                                   | /tmp/mysql.sock|

Wow, there comes in the socket line the mysql.sock file location

We have to connect through it.

After some research, I know that Rails settings the socket in the filedatabase.yml.

So, it’s EZ now, just replace the new found path.

It’s ok now. I can continue my work.

Fixing rbenv not update ruby system (rbenv version different from ruby -v)

Recently, I faced with the problem of not syncing ruby version with my Mac.

My project requires ruby version >= 2.2.2 but default version is 2.0.0.

I haved installed ruby 2.3.1  on my rbenv (ruby version manager) and set it global, but when i bundle install, there comes some error liked:

activesupport-5.0.0 requires ruby version >= 2.2.2, which is incompatible with the current
version, ruby 2.0.0p648

Even rbenv version shows:

2.3.1 (set by /Users/duchoang/.ruby-version)

I checked back with ruby -v, it shows 2.0.0. Oh shit what happened?

I searched and they said that I have to install ruby-build, ok but after that I reallized that it’s not the cause:

brew install rbenv ruby-build

rbenv rehash

I reallized that I’ve switched to zsh, so instead of ~/.bash_profile I need to rerun the following command to ~/.zshrc:

$ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.zshrc
$ source ~/.zshrc

done.

Better color for your Mac Terminal

Run this from terminal:

open ~/.bash_profile

Add these lines to the end:

export TERM="xterm-color" 
export PS1='\[\e[0;33m\]\u\[\e[0m\]@\[\e[0;32m\]\h\[\e[0m\]:\[\e[0;34m\]\w\[\e[0m\]\$ '

Then restart your Terminal to see the changes, now you’re done.

For more customizations, refer to the post: http://osxdaily.com/2012/02/21/add-color-to-the-terminal-in-mac-os-x/

Or, you could try some alternatives:

  • Cathode
  • iTerm2
  • Terminator
  • MacTerm