-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrr
51 lines (42 loc) · 1.22 KB
/
rr
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
#!/bin/bash
# Isolate the command name
CommandName=$1
if [ -z "$CommandName" ]; then
echo Root Resolve
echo Usage: rr \<command\> [options]
exit 1
fi
# Shift the command name out of the options list for forwarding
shift
# Start in the current directory and search parent folders for rr.cfg
ConfigPath=`pwd`
while [[ $ConfigPath != / ]];
do
ConfigFilename=$ConfigPath/rr.cfg
if [ -f "$ConfigFilename" ]; then
break
fi
ConfigPath="$(readlink -f "$ConfigPath"/..)"
done
# Locate the root config file
if ! [ -f "$ConfigFilename" ]; then
echo ERROR: Can\'t find \'rr.cfg\'
exit 1
fi
# Parse config file potential command paths
while read -r line; do
# Swap \ with /, remove newline and append to the root path
line="${line//\\/\/}"
line=`echo $line | tr -d '\r'`
CommandPath=$ConfigPath/$line
# Combine tentative command path, command name and all possible extensions to locate the command
Extensions=" .sh .bat .cmd .exe"
for extension in $Extensions; do
Command=$CommandPath/$CommandName$extension
if [ -f "$Command" ]; then
$Command "$@"
exit $?
fi
done
done <$ConfigFilename
echo Command \'$CommandName\' not found.