Skip to content

Instantly share code, notes, and snippets.

@tsengia
Last active May 9, 2024 05:10
Show Gist options
  • Save tsengia/be3d99c8222d924925cb9513ea879e21 to your computer and use it in GitHub Desktop.
Save tsengia/be3d99c8222d924925cb9513ea879e21 to your computer and use it in GitHub Desktop.
Temporarily configure a custom terminal prompt with specified host info and relative directory status.
#!/bin/bash
# NOTE: Tested on Kubuntu 24.04, using bash 5.2.21
host_info="${1}"
relative_dir="${2}"
if [ -z $relative_dir ]; then
relative_dir=$(dirname "${PWD}")
fi
prompt=$(echo '"${debian_chroot:+($debian_chroot)}\[\033[01;32m\]')
prompt+=${host_info}
prompt+=$(echo '\[\033[00m\]:\[\033[01;34m\]~\${PWD#')
prompt+=${relative_dir}
prompt+=$(echo '}\[\033[00m\]\$ "')
bash --rcfile <(cat ~/.bashrc; echo PS1="${prompt}" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment