InfoQ Homepage Articles The Best CLI Is the One You Don’t Have to Install

# The Best CLI Is the One You Don’t Have to Install

This item in chinese

### Key Takeaways

• Azure Cloud Shell is a full terminal in your browser
• You can configure the cloud shell just like you would your local terminal
• You can use vim, emacs and even a slimmed down VS Code experience in the Cloud Shell
• Your browser sends commands to an actual Unbuntu terminal instance in the background
• Cloud Shell allows you to use the Azure CLI without having to install anything

The other day a friend of mine was deploying some Node things to Azure, and his site wasn’t working. I generously offered to help, because I never pass up an opportunity to reassure myself that I’m not a terrible person.

He was getting a "Service Unavailable" error, which is my favorite error (heavy sarcasm alert) to get because it means nothing. Nothing at all. The error might as well just be "cheese on toast".

In order to find the actual error, I needed to get to the logs. At this point I was about to ask my friend if he had the Azure CLI installed, and I realized that if he didn’t, it could get kind of messy.

Is he on a Mac or Windows? Does he have Homebrew? What about his Python version? OMG THE PYTHON VERSION.

Things we already a bit tense and I didn't want to add to that by saying, "Oh and install this CLI so we can read a log file".

Then I realized that we didn’t have to do any of that. You don’t have to install the Azure CLI to use it. All you need, is the Azure Cloud Shell.

## Azure Cloud Shell

The "Cloud Shell" is an embedded terminal in your browser. There are a few different ways to access it. If you’re in the Azure Portal you can just click the little icon next to the bell.

This pops up a new terminal window with the Azure CLI already installed. No sign-in required.

Another option is to go to shell.azure.com.

You can also get to it in VS Code if you have the Azure Account extension installed. Just open the Command Palette and look for "Cloud Shell".

"Yes", I am using a light editor theme. "No", I don’t care that is ruining my eyeballs and "Yes", I like the band "Owl City". That last one isn’t really related to my love of light editor themes. OR IS IT?

Once we have a Cloud Shell instance, it’s easy to look at the logs. There is no sign in process so you just start typing your Azure CLI commands all willy-nilly as if you’re an old pro. I was trivial for us to access the streaming logs for his site and see that he had left out an npm package in his dependencies. Isn’t that always the problem with every Node app?

Now this wasn’t the first time I saw the Cloud Shell, but it was the first time that I understood its awesomeness.
The very first time I saw it, I thought …

I didn’t get it. I mean, I already have a terminal. I kind of like it. It’s rolling a nice Flat UI theme and I’ve spent a non-trivial amount time tweaking it in ways that I can’t possibly even remember nor can I even find all of the different profiles. Is it ~/.bashrc, or ~/.zshrc? And what the heck even is the ~/.bash_profile and why do I need that if I have the ~/bashrc? Life has no meaning.

Cloud Shell is awesome - not because it replaces your terminal, but because it gives you access to a CLI and you don’t have to install it.

We tend to install a lot of CLI’s, and they can be tricky to configure. I’ve spent more time than I would care to admit fighting with Ruby and Python versions all in the name of installing some CLI that has absolutely nothing to do with either Python or Ruby. That’s a trip to crazy town that I would rather not take.

The Azure Cloud Shell is giving you that CLI with zero commitments or configuration on your part. What version of Python do you have? WHO CARES. You have the Cloud Shell. And I obviously have some Python runtime PTSD.

Cloud Terminals abound though. Azure definitely isn’t the only one out there. What I immediately became interested in, is, outside of the Azure CLI, how much of an actual "terminal" is this? What can I do?

Let’s find out.

## vim

The first thing we have to know is can it do vim?

[Click on the image to enlarge it]

Yes. Yes it can. And it comes with all of VIM’s great easter eggs.

[Click on the image to enlarge it]

As John Oliver would say, "Cool".

Next we need to know if we can install things. And by "things", I mean "cowsay".

## apt-get

It won’t be a terminal without my cow, so I tried to install cowsay.

No sudo! But the docs do say that root access is disabled. Which I guess is to keep people like me from cluttering these servers with garbage and accidentally deleting system files.

Well crap. That’s kind of a bummer. But I’m not deterred. Let’s see if emacs is in the house …

[Click on the image to enlarge it]

In. The. House. Not that I would ever use emacs mind you, but how else am I going to play Snake? Speaking of which, can we still play Snake in emacs?

I’m the world’s worst snake player. That game sends my anxiety through the roof. I’m more of a Super Mario guy. Can we get that as an emacs game?

OK - enough futzing around here. Let’s get down to seeing if we can customize this thing. There are somethings we are going to need in the terminal to get the most out of the Azure CLI. Starting with changing the shell to zsh.

## zsh

We already know that we can’t install anything, but what if I zsh is already here? Let’s just run it and find out.

YES! Hahahaha yes. Now can we add oh-my-zsh? It’s just dot files so the curl install should do it.

