-
Notifications
You must be signed in to change notification settings - Fork 0
/
zellij-sessionizer
executable file
·53 lines (41 loc) · 1.64 KB
/
zellij-sessionizer
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
#!/usr/bin/env bash
# taken from:
# https://github.com/silicakes/zellij-sessionizer/blob/main/zellij-sessionizer
# Installation / Usage
# Place the zellij-sessionizer script in your PATH
# Create an alias to call this script in your shells .rc config, e.g. in zsh:
# `bindkey -s ^f "zellij-sessionizer path1 path2 etc..\n"` - binds Ctrl f to execute the script, the newline in the end is important
paths=$@
if [[ -z $paths ]]; then
echo "No paths were specified, usage: ./zellij-sessionizer path1 path2 etc.."
exit 0
fi
# Check whether the machine has fd available
if [ -x "$(command -v fd)" ]; then
selected_path=$(fd . $paths --min-depth 1 --max-depth 2 --type d | fzf)
else
# defer to find if not
selected_path=$(find $paths -mindepth 1 -maxdepth 2 -type d | fzf)
fi
# If nothing was picked, silently exit
if [[ -z $selected_path ]]; then
exit 0
fi
# If no directory was selected, exit the script
if [[ -z $selected_path ]]; then
exit 0
fi
# Get the name of the selected directory, replacing "." with "_"
session_name=$(basename "$selected_path" | tr . _)
# We're outside of zellij, so lets create a new session or attach to a new one.
if [[ -z $ZELLIJ ]]; then
cd $selected_path
# -c will make zellij to either create a new session or to attach into an existing one
zellij attach $session_name -c
exit 0
fi
# We're inside zellij so we'll open a new pane and move into the selected directory
zellij action new-pane
# Hopefully they'll someday support specifying a directory and this won't be as laggy
# thanks to @msirringhaus for getting this from the community some time ago!
zellij action write-chars "cd $selected_path" && zellij action write 10