feat(tmux): list Developer dirs in fuzzy switcher and auto-create tmuxinator configs
This commit is contained in:
@@ -9,7 +9,7 @@ die() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
list_projects() {
|
||||
list_tmuxinator_projects() {
|
||||
tmuxinator list 2>/dev/null \
|
||||
| sed '1{/tmuxinator projects:/d;}' \
|
||||
| tr -s '[:space:]' '\n' \
|
||||
@@ -17,9 +17,21 @@ list_projects() {
|
||||
|| true
|
||||
}
|
||||
|
||||
list_developer_dirs() {
|
||||
find ~/Developer -mindepth 1 -maxdepth 1 -type d -exec basename {} \; 2>/dev/null \
|
||||
|| true
|
||||
}
|
||||
|
||||
list_projects() {
|
||||
{
|
||||
list_tmuxinator_projects
|
||||
list_developer_dirs
|
||||
}
|
||||
}
|
||||
|
||||
# unique + sorted
|
||||
items="$(list_projects | sort -u)"
|
||||
[ -n "$items" ] || die "No tmuxinator projects found."
|
||||
[ -n "$items" ] || die "No projects found."
|
||||
|
||||
sel="$(
|
||||
printf '%s\n' "$items" | fzf \
|
||||
@@ -37,18 +49,37 @@ choice="$(printf '%s\n' "$sel" | sed -n '3p')"
|
||||
project="${choice:-$query}"
|
||||
[ -n "$project" ] || exit 0
|
||||
|
||||
if [ "$project" = "vrm-deploy" ] && tmux has-session -t vrm-deploy 2>/dev/null; then
|
||||
current_session=$(tmux display-message -p '#S' 2>/dev/null)
|
||||
if [ "$current_session" = "vrm-deploy" ]; then
|
||||
tmux rename-session -t vrm-deploy vrm-deploy-old
|
||||
tmuxinator start vrm-deploy
|
||||
tmux kill-session -t vrm-deploy-old 2>/dev/null
|
||||
exit 0
|
||||
else
|
||||
tmux kill-session -t vrm-deploy 2>/dev/null
|
||||
fi
|
||||
# Check if it's a tmuxinator project
|
||||
tmuxinator_projects="$(list_tmuxinator_projects)"
|
||||
is_tmuxinator=false
|
||||
if echo "$tmuxinator_projects" | grep -qxF "$project"; then
|
||||
is_tmuxinator=true
|
||||
fi
|
||||
|
||||
# Check if it's a ~/Developer directory
|
||||
developer_dir="$HOME/Developer/$project"
|
||||
is_developer_dir=false
|
||||
if [ -d "$developer_dir" ]; then
|
||||
is_developer_dir=true
|
||||
fi
|
||||
|
||||
if [ "$is_tmuxinator" = true ]; then
|
||||
tmuxinator start "$project"
|
||||
elif [ "$is_developer_dir" = true ]; then
|
||||
# Handle ~/Developer directory - create tmuxinator config if needed
|
||||
session_name="$project"
|
||||
tmuxinator_config="$HOME/.config/tmuxinator/${session_name}.yml"
|
||||
|
||||
if [ ! -f "$tmuxinator_config" ]; then
|
||||
cp ~/.config/tmuxinator/template.yml.temp "$tmuxinator_config"
|
||||
sed -i '' "s|{{\$PROJECT_NAME}}|$session_name|g" "$tmuxinator_config"
|
||||
sed -i '' "s|{{\$PROJECT_ROOT}}|$developer_dir|g" "$tmuxinator_config"
|
||||
fi
|
||||
|
||||
tmuxinator start "$session_name"
|
||||
else
|
||||
die "Project '$project' not found in tmuxinator or ~/Developer"
|
||||
fi
|
||||
|
||||
tmuxinator start "$project"
|
||||
exit 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user