Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialthomascawthorn
22,986 PointsMac hostname defaulting to unknown-xx-xx-xx-xx-xx-x in Terminal
I'm trying to fix this one issue with command line that keeps coming back.
I've modified my prompt in the .bash_profile by adding
#FOR CMD LINE GIT AND COLOR
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOR="\[\033[0m\]"
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="$GREEN\u@\h$RED \W$YELLOW\$(parse_git_branch)$NO_COLOR$ "
I wanted the current git branch to show up on the prompt like in the treehouse vm, which is where this started!
The exported PS1 outputs "user@hostname directory current_git_branch $"
My hostname on start up defaults to 'unknown-xx-xx-xx-xx-xx-x', where the x's represent an assortment of numbers and letters. It looks like
Tom@unknown-xx-xx-xx-xx-xx-xx ~$
I can change the 'unknown' section by running
sudo hostname Tommbp
which does change it to a glorious
Tom@Tommbp ~$
Sadly, following a reboot/randomly, the hostname decides to change back to unknown, which is really annoying and incredibly sneaky.
I've tried changing the Computer Name in System Preferences > Sharing
and also the local hostname at System Preferences > Sharing > Edit (under Computer Name) but this hasn't helped. I can tell you that if I change my hostname via command line and then change my local hostname via system preferences, the cmd prompt returns to 'unknown'
I think it's the local hostname that should appear instead of 'unknown' and it's having a hard time picking up the value I've given in system preferences?
Any help would be much appreciated!