Category: Shell

Httpie – a HTTP client not only for the terminal

Httpie – a HTTP client not only for the terminal

Software developers work a lot with REST endpoints nowadays. Sometimes we consume some endpoint exposed by some server and sometimes we create a new REST endpoint. In both cases you need to send a request to the endpoint and see what it returns.

I have been using different HTTP clients like Postman or Insomnia and they were OK. But when it comes to calling an endpoint from a terminal there was only one option: a curl command. Unfortunately it has not intuitive and verbose command line arguments so I am not a fan of it.

There I a very cool alternative and it is called httpie (httpie.io/cli). It comes with a handy http command and it is really easy to use.

Continue reading “Httpie – a HTTP client not only for the terminal”

Tldr – quick help for console commands

Most of the time I use applications with graphical interface but sometimes I still use console tools. They are often faster and more reliable. In some cases there are no alternatives to some command line tools or simply there is no graphical interface available. The problem is that I always forget how to invoke some specific commands.

In that situations I check man pages or simply google it. There is a small utility called tldr that can display only short documentation (in contrast to man pages) with examples how to use given command. To install this tool use brew formula.

Continue reading “Tldr – quick help for console commands”

Show git branch name in bash command prompt

I work with git command in terminal a lot and I often forget what branch I was working on. Running command git branch often is not very convenient I needed to put git branch in command prompt when I was inside git repository.

I wanted my console to look like this:

eanlr@vps some-repository (master) $ 

To get that you need to add following lines to your .bash_profile file in your home directory:

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

export PS1="\u@\h \W[\033[32m]$(parse_git_branch)[\033[00m] $ "

You can of course customize command prompt by changing PS1 variable.

Slow shell startup with Node Version Manager (NVM)

While I was working with some frontend projects I used node and npm tools. The problem is that each projects requires different version of those tools so you need something to manage various versions and switch on demand. Node version manager (nvm) is a great tool for that purpose and I was very satisfied with it.

Unfortunatelly after installing nvm my shell startup became quite slow and it was irritating when I opened new terminal tab. It turned out nvm was responsible for that. As i use frontend tools not very often I decided to load nvm on demand.

I changed a fragment responsible for nvm in my .bash_profile file from this:

. "/usr/local/opt/nvm/nvm.sh"

To that:

load_nvm() {
  . "/usr/local/opt/nvm/nvm.sh"
}

Now when I need node and npm tools i simply run load_nvm and my shell is ready for javascript development.

eanlr@vps ~ $ load_nvm
eanlr@vps ~ $ node -v
v8.9.4