Using Starship to Track Current NPM Registry
Tags: starship, bash, commandprompt
Published: 2021-06-26 16:34:09

---
title: Using Starship to Track Current NPM Registry
published: true
description: "See which npm registry you're on with a custom command in Starship"
tags: Starship, bash, commandprompt
//cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h9pjn2qdi7n9rm87oyu8.png
---

I will be forever grateful to [Jason Lengstorf](https://www.jason.af/) for introducing me to [Starship](https://starship.rs/)! It's a super fast, highly-customizable shell that comes with some great features out of the box. The default will show you your current directory, branch if you're in a repo, current package version, and current Node version. My setup looks like this:

![Starship customized command prompt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h9pjn2qdi7n9rm87oyu8.png)

As a consultant, and even more so as a DIRECTOR of consultants, I spend my days hopping between client code bases, node versions, internal NPM registries, and my own personal content creation. As someone who never has enough hours in a day, I'm always looking for ways to improve my processes and keep myself from trolling myself unintentionally. 

The number one thing that gets me every time is not realizing when I'm on an internal client NPM registry and try to do an `npm install`.😬 I use [npmrc](https://www.npmjs.com/package/npmrc) to create registry profiles and quickly switch between them, but with my chaotic days I don't usually remember which profile I have set!

Thankfully, you can create custom modules in Starship to customize your command prompt needs! I created a custom module to always show me which registry I'm currently using. 

```toml
// ~/.config/starship.toml

[custom.npmrc]
disabled = false
command = """
NPMREGISTRY=$(command npm config get registry)
if [[ "$NPMREGISTRY" =~ "clientregistrynamespace" ]]; then
    NPMREGISTRY_SYMBOL=""
else
    NPMREGISTRY_SYMBOL=" "
fi
echo "registry $NPMREGISTRY_SYMBOL"
"""
when = "true"
style = "bold blue"
```

If you're not a bash scripting pro (I certainly am NOT), I'll walk you through what's going on here. This is code in my custom config [toml](https://github.com/toml-lang/toml) file for Starship. Most of this configuration is based on how Starship returns information about different Modules, and bash scripting is done in the "command" option. You can see more about how to [configure current Modules](https://starship.rs/config/) or [create your own commands](https://starship.rs/config/#custom-commands) on their website. 

I'm running the command `npm config get registry` and converting the output of the command to a string variable for comparison with the `$`. The command spits out `https://registry.npmjs.org/` or whatever registry you're currently on. A custom registry url might look something like `https://npm.clientregistrynamespace.com`. I'm checking to see if my clients registry name is in the command output - if it is, I'm returning a symbol representing that client, and if it isn't I'm returning an NPM icon from [Nerd Fonts](https://www.nerdfonts.com/cheat-sheet).

![Starship NPM Registry display demo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xftezqpped6774scnr86.gif)

Now I can always see what registry I'm on!

You can see other custom commands built by community members here: [https://github.com/starship/starship/discussions/1252](https://github.com/starship/starship/discussions/1252)