Skip to content

Instantly share code, notes, and snippets.

@nkajic
Created January 17, 2026 15:40
Show Gist options
  • Select an option

  • Save nkajic/0bfbae1062ff96ea3b7259d46b8ac6fd to your computer and use it in GitHub Desktop.

Select an option

Save nkajic/0bfbae1062ff96ea3b7259d46b8ac6fd to your computer and use it in GitHub Desktop.
~/.bashrc.d/99-prompt.sh
__p_user() {
local u
u="$(id -un 2>/dev/null || echo "$USER")"
[[ -z "$u" || "$u" == "www-data" ]] && return 0
printf '%s@' "$u"
}
__p_host() {
local h
h="${HOSTNAME:-$(hostname 2>/dev/null)}"
printf '%s' "${h%-php-fpm}"
}
__p_path() {
if [[ "$PWD" == "/var/www/html" ]]; then
printf 'html'
return 0
fi
if [[ "$PWD" == /var/www/html/* ]]; then
printf '%s' "${PWD#/var/www/html/}"
return 0
fi
if [[ -n "$HOME" && "$PWD" == "$HOME"* ]]; then
printf '~%s' "${PWD#$HOME}"
else
printf '%s' "$PWD"
fi
}
case "$-" in
*i*)
PS1='\[\033[0;36m\]$(__p_user)$(__p_host)\[\033[0m\]:\[\033[0;37m\]$(__p_path)\[\033[0m\]\$ '
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment