Create a cool, bash PS1 prompt that initializes the terminal with a fun ascii animation
- User
Create a cool, bash PS1 prompt that initializes the terminal with a fun ascii animation
- Assistant
Certainly! Customizing your Bash prompt (the
PS1variable) can be a fun way to personalize your terminal. Additionally, you can display an ASCII animation when you start a new terminal session to add some flair. Below, I'll guide you through creating a cool Bash prompt and setting up an ASCII animation that plays when you open a new terminal.Step 1: Create an ASCII Animation Script
First, we'll create a simple ASCII animation script. For demonstration purposes, let's create a spinning globe animation.
Create the script file:
bashnano ~/ascii_animation.shAdd the following content to the file:
bash#!/bin/bash # Frames of the spinning globe frames=( "🌍" "🌎" "🌏" ) # Number of times the animation will loop loops=3 # Clear the screen clear for ((i=0; i<loops*${#frames[@]}; i++)); do # Display frame echo -ne "${frames[i % ${#frames[@]}]} Welcome to your terminal! ${frames[i % ${#frames[@]}]}\r" # Pause between frames sleep 0.2 done # Move to a new line after the animation echoSave and exit the editor:
- Press
Ctrl+O, thenEnterto save. - Press
Ctrl+Xto exit.
Make the script executable:
bashchmod +x ~/ascii_animation.shStep 2: Modify Your
.bashrcFile to Run the AnimationWe'll set up the script to run whenever you start a new interactive shell session.
Open your
.bashrcfile:bashnano ~/.bashrcAdd the following lines at the end of the file:
bash# Run ASCII animation on terminal startup if [ -n "$PS1" ] && [ -x ~/ascii_animation.sh ]; then ~/ascii_animation.sh fi - Press