From e56ca195f7351d037ddbb4f33ea646116e00073f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20P=C5=82azie=C5=84ski?= Date: Tue, 27 Feb 2024 20:57:20 +0100 Subject: [PATCH] Move screen support to partial --- zsh.d/screen.zsh | 54 +++++++++++++++++++++++++++++++++++++++++++++++ zshrc | 55 ------------------------------------------------ 2 files changed, 54 insertions(+), 55 deletions(-) create mode 100644 zsh.d/screen.zsh diff --git a/zsh.d/screen.zsh b/zsh.d/screen.zsh new file mode 100644 index 0000000..8379f62 --- /dev/null +++ b/zsh.d/screen.zsh @@ -0,0 +1,54 @@ +# vim: ft=zsh + +function title { + # param: title to use + + local prefix='' + + # If I'm in a screen, all the windows are probably on the same machine, so + # I don't really need to title every single one with the machine name. + # On the other hand, if I'm not logged in as me (but, e.g., root), I'd + # certainly like to know that! + if [[ $USER != "$DEFAULT_USER" ]]; then + prefix="[$USER] " + fi + # Set screen window title + if [[ $TERM == "screen"* ]]; then + print -n "\ek$prefix$1\e\\" + fi + + # Prefix the xterm title with the current machine name, but only if I'm not + # on a local machine. This is tricky, because screen won't reliably know + # whether I'm using SSH right now! So just assume I'm local iff I'm not + # running over SSH *and* not using screen. Local screens are fairly rare. + prefix=$HOST + if [[ $SSH_CONNECTION == '' && $TERM != "screen"* ]]; then + prefix='' + fi + # If we're showing host and not default user prepend it + if [[ $prefix != '' && $USER != "$DEFAULT_USER" ]]; then + prefix="$USER@$prefix" + fi + # Wrap it in brackets + if [[ $prefix != '' ]]; then + prefix="[$prefix] " + fi + + # Set xterm window title + if [[ $TERM == "xterm"* || $TERM == "screen"* ]]; then + print -n "\e]2;$prefix$1\a" + fi +} + +function title_precmd { + # Shorten homedir back to '~' + local shortpwd=${PWD/$HOME/\~} + title "zsh $shortpwd" +} + +function title_preexec { + title $* +} + +add-zsh-hook preexec title_preexec +add-zsh-hook precmd title_precmd diff --git a/zshrc b/zshrc index cb57dfc..b0d6064 100644 --- a/zshrc +++ b/zshrc @@ -372,61 +372,6 @@ function +vi-git-additional() { fi } -#---------------------------------- Screen ------------------------------------ - -function title { - # param: title to use - - local prefix='' - - # If I'm in a screen, all the windows are probably on the same machine, so - # I don't really need to title every single one with the machine name. - # On the other hand, if I'm not logged in as me (but, e.g., root), I'd - # certainly like to know that! - if [[ $USER != "$DEFAULT_USER" ]]; then - prefix="[$USER] " - fi - # Set screen window title - if [[ $TERM == "screen"* ]]; then - print -n "\ek$prefix$1\e\\" - fi - - # Prefix the xterm title with the current machine name, but only if I'm not - # on a local machine. This is tricky, because screen won't reliably know - # whether I'm using SSH right now! So just assume I'm local iff I'm not - # running over SSH *and* not using screen. Local screens are fairly rare. - prefix=$HOST - if [[ $SSH_CONNECTION == '' && $TERM != "screen"* ]]; then - prefix='' - fi - # If we're showing host and not default user prepend it - if [[ $prefix != '' && $USER != "$DEFAULT_USER" ]]; then - prefix="$USER@$prefix" - fi - # Wrap it in brackets - if [[ $prefix != '' ]]; then - prefix="[$prefix] " - fi - - # Set xterm window title - if [[ $TERM == "xterm"* || $TERM == "screen"* ]]; then - print -n "\e]2;$prefix$1\a" - fi -} - -function title_precmd { - # Shorten homedir back to '~' - local shortpwd=${PWD/$HOME/\~} - title "zsh $shortpwd" -} - -function title_preexec { - title $* -} - -add-zsh-hook preexec title_preexec -add-zsh-hook precmd title_precmd - #---------------------------------- Aliases ---------------------------------- # Use interactive sudo instead of su