]> arthur.barton.de Git - ax-zsh.git/blob - core/10_terminal/10_terminal.zshrc
f2665b6e5eb9578213f60b7adac319acf5689a6b
[ax-zsh.git] / core / 10_terminal / 10_terminal.zshrc
1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # 10_terminal.zshrc: Initialize terminal settings
3
4 # Set terminal title
5
6 # Set terminal "hardstatus" and "icon title"
7 function axzsh_terminal_set_icon_title {
8         [[ "$TERM" == "screen"* ]] && printf '\ek%s\e\\' "$1"
9         printf '\e]1;%s\a' "$1"
10 }
11
12 # Set terminal window title
13 function axzsh_terminal_set_window_title {
14         printf '\e]2;%s\a' "$1"
15 }
16
17 # Update terminal titles befor echoing the shell prompt
18 function axzsh_terminal_title_precmd {
19         axzsh_terminal_set_icon_title 'zsh'
20         if [[ "$TERM_PROGRAM" == "Apple_Terminal" && "$TERM" != "screen"* ]]; then
21                 axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST"
22                 # Update CWD in Terminal.app
23                 local url=$(echo "file://$HOSTNAME$PWD" | sed -e 's| |%20|g')
24                 printf '\e]7;%s\a' "$url"
25         else
26                 axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST:$PWD"
27         fi
28 }
29
30 precmd_functions+=(axzsh_terminal_title_precmd)
31
32 # Update terminal titles befor executing a command
33 function axzsh_terminal_title_preexec {
34         local cmd="${1[(w)1]}"
35         local remote=""
36         case "$cmd" in
37           "mosh"*|"ssh"*|"telnet"*)
38                 remote=1
39                 ;;
40         esac
41         if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then
42                 # Apple Terminal.app ...
43                 if [[ -n "$remote" ]]; then
44                         # Reset CWD for remote commands
45                         printf '\e]7;%s\a' ''
46                 fi
47         fi
48         axzsh_terminal_set_icon_title "$cmd"
49
50         [[ -z "$remote" ]] \
51                 && axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST$TITLE_ADD" \
52                 || axzsh_terminal_set_window_title "$1"
53 }
54
55 preexec_functions+=(axzsh_terminal_title_preexec)
56
57 # Colors
58
59 autoload -Uz colors
60 colors
61
62 # Text effects (FX)
63
64 typeset -Ag fx
65 fx=(
66         reset           "\e[00m"
67         bold            "\e[01m"
68         no-bold         "\e[22m"
69         italic          "\e[03m"
70         no-italic       "\e[23m"
71         underline       "\e[04m"
72         no-underline    "\e[24m"
73         blink           "\e[05m"
74         no-blink        "\e[25m"
75         reverse         "\e[07m"
76         no-reverse      "\e[27m"
77 )