-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathref
More file actions
executable file
·47 lines (36 loc) · 910 Bytes
/
Copy pathref
File metadata and controls
executable file
·47 lines (36 loc) · 910 Bytes
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
#!/usr/bin/bash
prefix="${PREFIX:-/usr}/share/ref"
cmd="$1"
filename="$2"
function search_target(){
local find_result=$(find $prefix -type f -regex ".*/$1.md")
local target
if [ -z "$find_result" ];then
find_result=$(find $prefix -type f -regex ".*/$1")
fi
if [ $(echo "$find_result" | wc -l) -gt 1 ] && [ -t 0 ] ; then
select target in $find_result; do
if [ -n "$target" ]; then
echo "$target"
break
else
echo "Invalid selection."
fi
done
else
echo "$find_result" | head -n 1
fi
}
if [ -z "$cmd" ] || [ -z "$filename" ]; then
echo "available filename:"
echo "$(find $prefix -type f -regex ".*" -printf "%f\n")"
echo ""
echo "Usage: $0 <command> <filename>"
echo "e.g.: $0 echo cpp"
echo "e.g.: ls -l $($0 echo cpp)"
echo "e.g.: $0 nvim cpp"
echo "e.g.: $0 glow cpp"
echo "e.g.: $0 microsoft-edge-stable cpp"
else
"$cmd" $(search_target "$filename")
fi