Created
November 12, 2019 11:15
-
-
Save refs/ce09c614b651d72af193d8ab592d94cc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/sh | |
# ============================== | |
# usage: reva-panes path/to/toml | |
# - it starts the panes on detached mode, so | |
# - when attached to the session [C-c] will kill the daemon | |
# ============================== | |
# at least arg1 must exist | |
if [ $# -eq 0 ]; then | |
echo "wrong number of arguments" && exit 1 | |
fi | |
# check $1 is a valid directory | |
if ! [ -d $1 ]; then | |
echo "invalid path: '$1'" && exit 1 | |
fi | |
# check whether the destination contains any toml files | |
ls -al $1/*.toml &>/dev/null | |
if [ $? -ne 0 ]; then | |
echo "no toml config files found on path: '$1'" && exit 1 | |
fi | |
# remove any possible reva tmux session that could have been started | |
tmux kill-session -t reva &>/dev/null | |
if [ $? -eq 0 ]; then | |
echo "old session was killed" | |
fi | |
# make sure a tmux server has already started | |
tmux start-server | |
if [ $? -ne 0 ]; then | |
echo "tmux not found" && exit 1 | |
fi | |
echo "running..." | |
current=0 | |
totalFiles=`find ~/automation/reva/separate -maxdepth 1 -name '*.toml' | wc -l` | |
echo $totalFiles | |
for CONFIG in $1/*.toml | |
do | |
if [ $current -eq 0 ]; then | |
tmux new-session -d -s reva revad -c $CONFIG -p $CONFIG-$current.pid | |
let "current += 1" && continue | |
fi | |
# split pane (prepare for the next iteration) | |
# note that on its name `current` is appended, which can be used for | |
# further scripting as it is the pane name | |
tmux split-window -h -c $1 revad -c $CONFIG -p $CONFIG-$current.pid | |
# make space for the remaining panes | |
tmux select-layout tiled | |
if [ $current -eq $totalFiles ]; then | |
break | |
else | |
# increase pane counter | |
let "current += 1" | |
fi | |
done | |
# attach to the new session | |
tmux attach-session -t reva |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment