-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen-dotnet-folder.sh
executable file
·65 lines (55 loc) · 2.6 KB
/
open-dotnet-folder.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
#!/bin/bash
source "./cmake-scripts/get-platform.sh"
case "$simpleOSName" in
"Windows")
# NOTE: We could've used something like:
# which dotnet | xargs dirname
# But if the folder path contains spaces, it xargs will send 2+ args over to the dirname command.
# To fix this, use:
# which dotnet | xargs -I {} dirname "{}"
# The -I specifies that the replacement string, {}, will be replaced by the input (the result of the "which dotnet" command).
# The quotes around {} allow us to take that entire command output from "which dotnet", and put quotes around them like we normally would, to make it 1 arg.
# However, on Windows/Git Bash environments, the "/c/Program Files" (POSIX) style of file paths don't work with explorer.exe.
# Luckily, there's a "cygwin -w" command to convert to Windows-style file paths that explorer.exe works with,
# But the previously-simple, 1-line command, was getting out of hand.
# Therefore, I wrote this bash script instead.
folderPath="$(which dotnet)"
folderPath="$(dirname "$folderPath")"
folderPath="$(cygpath -w "$folderPath")"
explorer "$folderPath"
;;
"MacOS")
# which dotnet | xargs -I {} dirname "{}" | xargs open
folderPath="$(which dotnet)"
if [[ $folderPath == "" ]]; then
printf ".NET SDK (\"dotnet\") not found in command-line.\nIt's either not installed, or just not in your \$PATH variable.\n"
exit 1
fi
folderPath="$(dirname "$folderPath")"
open "$folderPath"
printf "Found .NET SDK in the folder:\n $folderPath\n"
;;
"Linux")
if [[ $isRaspberryPi ]]; then
folderPath="$(which dotnet)"
if [[ $folderPath == "" ]]; then
printf ".NET SDK (\"dotnet\") not found in command-line.\nIt's either not installed, or just not in your \$PATH variable.\n"
exit 1
fi
folderPath="$(dirname "$folderPath")"
open "$folderPath"
printf "Found .NET SDK in the folder:\n $folderPath\n"
else
folderPath="$(which dotnet)"
if [[ $folderPath == "" ]]; then
printf ".NET SDK (\"dotnet\") not found in command-line.\nIt's either not installed, or just not in your \$PATH variable.\n"
exit 1
fi
folderPath="$(dirname "$folderPath")"
nautilus "$folderPath"
printf "Found .NET SDK in the folder:\n $folderPath\n"
fi
;;
"Unknown")
;;
esac