Hi, I’ve recently watched Jay’s video on terminal tips and it inspired me to go ahead and try to customize my shell prompt a little.
I managed to get things working the way I like, but then noticed that when typing long commands, or the terminal window is narrow (and sometimes, just because), the cursor suddenly jumps back to the start of the line.
Here’s an example of what I mean. At one point, it jumps back to the beginning and overwriting what I have i there. The command still works correctly though, it’s just a visual bug.
Luckily, I noticed the issue once I started to refactor the PS1 string a bit which is pretty long. So while I have no idea what it could be, I know if must be in how I did the refactoring. Here’s the working prompt:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]${i_fa_user} \u \[\033[01;34m\]${i_fa_folder_open} \W\[\033[38;5;214m\]$(__git_ps1 " $i_dev_git_branch %s")\[\033[38;5;205m\]$(docker_compose_count %s)\[\033[00m\] $i_fa_angle_double_right '
And here’s the output of the entire bash_profile
with the updated
source /usr/lib/git-core/git-sh-prompt
# Makes nerd-fonts icons available using convenient aliases
source ~/.local/bin/nerd-fonts/i_all.sh
# Prints the number of containers running on the current directory
function docker_compose_count() {
container_count=$(docker compose ps 2>/dev/null | grep -v STATUS | wc -l)
if [[ "${container_count}" -eq 0 ]]
then
printf ""
else
printf "\033[38;5;205m"
printf " $i_linux_docker $container_count"
fi
}
# Prints the number of jobs associated to the terminal session
function bg_jobs() {
job_count=$(jobs | wc -l)
if [[ "${job_count}" -eq 0 ]]
then
printf ""
else
printf "\033[38;5;157m"
printf " $i_fa_cog $job_count"
fi
}
# Prints the current checked out branch on a git-tracked directory
function git_branch() {
printf "\033[38;5;214m"
__git_ps1 " $i_dev_git_branch %s"
}
function user_icon() {
printf "\033[01;32m"
printf "$i_fa_user"
}
function folder_icon() {
printf "\033[01;34m"
printf "$i_fa_folder_open"
}
function double_arrow_icon() {
printf "\033[00m"
printf " $i_fa_angle_double_right"
}
PS1='${debian_chroot:+($debian_chroot)}$(user_icon) \u $(folder_icon) \W$(git_branch)$(docker_compose_count)$(bg_jobs)$(double_arrow_icon) '
Any help is much appreciated