Stop forgetting which directory your environment belongs to

Environment & Shell Customization (Aliases/Functions/.Bashrc)

Stop forgetting which directory your environment belongs to

🧩 The Challenge

Half the time I end up editing the wrong config file because I forgot I was in the prod directory instead of my local dev setup. It’s a fast way to break things you really shouldn’t be touching.

💡 The Fix

Throw this function in your bashrc to make your prompt scream exactly where you are sitting so you stop making stupid mistakes. It saves my skin every time I’m juggling multiple open terminals.

prompt_dir() {
local pdir=$(basename "$PWD")
echo -e "\e[32m[$pdir]\e[0m"
}
PS1='$(prompt_dir) \u@\h:\w\$ '

⚙️ Why It Works

Adding this to your primary shell prompt forces a dynamic visual cue that shifts with every cd command you execute. Bash re-evaluates that function every single time it draws the prompt, so the info is never stale.

🚀 Pro-Tip: Use bold or bright ANSI colors to make the directory name stand out against your standard server hostname.

Linux Tips & Tricks | © ngelinux.com | 10/27/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted