Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to restore old bash (pre 5.1_p16-r11) window title?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
lekto
Apprentice
Apprentice


Joined: 20 Sep 2014
Posts: 182
Location: Ancient Rome

PostPosted: Sun Jun 16, 2024 6:16 am    Post subject: How to restore old bash (pre 5.1_p16-r11) window title? Reply with quote

Hi, the last update of bash has changed the behaviour of the window title; instead of the whole working path, I'm seeing only the current directory. How do I restore old behaviour?
Back to top
View user's profile Send private message
Banana
Moderator
Moderator


Joined: 21 May 2004
Posts: 1502
Location: Germany

PostPosted: Sun Jun 16, 2024 7:03 am    Post subject: Reply with quote

Sounds like this here: https://forums.gentoo.org/viewtopic-t-1169437.html

So, please check any custom files in /etc/bash/bashrc.d and your ~/.bashrc
_________________
My personal space
My delta-labs.org snippets do expire

PFL - Portage file list - find which package a file or command belongs to.
Back to top
View user's profile Send private message
lekto
Apprentice
Apprentice


Joined: 20 Sep 2014
Posts: 182
Location: Ancient Rome

PostPosted: Sun Jun 16, 2024 7:23 am    Post subject: Reply with quote

I looked into 10-gentoo-title-bash and this line is causing my problem: _cwd=${PWD##*/}, I've changed it to _cwd=${PWD}. It works now, but I would rather do this in .bashrc, but I don't know how without copying the whole genfun_set_win_title function.

Also, what is with putting a function inside a function with same name and calling the function?
Code:
genfun_set_win_title() {
        (…)
        genfun_set_win_title() {
                (…)
        }

        genfun_set_win_title
}


EDIT
Okay, there were some differences in handling the home directory(~ vs full path) and formatting(- vs : ), this looks like correct way to do it the old way:
Code:
genfun_set_win_title() {
        _cwd=${PWD}
        if [[ ${_cwd} == ${HOME} ]]; then
                _cwd="~"
        elif [[ ! ${_cwd} ]]; then
                _cwd=${PWD}
        elif [[ ${_cwd} == *[![:graph:]]* ]]; then
                _cwd=${_cwd@Q}
        fi

        printf '\033]2;%s@%s:%s\007' "${USER}" "${HOSTNAME%%.*}" "${_cwd}"
}

PROMPT_COMMAND=('genfun_set_win_title')
Back to top
View user's profile Send private message
sdauth
l33t
l33t


Joined: 19 Sep 2018
Posts: 605
Location: Ásgarðr

PostPosted: Sun Jun 16, 2024 10:44 am    Post subject: Reply with quote

Thanks lekto, I prefer the old way too. (showing full path) Copying the modified function genfun_set_win_title to my bashrc works but I don't understand why it isn't default ?
edit : I modified the genfun_set_win_title function in /etc/bash/bashrc.d/10-gentoo-title.bash instead, to avoid cluttering my .bashrc and also be warned if it eventually change again in the future.


Last edited by sdauth on Sun Jun 16, 2024 6:32 pm; edited 1 time in total
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 21963

PostPosted: Sun Jun 16, 2024 3:38 pm    Post subject: Reply with quote

I suspect getting a default that pleases everyone will be impossible. I have a custom prompt here that trims some, but not all, directories. It is similar to, but not the same as, bash's PROMPT_DIRTRIM behavior. I routinely find myself in very deep paths, and want more than just the basename, but cannot spare the terminal width to see the full value of $PWD at all times.
Back to top
View user's profile Send private message
RumpletonBongworth
n00b
n00b


Joined: 17 Jun 2024
Posts: 54

PostPosted: Mon Jun 17, 2024 1:28 am    Post subject: Reply with quote

lekto wrote:
I looked into 10-gentoo-title-bash and this line is causing my problem: _cwd=${PWD##*/}, I've changed it to _cwd=${PWD}. It works now, but I would rather do this in .bashrc, but I don't know how without copying the whole genfun_set_win_title function.

One way would be as follows.
Code:
unset PROMPT_COMMAND
(( set_prompt++ )) || PS1+='\[\e]2;\u@\h:\w\a\]'
Back to top
View user's profile Send private message
RumpletonBongworth
n00b
n00b


Joined: 17 Jun 2024
Posts: 54

PostPosted: Mon Jun 17, 2024 7:27 am    Post subject: Reply with quote

Hu wrote:
I routinely find myself in very deep paths, and want more than just the basename, but cannot spare the terminal width to see the full value of $PWD at all times.

This is, indeed, one of the reasons why it was made so. Long titles also render poorly in tmux sessions, in so far as they will be truncated to a length of 21 characters by default.
Back to top
View user's profile Send private message
RumpletonBongworth
n00b
n00b


Joined: 17 Jun 2024
Posts: 54

PostPosted: Mon Jun 17, 2024 5:45 pm    Post subject: Reply with quote

lekto wrote:
Also, what is with putting a function inside a function with same name and calling the function?

The Shell Command Language tolerates functions that re-declare themselves. In this particular case, it's being done so that the genfun_sanitise_cwd function is declared lazily, thus avoiding the 'pollution' of the end user's command namespace in cases where it might never be used anyway.

Code:
$ hello() { printhello() { echo hello; }; hello() { printhello; }; hello; }
$ declare -F
declare -f hello
$ hello
hello
$ declare -F
declare -f hello
declare -f printhello
$ declare -f hello
hello ()
{
    printhello
}
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum