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
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
list_projects() {
|
list_tmuxinator_projects() {
|
||||||
tmuxinator list 2>/dev/null \
|
tmuxinator list 2>/dev/null \
|
||||||
| sed '1{/tmuxinator projects:/d;}' \
|
| sed '1{/tmuxinator projects:/d;}' \
|
||||||
| tr -s '[:space:]' '\n' \
|
| tr -s '[:space:]' '\n' \
|
||||||
@@ -17,9 +17,21 @@ list_projects() {
|
|||||||
|| true
|
|| 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
|
# unique + sorted
|
||||||
items="$(list_projects | sort -u)"
|
items="$(list_projects | sort -u)"
|
||||||
[ -n "$items" ] || die "No tmuxinator projects found."
|
[ -n "$items" ] || die "No projects found."
|
||||||
|
|
||||||
sel="$(
|
sel="$(
|
||||||
printf '%s\n' "$items" | fzf \
|
printf '%s\n' "$items" | fzf \
|
||||||
@@ -37,18 +49,37 @@ choice="$(printf '%s\n' "$sel" | sed -n '3p')"
|
|||||||
project="${choice:-$query}"
|
project="${choice:-$query}"
|
||||||
[ -n "$project" ] || exit 0
|
[ -n "$project" ] || exit 0
|
||||||
|
|
||||||
if [ "$project" = "vrm-deploy" ] && tmux has-session -t vrm-deploy 2>/dev/null; then
|
# Check if it's a tmuxinator project
|
||||||
current_session=$(tmux display-message -p '#S' 2>/dev/null)
|
tmuxinator_projects="$(list_tmuxinator_projects)"
|
||||||
if [ "$current_session" = "vrm-deploy" ]; then
|
is_tmuxinator=false
|
||||||
tmux rename-session -t vrm-deploy vrm-deploy-old
|
if echo "$tmuxinator_projects" | grep -qxF "$project"; then
|
||||||
tmuxinator start vrm-deploy
|
is_tmuxinator=true
|
||||||
tmux kill-session -t vrm-deploy-old 2>/dev/null
|
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
tmux kill-session -t vrm-deploy 2>/dev/null
|
|
||||||
fi
|
|
||||||
fi
|
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"
|
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
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user