This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zellij_run
91 lines (75 loc) · 2.19 KB
/
zellij_run
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
#!/usr/bin/env bash
# This script is a wrapper for zellij, show a friendly tui interface to deal
# with zellij sessions
# define colors
RED="$(echo -en '\033[0;31m')"
GREEN="$(echo -en '\033[0;32m')"
YELLOW="$(echo -en '\033[0;33m')"
BLUE="$(echo -en '\033[0;34m')"
PURPLE="$(echo -en '\033[0;35m')"
NC="$(echo -en '\033[0m')"
# make sure that dependencies are installed
for package in zellij fzf; do
command -v "$package" &> /dev/null && continue
echo -e "${RED}ERROR: $package is not installed!${NC}"
exit 1
done
# define FZF dracula theme
export FZF_DEFAULT_OPTS=$FZF_DEFAULT_OPTS'
--color=fg:#f8f8f2,bg:#282a36,hl:#bd93f9
--color=fg+:#f8f8f2,bg+:#44475a,hl+:#bd93f9
--color=info:#ffb86c,prompt:#50fa7b,pointer:#ff79c6
--color=marker:#ff79c6,spinner:#ffb86c,header:#6272a4 --ansi --cycle'
# zellij functions #
function attach_session {
local session_name
session_name="$(zellij ls \
| fzf --header "Select session to attach" --prompt "Session: " \
| awk '{print $1}')"
zellij a "$session_name"
exit 0
}
function create_session {
read -p "${BLUE}Session name ${RED}(Leave empty to abort)${BLUE}: ${YELLOW}" -r session_name
echo -en "${NC}"
[ -z "$session_name" ] && return 1
zellij -s "$session_name"
exit 0
}
function delete_session {
zellij ls | fzf -m --header "Select sessions to delete" \
| awk '{print $1}' | xargs -I {} zellij delete-session {}
exit 0
}
function list_sessions {
zellij ls | less -SR
}
function main_script {
clear
echo -e "${GREEN}Welcome to zellij runner!${NC}\n\n"
options=('attach' 'create' 'list' 'delete')
PS3="${PURPLE}Please enter your choice: ${BLUE}"
echo -en "${BLUE}"
select choice in "${options[@]}"; do
echo -e "${NC}"
case "$choice" in
'attach') attach_session;;
'create') create_session;;
'list') list_sessions;;
'delete') delete_session;;
esac
done
}
# Main Script #
action="$1"
if [ -z "$action" ]; then main_script && exit 0; fi
case "$action" in
'attach'|'a') attach_session;;
'create'|'new') create_session;;
'list'|'ls') list_sessions;;
'delete'|'rm') delete_session;;
*)
echo -e "${RED}Invalid action: ${YELLOW}$action${NC}"
echo -e "${BLUE}Valid actions: ${GREEN}attach|a, create|new, list|ls, delete|rm${NC}"
exit 1;;
esac