-
Notifications
You must be signed in to change notification settings - Fork 0
/
all.sh
84 lines (60 loc) · 1.26 KB
/
all.sh
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
# nash-complete
import deps
import common
import kill
import systemd
import history
import files
import programs
var OS <= uname -s
var sedArgs = "-r"
if $OS == "Darwin" {
sedArgs = "-E"
}
var NASHCOMPLETE_CMD = (
("kill" $nash_complete_kill)
("systemctl" $nash_complete_systemctl)
)
fn nash_complete_args(parts, line, pos) {
if len($parts) == "0" {
return ()
}
var cmd = $parts[0]
for completecmd in $NASHCOMPLETE_CMD {
var name = $completecmd[0]
var callback = $completecmd[1]
var ret = ""
if $cmd == $name {
var ret <= $callback($parts, $line, $pos)
return $ret
}
}
ret <= nash_complete_paths($parts, $line, $pos)
return $ret
}
fn nash_complete(line, pos) {
var ret = ""
if $line == "" {
# search in the history
ret <= nash_complete_history()
return $ret
}
var parts <= split($line, " ")
if len($parts) == "0" {
# not sure when happens
return ()
} else if len($parts) == "1" {
var _, status <= echo $line | grep "^\\." >[1=]
if $status == "0" {
ret <= nash_complete_paths($parts, $line, $pos)
return $ret
}
var _, status <= echo $line | grep " $" >[1=]
if $status != "0" {
ret <= nash_complete_program($line, $pos)
return $ret
}
}
ret <= nash_complete_args($parts, $line, $pos)
return $ret
}