View previous topic :: View next topic |
Author |
Message |
lekto Apprentice
Joined: 20 Sep 2014 Posts: 207 Location: Ancient Rome
|
Posted: Sun Jun 16, 2024 6:16 am Post subject: How to restore old bash (pre 5.1_p16-r11) window title? |
|
|
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 |
|
|
Banana Moderator
Joined: 21 May 2004 Posts: 1720 Location: Germany
|
|
Back to top |
|
|
lekto Apprentice
Joined: 20 Sep 2014 Posts: 207 Location: Ancient Rome
|
Posted: Sun Jun 16, 2024 7:23 am Post subject: |
|
|
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 |
|
|
sdauth l33t
Joined: 19 Sep 2018 Posts: 645 Location: Ásgarðr
|
Posted: Sun Jun 16, 2024 10:44 am Post subject: |
|
|
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 |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 22618
|
Posted: Sun Jun 16, 2024 3:38 pm Post subject: |
|
|
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 |
|
|
RumpletonBongworth n00b
Joined: 17 Jun 2024 Posts: 74
|
Posted: Mon Jun 17, 2024 1:28 am Post subject: |
|
|
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 |
|
|
RumpletonBongworth n00b
Joined: 17 Jun 2024 Posts: 74
|
Posted: Mon Jun 17, 2024 7:27 am Post subject: |
|
|
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 |
|
|
RumpletonBongworth n00b
Joined: 17 Jun 2024 Posts: 74
|
Posted: Mon Jun 17, 2024 5:45 pm Post subject: |
|
|
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 |
|
|
|