-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprograms.sh
46 lines (37 loc) · 1013 Bytes
/
programs.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
# autocomplete of system-wide binaries
fn nash_complete_program(line, pos) {
var paths <= _nash_complete_programs_paths()
var choice, status <= (
find $paths -maxdepth 1 -type f -follow
>[2=] |
sed "s#/.*/##g" |
sort --unique |
fzf --query "^"+$line
--select-1
--exit-0
--header "Looking for system-wide binaries"
--prompt "(λ programs)>"
--reverse
)
if $status != "0" {
return ()
}
choice <= diffword($choice, $line)
return ($choice+" " "0")
}
fn _nash_complete_programs_paths() {
var path <= _nash_complete_programs_clean_path()
var paths <= split($path, ":")
var validPaths = ()
for path in $paths {
var _, status <= ls $path >[2=] /dev/null
if $status == "0" {
validPaths <= append($validPaths, $path)
}
}
return $validPaths
}
fn _nash_complete_programs_clean_path() {
var ret <= echo $PATH | sed "s/^://g" | sed "s/:$//g"
return $ret
}