-
Notifications
You must be signed in to change notification settings - Fork 0
/
rstudio
executable file
·39 lines (34 loc) · 1.07 KB
/
rstudio
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
#! /usr/bin/env zsh
rstudio() {
# Check if RStudio is available
if [ ! -x /Applications/RStudio.app ]; then
echo "RStudio could not be found at /Applications/RStudio.app."
return 1
fi
# Check if directory is provided as argument
local dir=${1:-.};
# Check if there is an .Rproj file
local files=( "$dir"/*.Rproj(N) )
# If there is exactly one .Rproj file
if [ $(($#files)) -eq 1 ]; then
echo "Opening $(basename "${files[1]}") in RStudio"
open -a RStudio "${files[1]}"
# If there is more than one .Rproj file
elif [ $(($#files)) -gt 1 ]; then
PS3="Select the project to open: "
select file in "${files[@]}"; do
if [ -n "$file" ]; then
echo "Opening $(basename "$file") in RStudio"
open -a RStudio "$file"
break
else
echo "Invalid selection."
fi
done
# If there are no .Rproj files
else
echo "No .Rproj file found, just launching RStudio"
open -a RStudio
fi
}
rstudio