]> arthur.barton.de Git - ax-zsh.git/blob - core/10_terminal/10_terminal.zshrc
Use "autoload -Uz"
[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         if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then
36                 # Apple Terminal.app ...
37                 case "$cmd" in
38                   "mosh"*|"ssh"*|"telnet"*)
39                         # Reset CWD for remote commands
40                         printf '\e]7;%s\a' ''
41                         ;;
42                 esac
43         fi
44         axzsh_terminal_set_icon_title "$cmd"
45         axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST"
46 }
47
48 preexec_functions+=(axzsh_terminal_title_preexec)
49
50 # Colors
51
52 autoload -Uz colors
53 colors
54
55 # Text effects (FX)
56
57 typeset -Ag fx
58 fx=(
59         reset           "\e[00m"
60         bold            "\e[01m"
61         no-bold         "\e[22m"
62         italic          "\e[03m"
63         no-italic       "\e[23m"
64         underline       "\e[04m"
65         no-underline    "\e[24m"
66         blink           "\e[05m"
67         no-blink        "\e[25m"
68         reverse         "\e[07m"
69         no-reverse      "\e[27m"
70 )