From 5ac43c1b2a921fd2745f0d9945279f14c240ae89 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Tue, 27 Apr 2021 22:52:25 +0200 Subject: Tweak window title for terminal emulators --- .bash_prompt | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/.bash_prompt b/.bash_prompt index a922033..9b753b3 100644 --- a/.bash_prompt +++ b/.bash_prompt @@ -25,20 +25,27 @@ __have-gitprompt () __set-title () { - local title - local git_root=$(git root 2> /dev/null) + local title=${USER} + if __show-hostname + then + title+="@${HOSTNAME}" + fi + title+=: - if [ ${git_root} ] + local path=${PWD/~/\~} + local git_root=$(git rev-parse --show-toplevel 2> /dev/null) + + if [ -z "${git_root}" -o "${git_root}" = ~ ] then - title=$(basename ${git_root}) + title+=${path} else - local path=${PWD/~/\~} - - if __show-hostname + local project=$(basename "${git_root}") + path=$(realpath --relative-to "${git_root}" "${PWD}") + if [ "${path}" = . ] then - title="${USER}@${HOSTNAME}:${path}" + title+=${project} else - title="${USER}:${path}" + title+=${project}/${path} fi fi -- cgit v1.2.3