forked from alessandro-g89/bash-sessions
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbash_sessions
More file actions
executable file
·566 lines (475 loc) · 17.2 KB
/
bash_sessions
File metadata and controls
executable file
·566 lines (475 loc) · 17.2 KB
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
#!/bin/bash
# bash_sessions - Session manager for the Bash shell
#
# Copyright (C) 2016 Alessandro Grassi <alessandro.g89@gmail.com>
#
# 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/>.
BASH_SESSIONS_DIR="${HOME}/.bash_sessions"
BASH_SESSIONS_TEMP_DIR="/tmp/.bash_sessions/"
BASH_SESSIONS_MAXIMUM_OUTPUT_LINES="1000"
__bs_savepwd(){
# check that we are inside a session
[ -z "${BASH_SESSION_NAME}" ] && return
# check that the target directory exists
[ -d "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}" ] || return
# save current working directory to a file
if [ "${PWD}" != "${PREV_PWD}" ]; then
PREV_PWD="${PWD}"
echo "${PWD}" > "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/pwd"
fi
}
# save changes to the environment
__bs_saveenv(){
# check that we are inside a session
[ -z "${BASH_SESSION_NAME}" ] && return
# check that the target directory exists
[ -d "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}" ] || return
# check that temp dir exists
[ -d "${BASH_SESSIONS_TEMP_DIR}/${BASH_SESSION_NAME}" ] || mkdir -p "${BASH_SESSIONS_TEMP_DIR}/${BASH_SESSION_NAME}"
# save changes to the environment in a file
cat "/proc/$$/environ" | tr '\0' '\n' | sort | grep "=" > "${BASH_SESSIONS_TEMP_DIR}/${BASH_SESSION_NAME}/initial_env"
env | sort | grep "=" > "${BASH_SESSIONS_TEMP_DIR}/${BASH_SESSION_NAME}/current_env"
diff --new-line-format=%L --old-line-format= --unchanged-line-format= \
"${BASH_SESSIONS_TEMP_DIR}/${BASH_SESSION_NAME}/initial_env" \
"${BASH_SESSIONS_TEMP_DIR}/${BASH_SESSION_NAME}/current_env" \
| egrep -v "(^PATH=|^PROMPT_COMMAND=|^SHLVL=|^COMP_WORDBREAKS=|^PWD=|^HISTFILE=|^_=)" > "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/env_changed"
diff --new-line-format= --old-line-format=%L --unchanged-line-format= \
"${BASH_SESSIONS_TEMP_DIR}/${BASH_SESSION_NAME}/initial_env" \
"${BASH_SESSIONS_TEMP_DIR}/${BASH_SESSION_NAME}/current_env" \
| egrep -v "(^PATH=|^PROMPT_COMMAND=|^SHLVL=|^COMP_WORDBREAKS=|^PWD=|^HISTFILE=|^_=)" | cut -d = -f 1 > "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/env_deleted"
}
# create and activate a new session
n (){
# check number of arguments
if [ "$#" -ne 1 ]; then
echo "Error: ${FUNCNAME[0]}() requires exactly 1 argument"
return
fi
# create sessions directory if needed
[ -d "${BASH_SESSIONS_DIR}" ] || mkdir -p "${BASH_SESSIONS_DIR}"
# check session not existing already
if [ -d "${BASH_SESSIONS_DIR}/${1}" ]; then
echo "Error: session \"${1}\" already exists"
return
fi
# quit current session, if any
if [ -n "${BASH_SESSION_NAME}" ]; then
echo "Error: close current session first"
return
fi
# create directory for new session
[ -d "${BASH_SESSIONS_DIR}/${1}" ] || mkdir -p "${BASH_SESSIONS_DIR}/${1}"
# copy last part of current history to new session
tail -n 100 "${HISTFILE}" > "${BASH_SESSIONS_DIR}/${1}/history"
# enable tracking working directory
touch "${BASH_SESSIONS_DIR}/${1}/pwd"
# activate new session
o "${1}"
}
# activate an existing session
o (){
# check number of arguments
if [ "$#" -ne 1 ]; then
echo "Error: ${FUNCNAME[0]}() requires exactly 1 argument"
return
fi
# create sessions directory if needed
[ -d "${BASH_SESSIONS_DIR}" ] || mkdir -p "${BASH_SESSIONS_DIR}"
# check that session exists
if ! [ -d "${BASH_SESSIONS_DIR}/$1" ]; then
echo "Error: session \"$1\" does not exist"
return
fi
# quit current session, if any
if [ -n "${BASH_SESSION_NAME}" ]; then
echo "Error: close current session first"
return
fi
# check that the session is not already in use
if lsof "${BASH_SESSIONS_DIR}/$1/output" &> /dev/null; then
echo "Error: session \"$1\" is already in use!"
return
fi
# set session name
export BASH_SESSION_NAME="${1}"
# check that temp dir exists
[ -d "${BASH_SESSIONS_TEMP_DIR}/${BASH_SESSION_NAME}" ] || mkdir -p "${BASH_SESSIONS_TEMP_DIR}/${BASH_SESSION_NAME}"
# create script to activate session
echo '
# load global settings
[ -f /etc/bash.bashrc ] && . /etc/bash.bashrc
# load local settings
[ -f ~/.bashrc ] && . ~/.bashrc
# switch to dedicated history file
if [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/history" ]; then
history -c
export BASH_SESSIONS_OLD_HISTFILE="${HISTFILE}"
export HISTFILE="${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/history"
fi
# switch to working directory
if [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/pwd" ]; then
cd "$(cat "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/pwd")"
export PROMPT_COMMAND="${PROMPT_COMMAND:+;}__bs_savepwd"
fi
# load environment
if [[ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/env_changed" || -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/env_deleted" ]]; then
while read line; do
export $line;
done < "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/env_changed"
while read line; do
unset $line;
done < "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/env_deleted"
export PROMPT_COMMAND="${PROMPT_COMMAND};__bs_saveenv"
fi
' > "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/bashrc"
# add newline to output if needed
[ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/loaded" ] && echo >> "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output"
# load old output from file
if [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output" ]; then
if [ $(wc -l "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output" | cut -f 1 -d " ") -ge ${BASH_SESSIONS_MAXIMUM_OUTPUT_LINES} ]; then
tail -n ${BASH_SESSIONS_MAXIMUM_OUTPUT_LINES} "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output" > "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output.tail"
mv "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output.tail" "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output"
fi
cat "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output"
fi
# the session is executed inside script, to save the output to a file if desired, with a lock on "loaded" to mark the session as active
if [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output" ]; then
BASH_SESSION_OUTPUT_FILE="${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output"
else
BASH_SESSION_OUTPUT_FILE="/dev/null"
fi
(
flock -n 9 || exit 1
script -a -q "${BASH_SESSION_OUTPUT_FILE}" -c "bash --rcfile \"${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/bashrc\""
) 9>"${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/loaded"
#everything that follows happens after the session is closed
# delete temporary files
rm -f "${BASH_SESSIONS_TEMP_DIR}/${BASH_SESSION_NAME}/"*
# limit the length of saved output
if [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output" ]; then
if [ $(wc -l "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output" | cut -f 1 -d " ") -ge ${BASH_SESSIONS_MAXIMUM_OUTPUT_LINES} ]; then
tail -n ${BASH_SESSIONS_MAXIMUM_OUTPUT_LINES} "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output" > "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output.tail"
mv "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output.tail" "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output"
fi
fi
# mark session as unloaded
[ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/loaded" ] && rm -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/loaded"
unset BASH_SESSION_NAME
}
# try to recover previously unterminated session
__bs_recover()
{
# don't recover if we have a session active
[ -n "${BASH_SESSION_NAME}" ] && return
# temporarily set nullglob
local changed_nullglob
shopt -u | grep -q nullglob && changed=true && shopt -s nullglob
local IFS="$(printf '\n\t')" # remove space
# find first previously loaded session
for session_path in "${BASH_SESSIONS_DIR}"/*/loaded; do break; done
# without nullglob, we would get the original globbing pattern if no session was found
[ -z "${session_path}" ] && return
# extract session name from the absolute path
local session_dir="${session_path%/*}"
local recovered_session_name="${session_dir##*/}"
[ $changed ] && shopt -u nullglob; unset changed
# find PID of our session's script instance and kill it to unblock our session so that we can reopen it
for session_pid in $(lsof -c script -t "${BASH_SESSIONS_DIR}/${recovered_session_name}/" >&/dev/null); do
kill ${session_pid}
done \
&& o "${recovered_session_name}"
}
# execute recovery as the script is being loaded
__bs_recover
# exit active session
c (){
# check number of arguments
if [ "$#" -ne 0 ]; then
echo "Error: ${FUNCNAME[0]}() does not accept arguments"
return
fi
# check that we are in a session
if [ -z "${BASH_SESSION_NAME}" ]; then
echo "No session active!"
return
fi
exit &>/dev/null
}
# delete an existing session
f (){
# check number of arguments
if [ "$#" -ne 1 ]; then
echo "Error: ${FUNCNAME[0]}() requires exactly 1 argument"
return
fi
# check that we are not in a session
if [ -n "${BASH_SESSION_NAME}" ]; then
echo "Exit current session first!"
return
fi
# check if session exists
if ! [ -d "${BASH_SESSIONS_DIR}/$1" ]; then
echo "Session \"$1\" does not exist!"
return
fi
# ask confirmation and delete session
read -p "Delete session \"$1\"? [yN] " -n 1 -r
echo
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
rm -f -r "${BASH_SESSIONS_DIR}/$1"
echo "Session \"$1\" deleted"
fi
}
# rename an existing session
r (){
# check number of arguments
if [ "$#" -ne 2 ]; then
echo "Error: ${FUNCNAME[0]}() requires exactly 2 arguments"
return
fi
# check that we are not in a session
if [ -n "${BASH_SESSION_NAME}" ]; then
echo "Exit current session first!"
return
fi
# check if source session exists
if ! [ -d "${BASH_SESSIONS_DIR}/$1" ]; then
echo "Session \"$1\" does not exist!"
return
fi
# check if destination session exists
if [ -d "${BASH_SESSIONS_DIR}/$2" ]; then
echo "Session \"$2\" already exists!"
return
fi
mv "${BASH_SESSIONS_DIR}/$1" "${BASH_SESSIONS_DIR}/$2"
echo "Session \"$1\" renamed to \"$2\""
}
# duplicate an existing session
b (){
# check number of arguments
if [ "$#" -ne 2 ]; then
echo "Error: ${FUNCNAME[0]}() requires exactly 2 arguments"
return
fi
# check that we are not in a session
if [ -n "${BASH_SESSION_NAME}" ]; then
echo "Exit current session first!"
return
fi
# check if source session exists
if ! [ -d "${BASH_SESSIONS_DIR}/$1" ]; then
echo "Session \"$1\" does not exist!"
return
fi
# check if destination session exists
if [ -d "${BASH_SESSIONS_DIR}/$2" ]; then
echo "Session \"$2\" already exists!"
return
fi
cp -R "${BASH_SESSIONS_DIR}/$1" "${BASH_SESSIONS_DIR}/$2"
echo "Session \"$1\" copied to \"$2\""
}
# change settings for active session
S (){
# check number of arguments
if [ "$#" -ne 2 ]; then
echo "Error: ${FUNCNAME[0]}() requires exactly 2 arguments"
return
fi
# check that we are in a session
if [ -z "${BASH_SESSION_NAME}" ]; then
echo "No session active!"
return
fi
if [ "${1}" == "output" ]; then
if [ "${2}" == "on" ]; then
if ! [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output" ]; then
touch "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output"
echo "bash_session: saving output requires exiting and re-entering session to become effective"
fi
elif [ "${2}" == "off" ]; then
if [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output" ]; then
rm "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output"
fi
else
echo "bash_sessions: invalid argument \"${2}\""
fi
elif [ "${1}" == "pwd" ]; then
if [ "${2}" == "on" ]; then
if ! [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/pwd" ]; then
export PROMPT_COMMAND="${PROMPT_COMMAND};__bs_savepwd"
fi
elif [ "${2}" == "off" ]; then
if [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/pwd" ]; then
rm "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/pwd"
export PROMPT_COMMAND="${PROMPT_COMMAND/;__bs_savepwd/}"
fi
else
echo "bash_sessions: invalid argument \"${2}\""
fi
elif [ "${1}" == "env" ]; then
if [ "${2}" == "on" ]; then
if ! [[ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/env_changed" && -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/env_deleted" ]]; then
export PROMPT_COMMAND="${PROMPT_COMMAND};__bs_saveenv"
fi
elif [ "${2}" == "off" ]; then
if [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/env_changed" ]; then
rm "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/env_changed"
fi
if [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/env_deleted" ]; then
rm "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/env_deleted"
fi
export PROMPT_COMMAND="${PROMPT_COMMAND/;__bs_saveenv/}"
else
echo "bash_sessions: invalid argument \"${2}\""
fi
elif [ "${1}" == "history" ]; then
if [ "${2}" == "on" ]; then
if ! [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/history" ]; then
tail -n 100 "${HISTFILE}" > "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/history"
history -c
export BASH_SESSIONS_OLD_HISTFILE="${HISTFILE}"
export HISTFILE="${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/history"
fi
elif [ "${2}" == "off" ]; then
if [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/history" ]; then
export HISTFILE="${BASH_SESSIONS_OLD_HISTFILE}"
rm "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/history"
fi
else
echo "bash_sessions: invalid argument \"${2}\""
fi
else
echo "bash_sessions: invalid argument \"${1}\""
fi
}
# print label for bash prompt
__bs_ps1 (){
if [ -n "${BASH_SESSION_NAME}" ]; then
echo "[${BASH_SESSION_NAME}]"
else
echo ""
fi
}
# list sessions
function e {
# create sessions directory if needed
[ -d "${BASH_SESSIONS_DIR}" ] || mkdir -p "${BASH_SESSIONS_DIR}"
for i in $(ls ${BASH_SESSIONS_DIR}); do
if [ -f "${BASH_SESSIONS_DIR}/${i}/loaded" ]; then
if lsof "${BASH_SESSIONS_DIR}/${i}/output" &>/dev/null; then
echo "${i}*"
else
echo "${i}+"
fi
else
echo "${i}"
fi;
done
}
# list current settings
L() {
# check number of arguments
if [ "$#" -ne 0 ]; then
echo "Error: ${FUNCNAME[0]}() requires no arguments"
return
fi
# check that we are in a session
if [ -z "${BASH_SESSION_NAME}" ]; then
echo "No session active!"
return
fi
if [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/output" ]; then
echo "Save console text (output): on"
else
echo "Save console text (output): off"
fi
if [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/pwd" ]; then
echo "Track working directory (pwd): on"
else
echo "Track working directory (pwd): off"
fi
if [[ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/env_changed" && -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/env_deleted" ]]; then
echo "Maintain separate environment variables (env): on"
else
echo "Maintain separate environment variables (env): off"
fi
if [ -f "${BASH_SESSIONS_DIR}/${BASH_SESSION_NAME}/history" ]; then
echo "Remember typed commands (history): on"
else
echo "Remember typed commands (history): off"
fi
}
h() {
echo "bash_sessions command reference"
echo ""
echo "n <session_name> create and activate a new session"
echo "o <session_name> open an existing session"
echo "c close current session"
echo "f <session_name> delete an existing session"
echo "r <old_name> <new_name> rename an existing session"
echo "b <old_name> <new_name> duplicate an existing session"
echo "e list existing sessions"
echo "S <name> <value> change settings for active session"
echo "L show settings for current session"
echo "h show command reference"
echo ""
echo "All command arguments support auto-completion"
}
# helper function for sessions completion
function __bs_sessions_comp_list {
# create sessions directory if needed
[ -d "${BASH_SESSIONS_DIR}" ] || mkdir -p "${BASH_SESSIONS_DIR}"
ls "${BASH_SESSIONS_DIR}"
}
# helper function for options completion
function __bs_options_comp_list {
echo "output"
echo "pwd"
echo "env"
echo "history"
}
# helper function for option values completion
function __bs_values_comp_list {
echo "on"
echo "off"
}
# completion command for sessions
function __bs_sessions_comp {
COMPREPLY=()
local current_word=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(compgen -W '`__bs_sessions_comp_list`' -- ${current_word}))
return 0
}
# completion command for options
function __bs_options_comp {
COMPREPLY=()
local current_word=${COMP_WORDS[COMP_CWORD]}
local previous_word=${COMP_WORDS[COMP_CWORD-1]}
case "${previous_word}" in
"S") COMPREPLY=($(compgen -W '`__bs_options_comp_list`' -- ${current_word}));;
"output") COMPREPLY=($(compgen -W '`__bs_values_comp_list`' -- ${current_word}));;
"pwd") COMPREPLY=($(compgen -W '`__bs_values_comp_list`' -- ${current_word}));;
"env") COMPREPLY=($(compgen -W '`__bs_values_comp_list`' -- ${current_word}));;
"history") COMPREPLY=($(compgen -W '`__bs_values_comp_list`' -- ${current_word}));;
esac
return 0
}
# bind completion commands
shopt -s progcomp
complete -o filenames -F __bs_sessions_comp o
complete -o filenames -F __bs_sessions_comp f
complete -o filenames -F __bs_sessions_comp r
complete -F __bs_options_comp S