Adjust The Length Of Your Bash Prompt On The Fly
Set the PROMPT_COMMAND
According to the gnu.org bash reference regarding the PROMPT_COMMAND. If set, the value is interpreted as a command to execute before the printing of each primary prompt. One way to change your prompt on the fly is to simply set the value of PROMPT_COMMAND.
josephtyler@tylermbp[~] # PROMPT_COMMAND='PS1=# 'Set functions in your .bashrc to make it easier
I’ve set two functions in my bashrc file to make this process easier. I’ve called the functions eep for expand prompt and ccp for contract prompt but you can call them whatever you’d like. Open your bashrc file to edit:
vim ~/.bashrcAdd the following at the end:
INITIAL_PROMPT_COMMAND=$PROMPT_COMMAND
function ccp() {
PROMPT_COMMAND="PS1='# '"
}
function eep() {
PROMPT_COMMAND=$INITIAL_PROMPT_COMMAND
}The first line simply sets the initial command prompt to a new variable so that we can access it later.
INITIAL_PROMPT_COMMAND=$PROMPT_COMMANDThe next two lines are functions eep and ccp that you can use to expand and contract your bash prompt.
After saving this file, you’ll need to source it for it to take effect.
source ~/.bashrcSet the PROMPT_COMMAND
According to the gnu.org bash reference regarding the PROMPT_COMMAND. If set, the value is interpreted as a command to execute before the printing of each primary prompt. One way to change your prompt on the fly is to simply set the value of PROMPT_COMMAND.
josephtyler@tylermbp[~] # PROMPT_COMMAND='PS1=# 'Set functions in your .bashrc to make it easier
I’ve set two functions in my bashrc file to make this process easier. I’ve called the functions eep for expand prompt and ccp for contract prompt but you can call them whatever you’d like. Open your bashrc file to edit:
vim ~/.bashrcAdd the following at the end:
INITIAL_PROMPT_COMMAND=$PROMPT_COMMAND
function ccp() {
PROMPT_COMMAND="PS1='# '"
}
function eep() {
PROMPT_COMMAND=$INITIAL_PROMPT_COMMAND
}The first line simply sets the initial command prompt to a new variable so that we can access it later.
INITIAL_PROMPT_COMMAND=$PROMPT_COMMANDThe next two lines are functions eep and ccp that you can use to expand and contract your bash prompt.
After saving this file, you’ll need to source it for it to take effect.
source ~/.bashrcSet the PROMPT_COMMAND
According to the gnu.org bash reference regarding the PROMPT_COMMAND. If set, the value is interpreted as a command to execute before the printing of each primary prompt. One way to change your prompt on the fly is to simply set the value of PROMPT_COMMAND.
josephtyler@tylermbp[~] # PROMPT_COMMAND='PS1=# 'Set functions in your .bashrc to make it easier
I’ve set two functions in my bashrc file to make this process easier. I’ve called the functions eep for expand prompt and ccp for contract prompt but you can call them whatever you’d like. Open your bashrc file to edit:
vim ~/.bashrcAdd the following at the end:
INITIAL_PROMPT_COMMAND=$PROMPT_COMMAND
function ccp() {
PROMPT_COMMAND="PS1='# '"
}
function eep() {
PROMPT_COMMAND=$INITIAL_PROMPT_COMMAND
}The first line simply sets the initial command prompt to a new variable so that we can access it later.
INITIAL_PROMPT_COMMAND=$PROMPT_COMMANDThe next two lines are functions eep and ccp that you can use to expand and contract your bash prompt.
After saving this file, you’ll need to source it for it to take effect.
source ~/.bashrcSet the PROMPT_COMMAND
According to the gnu.org bash reference regarding the PROMPT_COMMAND. If set, the value is interpreted as a command to execute before the printing of each primary prompt. One way to change your prompt on the fly is to simply set the value of PROMPT_COMMAND.
josephtyler@tylermbp[~] # PROMPT_COMMAND='PS1=# 'Set functions in your .bashrc to make it easier
I’ve set two functions in my bashrc file to make this process easier. I’ve called the functions eep for expand prompt and ccp for contract prompt but you can call them whatever you’d like. Open your bashrc file to edit:
vim ~/.bashrcAdd the following at the end:
INITIAL_PROMPT_COMMAND=$PROMPT_COMMAND
function ccp() {
PROMPT_COMMAND="PS1='# '"
}
function eep() {
PROMPT_COMMAND=$INITIAL_PROMPT_COMMAND
}The first line simply sets the initial command prompt to a new variable so that we can access it later.
INITIAL_PROMPT_COMMAND=$PROMPT_COMMANDThe next two lines are functions eep and ccp that you can use to expand and contract your bash prompt.
After saving this file, you’ll need to source it for it to take effect.
source ~/.bashrcSet the PROMPT_COMMAND
According to the gnu.org bash reference regarding the PROMPT_COMMAND. If set, the value is interpreted as a command to execute before the printing of each primary prompt. One way to change your prompt on the fly is to simply set the value of PROMPT_COMMAND.
josephtyler@tylermbp[~] # PROMPT_COMMAND='PS1=# 'Set the PROMPT_COMMAND
According to the gnu.org bash reference regarding the PROMPT_COMMAND. If set, the value is interpreted as a command to execute before the printing of each primary prompt. One way to change your prompt on the fly is to simply set the value of PROMPT_COMMAND.
josephtyler@tylermbp[~] # PROMPT_COMMAND='PS1=# 'Set the PROMPT_COMMAND
Set functions in your .bashrc to make it easier
I’ve set two functions in my bashrc file to make this process easier. I’ve called the functions eep for expand prompt and ccp for contract prompt but you can call them whatever you’d like. Open your bashrc file to edit:
vim ~/.bashrcAdd the following at the end:
INITIAL_PROMPT_COMMAND=$PROMPT_COMMAND
function ccp() {
PROMPT_COMMAND="PS1='# '"
}
function eep() {
PROMPT_COMMAND=$INITIAL_PROMPT_COMMAND
}The first line simply sets the initial command prompt to a new variable so that we can access it later.
INITIAL_PROMPT_COMMAND=$PROMPT_COMMANDThe next two lines are functions eep and ccp that you can use to expand and contract your bash prompt.
After saving this file, you’ll need to source it for it to take effect.
source ~/.bashrcSet functions in your .bashrc to make it easier
I’ve set two functions in my bashrc file to make this process easier. I’ve called the functions eep for expand prompt and ccp for contract prompt but you can call them whatever you’d like. Open your bashrc file to edit:
vim ~/.bashrcAdd the following at the end:
INITIAL_PROMPT_COMMAND=$PROMPT_COMMAND
function ccp() {
PROMPT_COMMAND="PS1='# '"
}
function eep() {
PROMPT_COMMAND=$INITIAL_PROMPT_COMMAND
}The first line simply sets the initial command prompt to a new variable so that we can access it later.
INITIAL_PROMPT_COMMAND=$PROMPT_COMMANDThe next two lines are functions eep and ccp that you can use to expand and contract your bash prompt.
After saving this file, you’ll need to source it for it to take effect.
source ~/.bashrc