netbsdnoob
Greetings. Currently, I'm using a GNU/Linux distribution and I'm planning to switch to NetBSD on a computer that I'll receive in a couple of days. In my current distribution, I also use the Korn shell and have configured my prompt in the following manner:
- My prompt consists primarily of parameter substitutions and a function to determine the Git branches I have (this is visible when necessary).
- I've assigned colors to make it visually appealing.
- My prompt is invoked through a function from my interactive shell file.
The main function calling my prompt is composed as follows:
function prompt {
print "${GREEN}${PWD/$HOME/\~} ${CYAN}$(get_branch)"
print "${RED}-> ${YELLOW}$ ${NORM}"
}
PS1="\$(prompt)"
The function determining the current branch in Git repositories is set up as follows:
function get_branch {
BRANCH=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
if [[ ! -z ${BRANCH} ]]; then
print "${BRANCH}"
fi
unset BRANCH
}
The colors are defined as follows:
GREEN=$(printf '%b' "\033[1;32m")
CYAN=$(printf '%b' "\033[1;36m")
RED=$(printf '%b' "\033[1;31m")
YELLOW=$(printf '%b' "\033[1;33m")
NORM=$(printf '%b' "\033[0m")
In my interactive shell configuration ($HOME/.kshrc
), I load my prompt as follows:
. $HOME/.local/funcs/prompt
Lastly, here's a sample of how my prompt looks
As you can see, the configuration of my prompt isn't too complicated, so I don't believe it would be too difficult for you to modify it to suit your needs.
Regarding the prompt I use for the root account, I also have it customized through a function. The content of the function is as follows:
function admin_prompt {
[[ $PWD == $HOME ]] && dir="~" || dir="${PWD#*/}"
print "${YELLOW}[$dir] ${GREEN}#${RED} "
}
PS1="\$(admin_prompt) "
Similar to my personal prompt, the root account's prompt is loaded through its own interactive shell configuration (root home: .shrc
).
. $HOME/.local/funcs/admin_prompt
This is how the prompt looks when I switch to the root account.