-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfiles.sh
89 lines (71 loc) · 1.52 KB
/
files.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
85
86
87
88
89
# Autocomplete of files
fn nash_complete_paths(parts, line, pos) {
var choice = ""
var dir = ""
var dirpath = ""
var findArgs = ()
var fname = ""
var last = ""
var lastpart = ""
var partsz = ""
var status = ""
partsz <= len($parts)
last, _ <= expr $partsz - 1
last <= trim($last)
lastpart, _ <= echo -n $parts[$last] | sed $sedArgs "s#^~#"+$HOME+"#g"
var _, status <= test -d $lastpart
if $status == "0" {
# already a directory
var _, status <= echo -n $lastpart | grep "/$" >[1=]
# complete with '/' if it wasnt given
if $status != "0" {
return ("/" "0")
}
dir <= echo $lastpart | sed $sedArgs "s#/$##g"
dirpath = $dir+"/"
fname = ""
} else {
dir <= dirname $lastpart | tr -d "\n"
if $dir != "/" {
dirpath = $dir+"/"
} else {
dirpath = $dir
}
fname <= basename $lastpart | tr -d "\n"
}
if $fname == "/" {
fname = ""
}
var _, status <= test -d $dir
if $status != "0" {
# autocompleting non-existent directory
return ()
}
if $parts[0] == "cd" {
findArgs = ("-type" "d")
}
choice, status <= (
find $dir -maxdepth 1 $findArgs |
sed "s#"+$dirpath+"##g" |
fzf -q "^"+$fname
-1
-0
--header "Looking for path"
--prompt "(λ path)>"
--reverse
|
tr -d "\n"
)
if $status != "0" {
return ()
}
var _, status <= test -d $dir+$choice
if $status == "0" {
var _, status <= echo $choice | grep "/$" >[1=]
if $status != "0" {
choice = $choice+"/"
}
}
choice <= diffword($choice, $fname)
return ($choice "0")
}