-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesk
More file actions
executable file
·82 lines (65 loc) · 1.86 KB
/
desk
File metadata and controls
executable file
·82 lines (65 loc) · 1.86 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
#!/bin/bash
temp=$(getopt --name 'desk' --options 'h' --long 'help' -- "$@")
session='Desktop'
eval set -- "$temp"
unset temp
main() {
# Parse command options
parse_options $@
create_session "$session"
# large 1: bash* (3 panes) [232x65] [layout 1aa6,232x65,0,0{116x65,0,0,6,115x65,117,0[115x54,117,0,7,115x10,117,55,8]}] @3 (active)
# small 1: bash* (3 panes) [114x64] [layout 29f4,114x64,0,0[114x26,0,0,1,114x26,0,27,2,114x10,0,54,3]] @0 (active)
local panes=$(tmux list-panes -a)
local pane_2="$(echo $panes | grep 'Desktop:1.2')"
local pane_3="$(echo $panes | grep 'Desktop:1.3')"
if [ "$columns" -gt 230 ]; then
[ -z "$pane_2" ] && tmux split-window -h
[ -z "$pane_3" ] && tmux split-window -d -l 10 -t 'Desktop:1.2' cava
else
[ -z "$pane_2" ] && tmux split-window -d -l 10 -t 'Desktop:1.1' cava
fi
attach_session "$session"
}
attach_session() {
local target="$1"
# Attach if outside of tmux, switch if you're in tmux
if [ -z "$TMUX" ]; then
tmux attach-session -t $target
else
tmux switch-client -t $target
fi
}
create_session() {
local target="$1"
# Check if the session exists
tmux has-session -t $target 2> /dev/null
# Create the session if it doesn't exists
# $? is the exit status of the previous command
if [ $? != 0 ]; then
# Get the hight and width of the terminal
local lines="$(tput lines)"
columns="$(tput cols)"
# Create a new session in detached mode
TMUX='' tmux new-session -d -x "$columns" -y "$lines" -s "$target"
fi
}
help() {
echo 'Help Menu'
exit 0
}
parse_options() {
while [ -n "$1" ]; do
case "$1" in
'-h'|'--help')
help
break;;
'--')
shift
break;;
*)
echo 'Internal error!' >&2
exit 1;;
esac
done
}
main "$@"