Last active
July 27, 2024 13:10
-
-
Save silicakes/ad6da190d9c05270bc651086c200f8b2 to your computer and use it in GitHub Desktop.
zellij_sessionizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Inspired by https://github.com/ThePrimeagen/.dotfiles/blob/602019e902634188ab06ea31251c01c1a43d1621/bin/.local/scripts/tmux-sessionizer | |
# Just for zellij | |
# alows you to use `fzf` to navigate into a desire folder and either start or attach into a zellij session | |
# If you run it from inside zellij, it will open the newly selected folder in a new pane | |
# Demo of the original: https://youtu.be/bdumjiHabhQ?t=269 | |
# 1. Place the script in your path | |
# 2. Create an alias to call this script in your shells .rc config: | |
# bindkey -s ^f "zellij_sessionizer\n" | |
# 3. Update where you want to search: | |
# I'm using `fd` to perform the search inside a specific dir, you can use that or `find` | |
# Use an argument if passed | |
if [[ $# -eq 1 ]]; then | |
selected_path=$1 | |
else | |
# If no argument was provided, interactively choose a directory | |
selected_path=$(fd . ~/dev --min-depth 1 --max-depth 2 --type d | fzf) | |
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 |
Hey! while searching for zellij-sessionizer
I found this solution.
I used to use tmux switch-client
to switch to a newly created session and was missing that behavior in zellij. After some more time searching I've found a plugin with that exact functionality, so I've decided to inform here in case you might like this solution more as well. Here's the plugin.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great! can't wait