garysimpson.dev
Mobile development with swift and flutter

Terminal: Custom Bash Prompt

October 11, 2024 at 5:30PM

By default terminal prompt with machineName:folderName userName$

Just found out about my new favorite thing to customize on macOS when setting up a new machine. Customize the promt that is shown when I launch a new terminal window.

Initially a friend of mine shared the export that would display the full path with on branchName$ . I wanted to customize this a little. Opting to hide path info greater than 2 directory levels. Then updating the branch name to dispaly in parens.

Before

export PS1='\[\e[32m\]\w\[\e[m\]\[\e[33m\]$(git branch 2>/dev/null | grep "*" | sed "s/*/ on /")\[\e[m\]\$ '

Updated to display directoryPath on branchName$

After



export PS1='\[\e[38;5;202m\]$(pwd | awk -F"/" '\''{if (NF>2) printf "../%s/%s", $(NF-1), $NF; else print $0}'\'')\[\e[m\]\[\e[38;5;30m\]$(git branch 2>/dev/null | grep "*" | sed "s/^\* //;s/^/ (/;s/$/)/")\[\e[m\]\$ '

Finally set to display ../2RecentDirectoryNames (branchName)$

Happy Coding ;-)