hyper
hyper copied to clipboard
Tab titles don't reflect current directory or process running
- OS version and name: Windows 10 64bit
- Hyper.app version: 1.0.0
- Link of a Gist with the contents of your .hyper.js: hyper.js gist
- Relevent information from devtools: N/A
- The issue is reproducible in vanilla Hyper.app: Reproducible in vanilla
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).
This is true of macOS too.
@audunolsen in version 1.0.0?
I assumed it was Windows only because of this notice: https://github.com/parro-it/hyperterm-title/issues/5
Yes.
![screenshot 2016-12-14 01 12 42](https://cloud.githubusercontent.com/assets/16224137/21164615/8cd5f4fa-c19a-11e6-963c-e1b3fcb786ca.png)
Tab titles doesn't reflect directory or process running.
I stole your comment for a better issue title :)
Hi, since my plugin hyperterm-title
is now embedded in core, tabs title is now managed directly by your shell. There is a special escape sequence command that is meant to set terminal title.
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 The cwd or current foreground process instead was not trivial, previous hyper versions uses a polling procedure that is too resource heavy...
@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?
For what's it worth, on Windows, Cmder is capable of pulling the cwd, it might be possible to learn how they do it. Although it is only relevant to Windows terminals (ie. CMD and PowerShell) - as it doesn't work with the native Bash on Windows
I found this issue there: https://github.com/cmderdev/cmder/issues/815. Seems they are using terminal escape codes too to set the title... but I'm not sure. /cc @samvasko @Stanzilla @MartiUK @Jackbennett
This is my linux terminal, with two tabs running bash
:
It display current shell user and name of the shell. I had to comment lines on my .bashrc
that set the title using escape codes. The window title reflect that of the current tab.
I think this behavior could be acceptable for hyper too...
@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 echo -ne '\e]0;HelloCmder\a'
is working for you in your Linux shells? Then we could narrow it down to a single, cross-OS method
Edit: Would be better to just include the code from the link here: PowerShell:
$host.ui.RawUI.WindowTitle = "HelloCmder"
cmd:
title HelloCmder
bash:
echo -ne '\e]0;HelloCmder\a'
Can you check if echo -ne '\e]0;HelloCmder\a' is working for you in your Linux shells? Then we could narrow it down to a single, cross-OS method
It work, that is exactly the escape code we use to set tab title on hyper :smile:.
If you set your prompt to contains the same escape, you can get replace HelloCmder
with your CWD, and you get cwd on the title:
The tab on the right is running bash without custom prompt, the tab on the left is running zsh with pure
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: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html
@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 :)
@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.
PS1="\[\033]0;\w\007\]>"
@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 PS1="\[\033]0;\w\007\]>"
had no effect.
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. How do I get tab titles like the one in your GIF?
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 .bashrc
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 title My new title
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. my tabs are showing the correct command on hyper 1.4.3 on mac. but instead of "ng serve" I'd like something like 'myProject-ui' and the other tab could be 'myProject-service' instead of just 'node index.js' so is it posible to manually set title just the way you want?
@luismasg @achekulaev's solution seemd perfect for your needs
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.
![screenshot 2017-09-27 19 56 20](https://user-images.githubusercontent.com/16224137/30929251-3b080a8a-a3be-11e7-83b5-85f53501b5ed.png)
# ~/.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 ($ title My new title
), remove the static title with $ autotitle
.
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: https://github.com/mridgers/clink/pull/464
Something about the new conhost. https://github.com/Stanzilla/clink/commit/4217e6defd3914e338c3597c168f88ae54111e51
I'm running into an issue while using @audunolsen 's zsh script. My titles come out as %15<..<
, am I missing something simple?
@mackmmiller: I'm using zsh version 5.3 (x86_64-apple-darwin17.0)
. I don't use zsh in conjunction with any other framework, e.g. oh-my-zsh, if you are, then maybe there's some clash there.
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.
Took me a good hour to get to this point though.
It might me worthy to note that ohmyzsh has an implementation of title()
itself, which got me really confused at first: https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/termsupport.zsh
After working with @audunolsen 's solution a bit, I realized there's one problem. Using precmd()
and preexec()
directly causes conflicts with other zsh plugins which are also using these hooks. In my case, the git plugin wouldn't show the repo status anymore since its hooks were overridden by our tab title functions.
I managed to solve it, thanks to a similar solution posted in https://github.com/direnv/direnv/issues/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. $_ pretty much always contains show_command_in_title_bar.
Seems like this helps.
![screen shot 2018-03-14 at 9 18 22 pm](https://user-images.githubusercontent.com/17213165/37441127-d4e3192c-27cd-11e8-9ada-43936f6090b0.png)
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 https://github.com/zeit/hyper/issues/1188#issuecomment-359015977 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 DISABLE_AUTO_TITLE="true"
in my ~/.zshrc to make it work again.
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
function title() { echo -e "\033]0;$(basename $PWD)" }
$host.UI.RawUI.WindowTitle = Get-Location
@stilren hopefully this is still somehow not too late.
It's $(Get-Location)
instead of Get-Location
.
To all the windows powershell (10 or less?I don't use 11) users, the most effective workaround atm seems to be leveraging $Host.UI.RawUI.WindowTitle
by a PS profile.
For instance, $host.UI.RawUI.WindowTitle = $(Get-Location)
would set the PS window title bar (which is inherited by the tabs extensions of hyper terminal) to the working directory at the time the command is run.
If you want the tab/window title to update put the line in the prompt
function.