-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathalmostontop.plugin.zsh
78 lines (63 loc) · 1.51 KB
/
almostontop.plugin.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
source "${0:h}/version"
if [ "x$ALMOSONTOP" = "xfalse" ]; then
# doing nothing here
else
ALMOSONTOP=true
fi
if [ "$ALMOSTONTOP_COLOR" = "" ]; then
ALMOSTONTOP_COLOR="green"
fi
function _accept_line_almostontop {
if [ "x$ALMOSONTOP" = "xtrue" ]; then
# 1. put cursor to the top of the screen
tput cup 0 0
# 2. redraw line with prompt and command (with highlighted text as well)
zle redisplay
fi
zle .accept-line
}
zle -N accept-line _accept_line_almostontop
function almostontop
{
# Help message if there no args
if [ $# -eq 0 ]; then
almostontop_usage
fi
local arg=$1
if [ "x$arg" = "xon" ]; then
ALMOSONTOP=true
fi
if [ "x$arg" = "xoff" ]; then
ALMOSONTOP=false
fi
if [ "x$arg" = "xtoggle" ]; then
almostontop_toggle
fi
}
function almostontop_toggle
{
if [ "x$ALMOSONTOP" = "xtrue" ]; then
almostontop off
else
almostontop on
fi
}
# Create widget so it could be bound with keys
zle -N almostontop_toggle almostontop_toggle
# "ctrl-X ctrl-L" to toggle almostontop, alike "ctrl-L" to clear screen
bindkey "^X^L" almostontop_toggle
function almostontop_usage
{
cat <<-EOF
Usage: almostontop <command>
Commands:
on Enables almostontop plugin
off Disables almostontop plugin
toggle Toggles almostontop plugin
Description:
almostontop clears previous command output every time before new command
executed in shell. Insipred by 'alwaysontop' plugin for bash:
https://github.com/swirepe/alwaysontop
Version: $ALMOSTONTOP_VERSION
EOF
}