2024-10-16 17:46:26 +11:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-11-07 14:37:03 +11:00
|
|
|
# Save logs to ~/.logs/zellij.log
|
|
|
|
|
|
|
|
# Check if focus on zellig window worked wmctrl -a zellij
|
2024-10-16 17:46:26 +11:00
|
|
|
if [ -z "$(wmctrl -l | grep Zellij)" ]; then
|
2024-11-07 14:37:03 +11:00
|
|
|
echo "No terminal running" >/tmp/message
|
|
|
|
echo "No terminal running" >>~/.logs/zellij.log
|
2024-10-16 17:46:26 +11:00
|
|
|
polybar-msg action message hook 0
|
2024-11-07 14:37:03 +11:00
|
|
|
exit 1
|
2024-10-16 17:46:26 +11:00
|
|
|
else
|
|
|
|
wmctrl -a Zellij
|
2024-11-07 14:37:03 +11:00
|
|
|
echo "Focused on terminal" >>~/.logs/zellij.log
|
2024-10-16 17:46:26 +11:00
|
|
|
fi
|
|
|
|
|
2024-11-07 14:37:03 +11:00
|
|
|
session=$(zellij list-sessions | grep -v "EXITED" | sed -r 's/\x1B\[[0-9;]*[mK]//g' | awk '{print $1}')
|
|
|
|
|
|
|
|
# For each line in the session list, echo to log
|
|
|
|
for line in $session; do
|
|
|
|
echo "Found session: $line" >>~/.logs/zellij.log
|
|
|
|
echo "Found session: $line"
|
|
|
|
# Get arguments and run in new zellij pane
|
|
|
|
if [ "$#" -ne 0 ]; then
|
|
|
|
# Check if --cwd flag is passed
|
|
|
|
if [ "$1" == "--cwd" ]; then
|
|
|
|
echo "Using cwd: $2" >>~/.logs/zellij.log
|
|
|
|
echo "Running command: ${@:3}" >>~/.logs/zellij.log
|
|
|
|
|
|
|
|
zellij --session $line run -fc --cwd "$2" -- "${@:3}" >>~/.logs/zellij.log 2>&1
|
|
|
|
else
|
|
|
|
echo "Running command: $@" >>~/.logs/zellij.log
|
|
|
|
zellij --session $line run -fc -- "$@" >>~/.logs/zellij.log 2>&1
|
|
|
|
fi
|
2024-10-16 17:46:26 +11:00
|
|
|
else
|
2024-11-07 14:37:03 +11:00
|
|
|
echo "No command provided" >>~/.logs/zellij.log
|
|
|
|
echo "Usage: zelij.sh <command>"
|
2024-10-16 17:46:26 +11:00
|
|
|
fi
|
2024-11-07 14:37:03 +11:00
|
|
|
done
|