Adjust the Length of Your Bash Prompt on the Fly

Tyler Tyler (285)
Total time: 5 minutes 
Updated: July 22nd, 2020

As a developer, I’ve customized my bash prompt to always show the current git branch if I’m in an initialized git repository. This is convenient, but it can make for a very long bash prompt. When I need more space, it’s nice to be able to shorten the bash prompt on the fly.

Posted in these interests:

webdev
PRIMARY
58 guides
bash
5 guides

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=# '

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 ~/.bashrc

Add 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_COMMAND

The 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

Adjust the Length of Your Bash Prompt on the Fly

Tyler Tyler (285)
Total time: 5 minutes 
Updated: July 22nd, 2020

As a developer, I’ve customized my bash prompt to always show the current git branch if I’m in an initialized git repository. This is convenient, but it can make for a very long bash prompt. When I need more space, it’s nice to be able to shorten the bash prompt on the fly.

Posted in these interests:

webdev
PRIMARY
58 guides
bash
5 guides

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=# '

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 ~/.bashrc

Add 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_COMMAND

The 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
Jump to step

Adjust the Length of Your Bash Prompt on the Fly

Tyler Tyler (285)
Total time: 5 minutes 
Updated: July 22nd, 2020

As a developer, I’ve customized my bash prompt to always show the current git branch if I’m in an initialized git repository. This is convenient, but it can make for a very long bash prompt. When I need more space, it’s nice to be able to shorten the bash prompt on the fly.

Posted in these interests:

webdev
PRIMARY
58 guides
bash
5 guides

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=# '

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 ~/.bashrc

Add 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_COMMAND

The 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

Adjust the Length of Your Bash Prompt on the Fly

Tyler Tyler (285)
Total time: 5 minutes 
Updated: July 22nd, 2020

As a developer, I’ve customized my bash prompt to always show the current git branch if I’m in an initialized git repository. This is convenient, but it can make for a very long bash prompt. When I need more space, it’s nice to be able to shorten the bash prompt on the fly.

Posted in these interests:

webdev
PRIMARY
58 guides
bash
5 guides

Adjust the Length of Your Bash Prompt on the Fly

webdevbash
Tyler Tyler (285)
Total time: 5 minutes 
Updated: July 22nd, 2020
Tyler
1
 

Posted in these interests:

webdev
PRIMARY
58 guides
bash
5 guides
webdev
PRIMARY
58 guides
bash
5 guides
PRIMARY
Jump to step
Calling all writers!

We’re hiring. Write for Howchoo

1
 
In these interests
webdev
PRIMARY
58 guides
bash
5 guides
webdev
PRIMARY
58 guides
bash
5 guides
PRIMARY
Jump to step

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=# '

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 ~/.bashrc

Add 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_COMMAND

The 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

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=# '

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

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 ~/.bashrc

Add 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_COMMAND

The 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

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 ~/.bashrc

Add 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_COMMAND

The 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

Set functions in your .bashrc to make it easier

Calling all writers!

We’re hiring. Write for Howchoo

Tyler's profile pictureTyler
Joined in 2015
Software Engineer and creator of howchoo.
Tyler's profile picture
Share this guide!
RedditEmailText
Related to this guide:
MySQL vs PostgreSQLMySQL vs PostgreSQL
Comparing performance, syntax, replication, and features.
Gilad's profile picture GiladView
In these interests: postgresqlwebdevmysql
How to export clean HTML from Google DocsHow to export clean HTML from Google Docs
By default, the HTML exported from Google Docs includes tons of classes, styles, and is generally messy. This short guide will teach you how to export clean HTML devoid of classes and inline styles.
Zach's profile picture ZachView
In these interests: googledocswebdevcode
Filtering Google Analytics language spamFiltering Google Analytics language spam
Google Analytics spam is nothing new. But now spammers have realized that, since language appears in the initial Google Analytics dashboard view, spoofing the language code reaches eyeballs.
Zach's profile picture ZachView
In these interests: webdev
MySQL vs PostgreSQLMySQL vs PostgreSQL
Comparing performance, syntax, replication, and features.
Gilad's profile picture GiladView
In these interests: postgresqlwebdevmysql
Gilad's profile pictureViewpostgresqlwebdevmysql
How to export clean HTML from Google DocsHow to export clean HTML from Google Docs
By default, the HTML exported from Google Docs includes tons of classes, styles, and is generally messy. This short guide will teach you how to export clean HTML devoid of classes and inline styles.
Zach's profile picture ZachView
In these interests: googledocswebdevcode
Zach's profile pictureViewgoogledocswebdevcode
Filtering Google Analytics language spamFiltering Google Analytics language spam
Google Analytics spam is nothing new. But now spammers have realized that, since language appears in the initial Google Analytics dashboard view, spoofing the language code reaches eyeballs.
Zach's profile picture ZachView
In these interests: webdev
Zach's profile pictureViewwebdev
People also read:
Converting XML files to JSON is a good practice for providing easy manipulation and preparing service responses. You can accomplish this efficiently with just three lines of code.
Part of being a web developer is testing things that will inevitably break in insane and unexpected ways in Internet Explorer.
This guide will show you how to set up a LAMP environment in macOS and OS X.
I’ll spoil it – “printenv” is your friend. This guide will show a few examples of how to use it.
Surprisingly, normal YouTube embeds are not automatically sized to the browser window as it is resized.
I started programming in PHP, so by default I would use apache even when I just wanted to test basic HTML files. As I was learning Python, I discovered a great HTTP request handler.
As a web developer, I stare at Chrome’s developer tools — particularly the Elements and Console tabs — all day long. As a result, all light and no dark makes Zach’s eyes dull and tired.
You can echo the current MODX resource’s full page URL without the use of a snippet call.
Renaming a MySQL table is very simple, but sometimes the syntax is hard to remember.
Converting XML files to JSON is a good practice for providing easy manipulation and preparing service responses. You can accomplish this efficiently with just three lines of code.
Part of being a web developer is testing things that will inevitably break in insane and unexpected ways in Internet Explorer.
This guide will show you how to set up a LAMP environment in macOS and OS X.
I’ll spoil it – “printenv” is your friend. This guide will show a few examples of how to use it.
How to Convert XML to JSON in PHP
How to Run Internet Explorer on Mac (For Free)
How to Set Up a LAMP server in macOS
How to Print Environment Variables in Linux/Unix
GitHub Pull Requests: How and Why to Use Pull Requests
Surprisingly, normal YouTube embeds are not automatically sized to the browser window as it is resized.
I started programming in PHP, so by default I would use apache even when I just wanted to test basic HTML files. As I was learning Python, I discovered a great HTTP request handler.
As a web developer, I stare at Chrome’s developer tools — particularly the Elements and Console tabs — all day long. As a result, all light and no dark makes Zach’s eyes dull and tired.
You can echo the current MODX resource’s full page URL without the use of a snippet call.
Renaming a MySQL table is very simple, but sometimes the syntax is hard to remember.
Make YouTube Video Embeds Responsive Using Pure HTML and CSS
Using Python’s simple HTTP server
Tell Chrome Developer Tools to Use a Dark Theme
How to Print the Current Page URL in MODX
Rename a MySQL table
Posted in these interests:
webdevwebdev
webdev
PRIMARY
All things web development.
webdevwebdev
webdev
PRIMARY
All things web development.
PRIMARY
ExploreExplore
Discuss this guide:
We’re hiring!
Are you a passionate writer? We want to hear from you!
We’re hiring!
Are you a passionate writer? We want to hear from you!
View openings

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.

Donate

Leave a Reply

Your email address will not be published. Required fields are marked *