-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanything-zsh-screen.zsh
89 lines (77 loc) · 1.95 KB
/
anything-zsh-screen.zsh
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
## screen and zsh side's functions.
# zle widget.
function anything-zsh-screen-hardcopy () {
command screen \
-X eval \
"hardcopy -h ${ANYTHING_ZSH_SCREEN_EXCHANGE}" \
'scrollback 0' \
'stuff "^U"' \
'stuff "cd ~/^M"' \
'stuff "^L"'
}
# specialized startup command
function anything-zsh-screen-rc () {
ANYTHING_ZSH_SCREEN_EXCHANGE=${1}
if [ -z ${ANYTHING_ZSH_SCREEN_EXCHANGE} ]; then
ANYTHING_ZSH_SCREEN_EXCHANGE=${HOME}/tmp/anything-zsh-screen-exchange
fi
zstyle ':completion:*' list-rows-first yes
zstyle ':completion:*' verbose yes
zstyle ':completion:*' list-separator '--'
zstyle ':completion:*' group-name ''
zstyle ':completion:*:descriptions' format '* %d'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*:corrections' format '%d (errors: %e)'
bindkey -e
zle -N anything-zsh-screen-hardcopy
bindkey '^X^X' anything-zsh-screen-hardcopy
bindkey '^I' complete-word
LISTMAX=-1
PS1='> '
}
## emacs side's functions.
function azs-run1 () {
local sessionname=${1}
local scrollback=${2}
shift 2
command screen -x ${sessionname} \
-X eval \
'stuff "^U"' \
"scrollback ${scrollback}" \
${argv}
}
function anything-zsh-screen-run () {
local exchange=${1}
local sessionname=${2}
local scrollback=${3}
local awaits=${4}
shift 4 # treat rest arguments as the screen commands.
rm -f ${exchange}
azs-run1 \
${sessionname} ${scrollback} \
${argv}
azs-run-await ${exchange} ${awaits}
return $?
}
function azs-run-await () {
local exchange=${1}
local awaits=${2-$((20))}
zmodload zsh/stat
local ret=-1
local size=-1
repeat ${awaits} ; do
if [[ -f ${exchange} ]]; then
builtin stat -H h ${exchange}
if (( ${size} == $h[size] )); then
ret=0
break;
else
size=$h[size]
fi
fi
sleep 0.01
ret=-1
done
return $ret
}