[Click on the image to enlarge it]

Now we’re getting somewhere. Can we change the theme? Let’s go with "cloud". It seems appropriate here.

// .zshrc file
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="cloud"

[Click on the image to enlarge it]

Pretty. I like it. It’s not a light theme, but I dig the tiny cloud.

I should note that Cloud Shell has trouble with some themes. For instance, it doesn’t seem to like to render the chevrons in the super popular "Agnoster" theme …

[Click on the image to enlarge it]

In case you’re wondering, Agnoster is supposed to look like this …

No problem, I don’t use Agnoster anyway. Now let’s do some plugins. One that I use a LOT is called "zsh_autosuggestions. Jessica Deen showed me this one and it basically just tracks everything that you enter into the terminal, and then puts ghost characters up if you are typing something you have typed before. Like this …

[Click on the image to enlarge it]

The zsh-autosuggestions plugin is not in the list of oh-my-zsh plugins, so the manual install works just fine …

git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions

And then add to your ~/.zshrc file …

source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh

I also took the liberty of installing git, jsontools, and a bunch of others. All of them worked.

[Click on the image to enlarge it]

Now let’s set zsh as our default shell. Normally this is done by just installing zsh, but it’s already installed. We also can’t do the normal chsh business because we don’t have permissions to do that either.

Shayne Boyer pointed out that a simple setting of the SHELL in your ~/.bashrc does the trick. Since the Cloud Shell is the same for everyone, your zsh should be in the exact same place as mine.

export SHELL=/usr/bin/zsh
exec /usr/bin/zsh -ld

Now we startup in ZSH with our theme and all of the plugins by default. Even when opening in VS Code. The settings follow us around anyplace we are using Cloud Shell.

## npm

As a JavaScript developer, I’ve gotta have my Node. It didn’t surprise me to find Node in the terminal by default. But what did rock my socks was that npm is installed by default as well.

BUT THAT’S NOT ALL.

The docs also boast support for make, maven, and pip. Java developers will probably be happy with that last sentence. I’m not a huge make or pip user. I usually only use those when I’m copying and pasting something from Stack Overflow into my terminal.

## How is this working?

Every time you open a Cloud Shell instance, under the covers you get a Docker container with Ubuntu running inside. The Cloud Shell then connects to that instance via a web socket and becomes the interface for your full-on Ubuntu container.

For instance, if type "Docker" into the Cloud Shell, here is what gets passed back to the container on the server …

[Click on the image to enlarge it]

Do you see it? That’s "d" "o" "c" "k" "e" "r" (the green arrows are outgoing). Notice that the web socket is also responding after each one of my key presses (red arrows are incoming). Because that’s exactly what a terminal would do. See how it’s responding with "[39m" and then the letter I just passed in? That’s ANSI syntax highlighting. That’s how Cloud Shell knows what color to display the text. This is why it can do themes and other highlighting.

Once the command executes, it sends back the terminal output from the container.

[Click on the image to enlarge it]

And back and forth we go as I type characters into the Cloud Shell and they are sent over the wire, executed on a terminal and then back to me.

This is a pretty remarkable feat when you think about it. They have turned the browser into a character-for-character UI for an actual terminal running somewhere else.

The Cloud Shell persists storage using Azure Storage. All of our profiles and any files that we work with get stored in that storage which is mounted by the underlying Ubuntu container.

## THIS JUST IN

After writing this article and waiting for some time to publish it, it looks like the Cloud Shell has not waited on my article to add a new and rather "baller" feature.

You can now get a VS-Code-Like editor by typing code in the shell. The editor pops open above the terminal. I say "VS Code Like" because it’s clearly the text editor from VS Code - complete with things like Find & Replace and multiple cursors and a command palette (F1).

[Click on the image to enlarge it]

Vim is not for everyone. And by everyone, I mean ME. So for the rest of us there is now this nifty visual editor which I have called VS Code even though it is NOT VS Code.

I can even figure out how to close it. Take that, Vim users.

[Click on the image to enlarge it]

## Get more Cloud Shell

Cloud CLI’s are necessary, but a pain to install. The Cloud Shell gives you the full power of a CLI and a pretty beefy terminal experience to boot, and all you need is a browser tab.

You can find the Cloud Shell in the Azure Docs, as well as the Azure Mobile app. You can also find a full list of all features supported in Azure Cloud Shell.

Burke Holland is a front-end developer living in Nashville, TN; the greatest city in the world. He enjoys JavaScript a lot because it’s the only way he Node to Express himself. Get it? Never mind. Burke blogs only slightly better than he codes and definitely not as good as he talks about himself in the third person. Burke works on the Azure team at Microsoft on behalf of JavaScript developers everywhere. You can find him on Twitter as @burkeholland.

Style

## Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

by 王 堃澎 /

• ##### very cool!

by 王 堃澎 /

Your message is awaiting moderation. Thank you for participating in the discussion.

very cool!

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.