Site icon New Generation Enterprise Linux

Stop running commands in the wrong shell session

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

Stop running commands in the wrong shell session

🧩 The Challenge

Everyone has ended up accidentally nuking a directory or restarting a service on the wrong server because they forgot which terminal window was which. It’s annoying, it’s dangerous, and I’ve definitely blown away a production config thinking I was in staging.

💡 The Fix

Use a shell function to dynamically update your terminal tab title based on your hostname and current directory, so you always know where you are at a glance.

case $TERM in
xterm*|rxvt*)
trap 'echo -ne "\e]0;${USER}@${HOSTNAME%%.*}: ${PWD##*/}\007"' DEBUG
;;
esac

⚙️ Why It Works

Setting a trap on the DEBUG signal forces the shell to execute that title update command every time before a new prompt is drawn, keeping your tab text in sync with your location. You won’t have to look at the prompt text as hard when your tab bar is screaming the server name at you.

🚀 Pro-Tip: Stick this in your .bashrc and export the PROMPT_COMMAND variable if you want it to trigger only on prompts instead of every single sub-process.

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

0 0 votes
Article Rating
Exit mobile version