-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojectline.sh
executable file
·130 lines (103 loc) · 2.94 KB
/
projectline.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/bash
# helpers
bold=$(tput bold)
red="\e[31m"
yellow="\e[33m"
green="\e[32m"
normal=$(tput sgr0)
# Default variables
projects_path=~/projects
config_file=~/.config/projectline/config.sh
usage="${green}projectline${normal}: program to set the environment for a project
${yellow}USAGE:${normal}
projectline [OPTIONS]
${yellow}OPTIONS:${normal}
${green}-h ${normal} Print this help message
${green}-c <FILE>${normal} Set config file (default: ~/.config/projectilne/config.sh)
${green}-p <PATH>${normal} Set projects path (default: ~/projects)"
if test -f "${config_file}" ; then
source "${config_file}"
else
echo -e "${bold}${yellow}WARNING:${normal} config file doesn't exists. Loading defaults"
fi
while getopts ':hc:p:' option; do
case "${option}" in
h) echo -e "$usage"
exit 0
;;
c) config_file=$OPTARG
;;
:) echo -e "${bold}${red}ERROR:${normal} missing argument for -${OPTARG}" >&2
exit 1
;;
p) projects_path=$OPTARG
;;
:) echo -e "${bold}${red}ERROR:${normal} missing argument for -${OPTARG}" >&2
exit 1
;;
\?) echo -e "${bold}${red}ERROR:${normal} illegal option: -${OPTARG}" >&2
exit 1
;;
esac
done
if [ "${projects_path: -1}" != "/" ]; then
projects_path+="/"
fi
[ ! -d "$projects_path" ] && echo -e "${bold}${red}ERROR:${normal} '$projects_path' doesn't exists." && exit 1
cd $projects_path
project_path=$projects_path
project_relative_path=$(FZF_DEFAULT_COMMAND="fd -H -t d '\.git$' --prune ./ | sed 's#/.git##'" fzf --bind "change:reload:fd -H -t d '\.git$' --prune ~/proyectos| sed 's#/.git##' {q} || true" --ansi --phony --query "")
if [ -z "$project_relative_path" ]; then
exit 0
fi
project_path+=$project_relative_path
project_name=$(basename $project_path)
cd $project_path
if [ $(type -t before) ]; then
before
else
echo -e "${bold}${yellow}WARNING:${normal} before() not found. Executing default"
tmux new -d -s $project_name -n editor
fi
if [ $(type -t onRust) ]; then
if test -e "Cargo.toml"; then
onRust
fi
fi
if [ $(type -t onNode) ]; then
if test -e "package.json"; then
onNode
fi
fi
if [ $(type -t onPython) ]; then
if test -e "requirements.txt"; then
onPython
fi
fi
if [ $(type -t onDocker) ]; then
if test -e "Dockerfile"; then
onDocker
fi
fi
if [ $(type -t onDockerCompose) ]; then
if test -e "docker-compose.yml" || test -e "docker-compose.yaml"; then
onDockerCompose
fi
fi
if [ $(type -t onCmake) ]; then
if test -e "CMakeLists.txt"; then
onCmake
fi
fi
if [ $(type -t onGo) ]; then
if test -e "go.mod"; then
onGo
fi
fi
if [ $(type -t after) ]; then
after
else
echo -e "${bold}${yellow}WARNING:${normal} after() not found. Executing default"
tmux a -t $project_name
fi
exit 0