-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: Shmux isn't readily available
Solution: - Import its code in a separate repository - Clean up the code, insert some commentaries - Make sure it complies with `shellcheck`
- Loading branch information
0 parents
commit 14cb7d1
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env bash | ||
# shmux is shell tmuxinator for a generic project | ||
|
||
## Error codes | ||
_err_no_target=1 | ||
_tmux_session_not_found=1 | ||
|
||
_session="$(basename "$1")" | ||
_session="${_session/./_}" | ||
|
||
tmux start-server || true | ||
|
||
# tmux has-session returns value that we'll refer to via $? | ||
tmux has-session -t "$_session" | ||
if [ "$?" -eq "$_tmux_session_not_found" ]; then # If there is no session | ||
if [ -n "$1" ]; then # And we have an argument | ||
# It's OK to fail | ||
cd "$1" || true | ||
_wd="$(pwd)" | ||
_post_hook_maybe="" | ||
|
||
TMUX="$(tmux new-session -d -s "$_session" -n vim)" | ||
tmux new-window -c "$_wd" -t "$_session:1" -n tasks | ||
tmux new-window -c "$_wd" -t "$_session:2" -n git | ||
tmux new-window -c "$_wd" -t "$_session:3" -n grep | ||
tmux new-window -c "$_wd" -t "$_session:4" -n mon0 | ||
tmux new-window -c "$_wd" -t "$_session:5" -n mon1 | ||
|
||
tmux send-keys -t "$_session:0" "vim ." C-m | ||
tmux send-keys -t "$_session:2" "git log --graph --decorate --all -n7 | grep ." C-m | ||
if [ -n "$_post_hook_maybe" ]; then | ||
for x in {2..5}; do | ||
tmux send-keys -t "$_session:$x" "$_post_hook_maybe" C-m | ||
done | ||
fi | ||
|
||
if [ -d tasks ]; then | ||
_split="horizontal" | ||
for x in tasks/*; do | ||
# Run buffer hook in the current split | ||
tmux send-keys -t "$_session:1" "$_post_hook_maybe" C-m | ||
# Run the task the current split | ||
tmux send-keys -t "$_session:1" "$x" C-m | ||
# Create a new split, spiral layout | ||
if [[ $_split == "horizontal" ]]; then | ||
tmux split-window -h -t "$_session:1" | ||
_split="vertical" | ||
else | ||
tmux split-window -t "$_session:1" | ||
_split="horizontal" | ||
fi | ||
done | ||
# Exit last split (it didn't have a task) | ||
tmux send-keys -t "$_session:1" "exit" C-m | ||
else | ||
tmux send-keys -t "$_session:1" "$_post_hook_maybe" C-m | ||
fi | ||
|
||
tmux select-window -t 0 | ||
fi | ||
fi | ||
|
||
# We can run tmux in detached mode with -d | ||
if [ "$2" == "-d" ]; then | ||
exit 0; | ||
fi | ||
# Otherwise we attach to the session if we're outside tmux | ||
if [ -z "$TMUX" ]; then | ||
tmux -u attach-session -t "$_session" | ||
# And switch to the session if we're inside | ||
else | ||
tmux -u switch-client -t "$_session" | ||
fi |