-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathshelix.sh
executable file
·236 lines (207 loc) · 7.98 KB
/
shelix.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/bash
# ╔-----------------------------------------------------------------------╗
# ║ ║
# ║ This file is part of the Shelix IDE. ║
# ║ Copyright (C) 2024 NVRM webdev23 https://github.com/webdev23 ║
# ║ ║
# ║ This program is free software: you can redistribute it and/or modify ║
# ║ it under the terms of the GNU General Public License as published by ║
# ║ the Free Software Foundation, either version 3 of the License, or ║
# ║ (at your option) any later version. ║
# ║ ║
# ║ This program is distributed in the hope that it will be useful, ║
# ║ but WITHOUT ANY WARRANTY; without even the implied warranty of ║
# ║ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ║
# ║ GNU General Public License for more details. ║
# ║ ║
# ║ You should have received a copy of the GNU General Public License ║
# ║ along with this program. If not, see <http://www.gnu.org/licenses/>. ║
# ╚-----------------------------------------------------------------------╝
export SHELIXPATH=$(dirname $(readlink -f $0))
export PATH="$SHELIXPATH/libs/:$PATH"
source $SHELIXPATH/env/utils.sh
USESESSION="$1"
logs() {
local message=$1
echo "$(date)" >> $SHELIXPATH/shelix.logs
echo $message >> $SHELIXPATH/shelix.logs
}
pwn() {
local session_name=$1
local session_path=$2
local commands=$3
local theme=$4
tmux new-session -d -s "$session_name" -c "$session_path"
# Write logs
logs "=== New Session === $session_name $session_path"
# tmux system config
tmux source ~/.tmux.conf
# override tmux config
# tmux config
tmux source $SHELIXPATH/env/tmux.conf.sh
# Store workdir path for later
tmux setenv SHELIXSESSIONDIR $session_path
# Panes layout
if [ "$commands" != "1" ];then
"$SHELIXPATH"/libs/layouts/base $session_path
else
"$SHELIXPATH"/libs/layouts/reactor $session_path $commands
fi
# Colors and ui
tmux_theme "$SHELIXPATH/themes/$theme.json" --session
# Maximize window
wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
sleep 0.5
# Attach to screen
tmux attach -t "$session_name"
}
# if [[ " $@ " =~ " --theme " ]] || ;then
# fi
if [[ " $@ " =~ " --install " ]];then
echo "Installing. See shelix.sh for details. "
# exit
ln -sf $SHELIXPATH/shelix.sh ~/.local/bin/shelix
# Place the shelix.desktop file somewhere it can be found by the OS
cp -f $SHELIXPATH/install/shelix.desktop ~/.local/share/applications/
# Add the shelix.desktop file
cp -f $SHELIXPATH/install/shelix-open.desktop ~/.local/share/applications/
# Icon
xdg-icon-resource install --size 128 $SHELIXPATH/shelix-ide.png
# Update the paths to the shelix and its icon in the shelix.desktop file(s)
sed -i "s|SHELIXPATH|$SHELIXPATH|g" ~/.local/share/applications/shelix*.desktop
# sed -i "s|Icon=SHELIXPATH|Icon=$SHELIXPATH/shelix.png|g" ~/.local/share/applications/shelix*.desktop
# sed -i "s|Exec=SHELIXPATH|Exec=$SHELIXPATH/shelix|g" ~/.local/share/applications/shelix*.desktop
exit
fi
if [[ " $@ " =~ " --uninstall " ]];then
echo "Cleaning down."
rm ~/.local/bin/shelix
rm ~/.local/share/applications/shelix.desktop
rm ~/.local/share/applications/shelix-open.desktop
xdg-icon-resource uninstall --size 128 shelix-ide.png
exit
fi
# @TODO improve command line param handling
if [[ " $@ " =~ " -l0 " ]]; then
"$SHELIXPATH"/libs/layouts/base
exit
fi
# STDIN
if [ -t 0 ]; then
: # null
else
if [[ " $@ " =~ " - " ]]; then
cat > /tmp/stdin.txt
tmux respawnp
tmux send "cd $SHELIXPATH && ./main -f /tmp/stdin.txt" ENTER
exit
fi
fi
# Parse commands -c
rm /tmp/commands.txt 2> /dev/null
COMMANDS=""
THEME="embers.dark"
# Commands feed
while [[ $# -gt 0 ]]; do
case "$1" in
-c)
if [[ -n $2 && $2 != -* ]]; then
echo "$2" >> /tmp/commands.txt
COMMANDS="1"
# echo "$2" >> COMMANDS
else
echo "Error: Missing or invalid value for -c parameter."
exit 1
fi
shift 2
;;
--theme) # Adding the new condition for --theme
if [[ -n $2 && $2 != -* ]]; then
THEME="$2"
else
echo "Error: Missing or invalid value for --theme parameter."
exit 1
fi
shift 2
;;
--help) # Adding the new condition for --theme
echo "$HELP"
exit
shift 2
;;
*)
shift
;;
esac
done
if [ "$TERM_PROGRAM" = tmux ]; then
# Shelix is ran under tmux, display the menu only
printf '\033]2;%s\033\\' 'shelix' # Pane title
# cd $SHELIXPATH && ./main
$SHELIXPATH/main
# cd $SHELIXPATH && ./main
else
echo -e "$head80"
echo -e "\033[0:5H$GNUV3"
echo -e "\033[17;0H=== Welcome to the Shelix IDE ==="
if [ -n "$USESESSION" ]; then
echo "::: $USESESSION"
if [ -e "$USESESSION" ] && [ -d "$USESESSION" ]; then
session_path="$USESESSION"
session_name="$(basename $USESESSION)"
echo "Session name = $session_name "
echo "Session path = $session_path "
else
session_name=$(basename $PWD)
session_path=$PWD
fi
else
session_name=$(basename $PWD)
session_path=$PWD
fi
# Check if a session already exists
if tmux has-session -t "$session_name" 2>/dev/null; then
printf '\033]2;%s\033\\' "Shelix - $session_name" # Terminal title
echo -e "Session \033[7m$session_name\e[0m already exists."
echo " ENTER Open session"
echo " K/k Kill and start a new $session_name session"
echo " R/r Extend $session_name on the right"
echo " L/l Extend $session_name on the left"
read -p "? " choice
case "$choice" in
"K" | "k")
# user pressed K/k
tmux kill-session -t "$session_name"
logs "=== Session killed === $session_name"
printf '\033]2;%s\033\\' "Shelix - $session_name" # Terminal title
echo "Killing and starting a new session..."
pwn "$session_name" "$session_path" "$COMMANDS" "$THEME"
;;
"R" | "r")
# user pressed R/r
echo "Extending session on the right..."
logs "=== Extend session on right === $session_name $PWD"
printf '\033]2;%s\033\\' "Shelix - $session_name"_R # Terminal title
pwn "$session_name"_R "$session_path" "$COMMANDS" "$THEME"
;;
"L" | "l")
# user pressed L/l
echo "Extending session on the left..."
logs "=== Extend session on left === $session_name $PWD"
printf '\033]2;%s\033\\' "Shelix - $session_name"_L # Terminal title
pwn "$session_name"_L "$session_path" "$COMMANDS" "$THEME"
;;
*)
# user pressed ENTER
echo "Opening session..."
logs "=== Session attached === $session_name"
printf '\033]2;%s\033\\' "Shelix - $session_name" # Terminal title
tmux attach -t "$session_name"
;;
esac
else
logs "=== New Session === $session_name $PWD"
printf '\033]2;%s\033\\' "Shelix - $session_name" # Terminal title
pwn "$session_name" "$session_path" "$COMMANDS" "$THEME"
fi
fi