-
Notifications
You must be signed in to change notification settings - Fork 0
/
default-command
112 lines (103 loc) · 5.24 KB
/
default-command
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#! /bin/sh -i
# set -x
#
type print > /dev/null 2>&1 ||
# Ruin the line numbers?
# alias print=$'printf "[%6.6d] %-$((${LENGTH_HEADER:-59} - 10))s \'%s\'\n" "$LINENO"'
alias print='printf "[%6.6d] %-$((${LENGTH_HEADER:-59} - 10))s '"'"'%s'"'"'\n" "$LINENO"'
[ -z "${ENV:+x}" ] || unset ENV
[ -n "${prefix_background:+x}" ] ||
prefix_background="$(\tmux showenv -gh prefix_background 2> /dev/null | awk -F = '{print $2}')"
# tmux display -p -d 0 "#[fill=white fg=white bg=black align=left][prefix-mode] [#{prefix_key} to enter prefix-mode] [#{prefix_key}-[ to enter copy-mode]"
# tmux display -p -d 0 "[prefix-mode] [#{prefix_key} to enter prefix-mode] [#{prefix_key}-[ to enter copy-mode]"
: "${TABSTOP:=4}" && export TABSTOP
indent=$((TABSTOP + 1))
[ -n "${prefix_key:+x}" ] ||
prefix_key="$(\tmux showenv -gh prefix_key 2> /dev/null | awk -F = '{print $2}')"
[ -n "${normal_key:+x}" ] ||
normal_key="$(\tmux showenv -gh normal_key 2> /dev/null | awk -F = '{print $2}')"
[ -n "${escape_key:+x}" ] ||
escape_key="$(\tmux showenv -gh escape_key 2> /dev/null | awk -F = '{print $2}')"
[ -n "${assist_key:+x}" ] ||
assist_key="$(\tmux showenv -gh assist_key 2> /dev/null | awk -F = '{print $2}')"
[ -n "${one_stage_policy:+x}" ] ||
one_stage_policy="$(\tmux showenv -gh one_stage_policy 2> /dev/null | awk -F = '{print $2}')"
[ -n "${is_reloading:+x}" ] ||
is_reloading="$(\tmux showenv -gh is_reloading 2> /dev/null | awk -F = '{print $2}')"
tput cup "$(tput lines)"
printf "%b%-${indent}s%-28s%s%b\n" "\033[1;042m" "" "copy-mode -- C-x" "toggle" "\033[0m" > "$TTY"
# prefix_key="$(tmux display -p "#{prefix_key}")"
[ "$prefix_key" = "Escape" ] &&
{
printf "%b%-${indent}s%-28s%s%b\n" "\033[1;042m" "" "copy-mode -- $escape_key-[/[" "enter/quit" "\033[0m" > "$TTY"
# print "$(printf "%b%s%b" "\033[1;042m" "copy-mode" "\033[0m")" "$(printf "%b%s%b" "\033[1;042m" "$escape_key-[ toggle" "\033[0m")"
[ -z "${assist_key:+x}" ] ||
printf "%b%-${indent}s%-28s%s%b\n" "\033[1;042m" "" "copy-mode -- $assist_key" "toggle on top of $escape_key" "\033[0m" > "$TTY"
# print "$(printf "%b%s%b" "\033[1;042m" "copy-mode" "\033[0m")" "$(printf "%b%s%b" "\033[1;042m" "\\$assist_key toggle on top of $escape_key" "\033[0m")"
} ||
{
[ "$normal_key" = "Escape" ] &&
printf "%b%-${indent}s%-28s%s%b\n" "\033[1;042m" "" "copy-mode -- $escape_key" "toggle" "\033[0m" > "$TTY" || :
}
# copy_tip="$(printf "%b%-${indent}s%s%b\n" "\033[1;042m" "" "copy-mode -- $prefix_key-[ (enter) | $prefix_key (quit)" "\033[0m")"
# tmux display -p "copy-mode -- $prefix_key-[ (enter) | $prefix_key (quit)"
# printf '%b%s%b\n' "\033[1;044m" "['[' to enter copy-mode when inside prefix-mode and $prefix_key ot quit]" "\033[0m"
# printf '%b%s%b\n' "\033[1;044m" "[prefix-mode -- $prefix_key (toggle) / Enter (exit)]" "\033[0m"
escape_on_root_event_exists() {
# /usr/bin/tmux switch-client -T prefix
# /usr/bin/tmux run -C "$(\tmux display -p '#{prefix_enter}')" # #{prefix_enter} might be empty
local escape_on_root_key_exists=1
while read -r line; do
[ "$line" = "escape_on_root" ] || continue
escape_on_root_key_exists=0
break
done < <(\tmux show -g command-alias | awk -F = '{print $1}' | awk -F " " '{ print $2}' | tr -d \")
return $escape_on_root_key_exists
}
# TTY="$(tty)"
rolling() {
exec < /dev/tty
[ -z "${IS_KISS:+x}" ] &&
trap 'return 0' INT TERM QUIT PIPE EXIT ||
trap 'return 0' INT TERM QUIT PIPE EXIT ERR
while
# case "$(tmux display -p "#{client_prefix}")" in
# "1") ;;
# *)
# break
# esac
[ "$(\tmux display -p "#{client_prefix}")" -eq 1 ] || return 0
do
# Can not quit ?
# tmux bind -T prefix "$prefix_key" ' if-shell true { switch-client -T root ; select-pane -P bg=terminal } '
sleep 0.75
[ "$prefix_key" = "Escape" ] &&
{
printf "%b%-${indent}s%-28s%s%b\r" "\033[1;044m" "" "prefix-mode -- $escape_key" "$([ "$one_stage_policy" -eq 1 ] && printf '%s' "toggle" || printf '%s' "prefix/copy")" "\033[0m" > "$TTY"
} || {
[ "$normal_key" = "Escape" ] && [ -n "${assist_key:+x}" ] &&
printf "%b%-${indent}s%-28s%s%b\r" "\033[1;044m" "" "prefix-mode -- $assist_key" "toggle on top of $escape_key" "\033[0m" > "$TTY" || :
}
# /usr/bin/tmux select-pane -P "bg=$prefix_background"
# /usr/bin/tmux set -p window-active-style bg=$prefix_background
sleep 0.75
[ "$prefix_key" = "Escape" ] &&
{
printf "%b%-${indent}s%-28s%s%b\r" "\033[1;007m" "" "prefix-mode -- $escape_key" "$([ "$one_stage_policy" -eq 1 ] && printf '%s' "toggle" || printf '%s' "prefix/copy")" "\033[0m" > "$TTY"
} || {
[ "$normal_key" = "Escape" ] && [ -n "${assist_key:+x}" ] &&
printf "%b%-${indent}s%-28s%s%b\r" "\033[1;007m" "" "prefix-mode -- $assist_key" "toggle on top of $escape_key" "\033[0m" > "$TTY" || :
}
# /usr/bin/tmux select-pane -P bg=terminal
# /usr/bin/tmux set -p window-active-style bg=terminal
done
}
! escape_on_root_event_exists ||
[ "$is_reloading" -eq 1 ] ||
{
/usr/bin/tmux run -C "escape_on_root"
(rolling & :)
# rolling
}
# \tmux send-prefix
# /usr/bin/tmux send-keys Escape