iac,

Pulumi Stack Name in Bash Prompt

Sven Malvik Sven Malvik Connect Oct 31, 2020 · 1 min read

This post describes how we can add custom information to a bash prompt.

Instead of using features for interacting with GitHub, Azure and my file system from within an IDE, I prefer to use my tools from a terminal. This approach forces me to learn, to understand, and to remember how a tool works. I also want to have certain information visible at all time. Examples are the branch name of a Git project, and the stack name of a Pulumi project. The script below adds those two information to the bash prompt. Put it in the .bashrc or .bash_profile and restart the terminal or read the file with source .bashrc.

# We use tput to define colors
_GREEN=$(tput setaf 2)
_YELLOW=$(tput setaf 3)
_BLUE=$(tput setaf 4)
_RED=$(tput setaf 1)
_RESET=$(tput sgr0)
_BOLD=$(tput bold)

# Print stack name
pulumiinfo() {
        FILE=./Pulumi.yaml
        output=""
        if [ -f "$FILE" ]; then
                output="(p.$(pulumi stack --show-name))"
        fi
        echo $output
}


# Print git branch
gitinfo() {
        output=""
        if [ -d ".git" ]; then 
                output="(g.$(git rev-parse --abbrev-ref HEAD))"
        fi
        echo $output
}

# Set custom bash prompt
export PS1='${_BLUE}\w ${_RED}$(gitinfo)${_YELLOW}$(pulumiinfo) ${_GREEN} ${_BOLD}$ ${_RESET}'

Next steps

The problem here might be for some that it doesn’t print any information if we aren’t in the root directory of a Git or Pulumi project. Personally, I want to be reminded of that I’m not in the root directory, so this is fine for me. In addition we print some empty characters in cases where we don’t have any additional information. This is all details that can be implemented as well.

Join Newsletter
Get the latest updates right in your inbox. I never spam!
Sven Malvik
Written by Sven Malvik

Latest Stories

How To Manage Azure Virtual Machines

I will go through the first steps for managing Virtual Machines. We will create a Windows VM, start the Internet Information Service IIS,...

Dec 26, 2020

Event-Driven Infrastructure with App Configuration

Azure App Configuration is great for externalizing application configurations. But what if an application is our infrastructure? How coul...

Sep 12, 2020

Azure Naming Convention Best Practices

Structure helps us to be in control. That is very true also in Azure. Especially in larger organizations where many cloud engineers creat...

Feb 02, 2021

Using Feature Flags with Azure App Configuration

Sometimes we would like to test a new feature of an application. Or we would like to disable code junks because they are not fully implem...

May 16, 2020

Using App Configuration in Azure DevOps

Application deployments dependent often on environment specific data like the name of a resource group, location or flags for certain use...

Aug 01, 2020

Azure App Configuration Introduction #3

After playing around with Azure App Configuration Service and how to read a configuration entry with REST, and then using feature flags i...

May 23, 2020

How to Establish a VPN Point to Site Connection in Azure

I will demonstrate how to establish a point to site connection in Azure, and connect from a Windows workstation to a virtual machine via ...

Dec 17, 2020

8 Actions to Cut Infrastructure Costs in 2021

8 Actions to Cut Infrastructure Costs in 2021 is the result of a research I did. I wanted to know more about the impact of the pandemic f...

Jan 10, 2021

Serving Website Images from Azure CDN with SSL

In this post I will show you step by step how to serve images on a website from Azure CDN with SSL enabled. My blog has a couple of Azure...

Apr 25, 2020

Sync Azure App Configuration with GitHub Actions

One questions we might ask us when we move our properties files from an application to Azure App Configuration is how we can do this with...

Sep 05, 2020

Running Scripts from ARM Templates

Why would we want t execute code within an ARM template? Sometimes we need some value in an ARM template that we don’t want to copy and p...

Jul 11, 2020

Latest Stories

How To Manage Azure Virtual Machines

How To Manage Azure Virtual Machines

I will go through the first steps for managing Virtual Machines. We will create a Windows VM, start the Internet Information Service IIS,...

Dec 26, 2020

Event-Driven Infrastructure with App Configuration

Event-Driven Infrastructure with App Configuration

Azure App Configuration is great for externalizing application configurations. But what if an application is our infrastructure? How coul...

Sep 12, 2020

Azure Naming Convention Best Practices

Azure Naming Convention Best Practices

Structure helps us to be in control. That is very true also in Azure. Especially in larger organizations where many cloud engineers creat...

Feb 02, 2021

Using Feature Flags with Azure App Configuration

Using Feature Flags with Azure App Configuration

Sometimes we would like to test a new feature of an application. Or we would like to disable code junks because they are not fully implem...

May 16, 2020

Using App Configuration in Azure DevOps

Using App Configuration in Azure DevOps

Application deployments dependent often on environment specific data like the name of a resource group, location or flags for certain use...

Aug 01, 2020

Azure App Configuration Introduction #3

Azure App Configuration Introduction #3

After playing around with Azure App Configuration Service and how to read a configuration entry with REST, and then using feature flags i...

May 23, 2020

How to Establish a VPN Point to Site Connection in Azure

How to Establish a VPN Point to Site Connection in Azure

I will demonstrate how to establish a point to site connection in Azure, and connect from a Windows workstation to a virtual machine via ...

Dec 17, 2020

8 Actions to Cut Infrastructure Costs in 2021

8 Actions to Cut Infrastructure Costs in 2021

8 Actions to Cut Infrastructure Costs in 2021 is the result of a research I did. I wanted to know more about the impact of the pandemic f...

Jan 10, 2021

Serving Website Images from Azure CDN with SSL

Serving Website Images from Azure CDN with SSL

In this post I will show you step by step how to serve images on a website from Azure CDN with SSL enabled. My blog has a couple of Azure...

Apr 25, 2020

Sync Azure App Configuration with GitHub Actions

Sync Azure App Configuration with GitHub Actions

One questions we might ask us when we move our properties files from an application to Azure App Configuration is how we can do this with...

Sep 05, 2020

Running Scripts from ARM Templates

Why would we want t execute code within an ARM template? Sometimes we need some value in an ARM template that we don’t want to copy and p...

Jul 11, 2020