diff --git a/Makefile b/Makefile index 078fb1d..892580b 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,6 @@ -.PHONY: test test-verbose install clean +.PHONY: test install clean test: - @bats tests/ - -test-verbose: @bats -t tests/ install: diff --git a/README.md b/README.md index da52587..0193371 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,9 @@ tmux-ws create project # Create in background, stay in current shell tmux-ws create project --detach +# Attach to a running workspace +tmux-ws attach project + # List what's available and what's running tmux-ws list @@ -145,11 +148,10 @@ Directories starting with `_` (like `_templates`, `_examples`) are hidden from ` ## Testing ```bash -make test # run test suite -make test-verbose # run with trace output +make test ``` -Requires [bats](https://github.com/bats-core/bats-core). Tests cover: help, version, list, create, inheritance, hooks, validation, kill, edit, and init. +Requires [bats](https://github.com/bats-core/bats-core). Tests cover: help, version, list, create, inheritance, hooks, validation, kill, attach, edit, and init. ## tmux Configuration diff --git a/completions/tmux-ws.bash b/completions/tmux-ws.bash new file mode 100644 index 0000000..e7d75b6 --- /dev/null +++ b/completions/tmux-ws.bash @@ -0,0 +1,34 @@ +#!/bin/bash +# Bash completion for tmux-ws + +_tmux_ws() { + local config_dir="${TMUX_WS_CONFIG:-$HOME/.config/tmux-ws}" + local cur="${COMP_WORDS[COMP_CWORD]}" + local prev="${COMP_WORDS[COMP_CWORD-1]}" + local subcommands="create attach list kill edit init help version" + + # First argument: complete subcommands + if [[ $COMP_CWORD -eq 1 ]]; then + COMPREPLY=($(compgen -W "$subcommands" -- "$cur")) + return + fi + + # Second argument: complete workspace names for commands that take them + if [[ $COMP_CWORD -eq 2 ]]; then + case "$prev" in + create|attach|kill|edit) + local workspaces="" + for dir in "$config_dir"/*/; do + [[ ! -f "$dir/workspace.conf" ]] && continue + local name + name=$(basename "$dir") + [[ "$name" == _* ]] && continue + workspaces="$workspaces $name" + done + COMPREPLY=($(compgen -W "$workspaces" -- "$cur")) + ;; + esac + fi +} + +complete -F _tmux_ws tmux-ws diff --git a/completions/tmux-ws.zsh b/completions/tmux-ws.zsh new file mode 100644 index 0000000..9d7cdc2 --- /dev/null +++ b/completions/tmux-ws.zsh @@ -0,0 +1,35 @@ +#compdef tmux-ws + +# Zsh completion for tmux-ws + +_tmux_ws() { + local config_dir="${TMUX_WS_CONFIG:-$HOME/.config/tmux-ws}" + local subcommands=(create attach list kill edit init help version) + + _arguments -C \ + '1:subcommand:->subcommand' \ + '2:workspace:->workspace' \ + && return + + case $state in + subcommand) + compadd -a subcommands + ;; + workspace) + case $words[2] in + create|attach|kill|edit) + local -a workspaces + for dir in "$config_dir"/*/; do + [[ ! -f "$dir/workspace.conf" ]] && continue + local name="${dir:t}" + [[ "$name" == _* ]] && continue + workspaces+=("$name") + done + compadd -a workspaces + ;; + esac + ;; + esac +} + +_tmux_ws "$@" diff --git a/install.sh b/install.sh index 18cc2a7..738b4c4 100755 --- a/install.sh +++ b/install.sh @@ -54,6 +54,39 @@ else warn "No .bashrc or .zshrc found — add $BIN_DIR to your PATH manually" fi +# Install shell completions +COMPLETIONS_SRC="$SCRIPT_DIR/completions" + +# Bash completion +if [[ -f "$HOME/.bashrc" ]]; then + if ! grep -qF "tmux-ws.bash" "$HOME/.bashrc" 2>/dev/null; then + echo "" >> "$HOME/.bashrc" + echo "# tmux-ws completion" >> "$HOME/.bashrc" + echo "source \"$COMPLETIONS_SRC/tmux-ws.bash\"" >> "$HOME/.bashrc" + info "Bash completion added to ~/.bashrc" + else + warn "Bash completion already configured in ~/.bashrc" + fi +fi + +# Zsh completion +if [[ -f "$HOME/.zshrc" ]]; then + ZSH_COMPLETIONS_DIR="$HOME/.zsh/completions" + mkdir -p "$ZSH_COMPLETIONS_DIR" + cp "$COMPLETIONS_SRC/tmux-ws.zsh" "$ZSH_COMPLETIONS_DIR/_tmux-ws" + info "Zsh completion installed to $ZSH_COMPLETIONS_DIR" + + if ! grep -qF "zsh/completions" "$HOME/.zshrc" 2>/dev/null; then + echo "" >> "$HOME/.zshrc" + echo "# tmux-ws completion" >> "$HOME/.zshrc" + echo "fpath=($ZSH_COMPLETIONS_DIR \$fpath)" >> "$HOME/.zshrc" + echo "autoload -Uz compinit && compinit" >> "$HOME/.zshrc" + info "Zsh completion configured in ~/.zshrc" + else + warn "Zsh fpath already configured in ~/.zshrc" + fi +fi + # Make script executable chmod +x "$BIN_DIR/tmux-ws"