auto up 04:40:43 up 1 day 16:08, 2 users, load average: 1.69, 1.81, 1.46

This commit is contained in:
2025-12-24 04:40:45 +01:00
parent 66261bd55c
commit 0c719d933c

46
other/zellij-sessionizer Executable file
View File

@@ -0,0 +1,46 @@
#!/usr/bin/env bash
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