-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tab titles don't reflect current directory or process running #1188
Comments
This is true of macOS too. |
@audunolsen in version 1.0.0? I assumed it was Windows only because of this notice: parro-it/hyperterm-title#5 |
I stole your comment for a better issue title :) |
Hi, since my plugin You have to setup a shell prompt that uses this escape sequence in order to avoid "Shell" as tab title. |
Checkout pure prompt for zsh. I'm sure there are similar ones for bash or fish too |
I agree that a better default behaviour is useful... Show the Shell name should be simple to implement |
@parro-it thanks for chiming in! I appreciate your work on this plugin as it is a feature probably most users if not everyone take it for granted. With that said, I think an ideal solution would be supporting all terminals, in particular now that Hyper is meant to be used on all major operating systems. So perhaps additional methods of retrieving the shell title are needed :) |
@parro-it you were quicker than me! |
@stereokai 😁 any idea on how we Can listen for cwd change or foreground process change without polling? |
I found this issue there: cmderdev/cmder#815. |
@parro-it Excellent find! Using this, I can confirm Hyper recognizes and picks up the titles from all shells on my machine, that is, PowerShell, cmd, and native Bash on Ubuntu on Windows. I guess you deserve a huge applause because it's your code that's doing the magic ;) Can you check if Edit: Would be better to just include the code from the link here: $host.ui.RawUI.WindowTitle = "HelloCmder" cmd: title HelloCmder bash: echo -ne '\e]0;HelloCmder\a' |
It work, that is exactly the escape code we use to set tab title on hyper 😄. The tab on the right is running bash without custom prompt, the tab on the left is running zsh with |
What do you mean technically by "set your prompt to contain the same escape"? Can you be more clear? |
Try to run this on bash: PS1="\[\033]0;\w\007\]>" That command set your prompt to an escape sequence that change the title to the cwd every time you run a command (and add a '>' to the prompt just for convenience) Here are various code you can use in the prompt: |
@parro-it doesn't seem to work in Bash on Windows, but anyway - it won't be supported in cmd and PowerShell - so what's the use? It is a Linux-only infrastructure. Or maybe you can enlighten me :) |
It work very well on macOS too... it's very useful to have custom prompt in these two operating system. anyway, I still think that a better default for hyper is needed that does not use ansi escape sequences. |
@parro-it This works great for me on macOS, thank you! Do you know if there is an additional way to make it reflect a process like e.g. node? Like if it's possible to prepend the process name to the cwd? |
I managed to find a solution to show the basedir and append bash commands to it! case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "\033]0;${PWD##*/}\007"'
show_command_in_title_bar()
{
case "$BASH_COMMAND" in
*\033]0*)
;;
*)
echo -ne "\033]0;${BASH_COMMAND} - ${PWD##*/}\007"
;;
esac
}
trap show_command_in_title_bar DEBUG
;;
*)
;;
esac I threw the above code in ~.profile, it's based on this. |
@audunolsen awesome! |
As I mentioned on #1162 (same bug) the tabs are just displaying "Shell" with Hyper 1.0.0 on Yosemite. Setting The bash script above does work. |
@audunolsen My current tab title was blank, and all tabs just showed "Shell". Placed the code you gave in ~/.profile. All tab titles got replaced by the name of current User. |
Sorry to pile on @audunolsen - I also pasted the code into .profile and no change. Using Bash on Windows10. |
Nevermind - user error. I put this in .bashrc and it worked. Now to figure out how to get it to show the complete path, not just the current directory. :) |
I decided to extend audunolsen's solution. I wanted the auto-title he created but I also wanted to have ability to set a static title to a tab when needed. So I did this in function title {
export TITLE_OVERRIDDEN=1
PROMPT_COMMAND=''
echo -ne "\033]0;"$*"\007"
}
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "\033]0;${PWD##*/}\007"'
show_command_in_title_bar()
{
if [[ "$TITLE_OVERRIDDEN" == 1 ]]; then return; fi
case "$BASH_COMMAND" in
*\033]0*)
;;
*)
echo -ne "\033]0;${BASH_COMMAND} - ${PWD##*/}\007"
;;
esac
}
trap show_command_in_title_bar DEBUG
;;
*)
;;
esac
Now when I need title it's |
I am still having trouble getting the location in tab title using powershell the following line of code does the trick in ConEmu and in vanilla powershell but does not work when opening powershell in hyper. What gives? $host.UI.RawUI.WindowTitle = Get-Location Setting it to a string (se below) works fine. $host.UI.RawUI.WindowTitle = "Hello" |
I'm a bit confused. |
@luismasg |
Hello all, here's a small update benefiting all of you using zsh. I recently made the switch from bash which broke my previous solution. Luckily, fixing this for zsh wasn't too difficult. # ~/.zshrc
# Override auto-title when static titles are desired ($ title My new title)
title() { export TITLE_OVERRIDDEN=1; echo -en "\e]0;$*\a"}
# Turn off static titles ($ autotitle)
autotitle() { export TITLE_OVERRIDDEN=0 }; autotitle
# Condition checking if title is overridden
overridden() { [[ $TITLE_OVERRIDDEN == 1 ]]; }
# Echo asterisk if git state is dirty
gitDirty() { [[ $(git status 2> /dev/null | grep -o '\w\+' | tail -n1) != ("clean"|"") ]] && echo "*" }
# Show cwd when shell prompts for input.
precmd() {
if overridden; then return; fi
pwd=$(pwd) # Store full path as variable
cwd=${pwd##*/} # Extract current working dir only
print -Pn "\e]0;$cwd$(gitDirty)\a" # Replace with $pwd to show full path
}
# Prepend command (w/o arguments) to cwd while waiting for command to complete.
preexec() {
if overridden; then return; fi
printf "\033]0;%s\a" "${1%% *} | $cwd$(gitDirty)" # Omit construct from $1 to show args
} I've commented each step, making it easy to modify the script to your likings (full path vs. basename only, show command with or without args, git dirty state). I've also incorporated @achekulaev's static titles, letting you override auto-titles with your own static titles ( |
For windows bash users, I upgraded to Fall Creators update using the Windows update assistant, and this resolved itself for me 😄 |
Titles are broken again on Windows (using cmd) when "Use legacy console" is not enabled. Switching to the legacy console works fine, but breaks WSL bash. Clink (and Cmder) had a similar, possibly related issue: mridgers/clink#464 Something about the new conhost. Stanzilla/clink@4217e6d |
I'm running into an issue while using @audunolsen 's zsh script. My titles come out as |
@mackmmiller: I'm using zsh version |
Using zsh with ohmyzsh and hyper-tabs-enhanced and @audunolsen 's solution worked for me. It's even getting the process icons right which is pretty cool. |
After working with @audunolsen 's solution a bit, I realized there's one problem. Using I managed to solve it, thanks to a similar solution posted in direnv/direnv#24. The idea is to attach our handlers to the array of existing handlers, rather than directly defining precmd() and preexec(). So, extending @audunolsen 's solution: # ~/.zshrc
# Override auto-title when static titles are desired ($ title My new title)
title() { export TITLE_OVERRIDDEN=1; echo -en "\e]0;$*\a"}
# Turn off static titles ($ autotitle)
autotitle() { export TITLE_OVERRIDDEN=0 }; autotitle
# Condition checking if title is overridden
overridden() { [[ $TITLE_OVERRIDDEN == 1 ]]; }
# Echo asterisk if git state is dirty
gitDirty() { [[ $(git status 2> /dev/null | grep -o '\w\+' | tail -n1) != ("clean"|"") ]] && echo "*" }
# Show cwd when shell prompts for input.
tabtitle_precmd() {
if overridden; then return; fi
pwd=$(pwd) # Store full path as variable
cwd=${pwd##*/} # Extract current working dir only
print -Pn "\e]0;$cwd$(gitDirty)\a" # Replace with $pwd to show full path
}
[[ -z $precmd_functions ]] && precmd_functions=()
precmd_functions=($precmd_functions tabtitle_precmd)
# Prepend command (w/o arguments) to cwd while waiting for command to complete.
tabtitle_preexec() {
if overridden; then return; fi
printf "\033]0;%s\a" "${1%% *} | $cwd$(gitDirty)" # Omit construct from $1 to show args
}
[[ -z $preexec_functions ]] && preexec_functions=()
preexec_functions=($preexec_functions tabtitle_preexec) |
I'm getting the same issue as @mackmmiller |
@audunolsen thanks for your solution but I have a problem with it. |
Seems like this helps. |
I just did a clean install of Hyper (and added plugin 'hyper-tab-icons') and the tab titles are not changing. Nor are the icons, like they are supposed to with hyper-tab-icons. Do I need to do something in order for the title/icons to show? |
@ugrupp I imported your code suggested at #1188 (comment) but I am having issues since the title is all messed up and it looks like this: Do you happen to know how I may fix it? |
@ugrupp Fortunately I found a quick fix. Since I am using oh-my-zsh I had to uncomment the line |
really late to the party, but #3015 fixes this issue. Should work on all shells too. |
putting it in my ~/.zshrc or ~/.bashrc worked for me
|
@stilren hopefully this is still somehow not too late. |
To all the windows powershell (10 or less?I don't use 11) users, the most effective workaround atm seems to be leveraging For instance, |
as of 2024-12-31, the suggested solution above: |
Issue
Current directory is not displayed. All tab titles display "Shell" regardless of which shell I am using (tried cmd and Bash on Ubuntu on Windows).
The text was updated successfully, but these errors were encountered: