@ogpoyraz/wtx 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,164 @@
1
+ _wtx_get_repos() {
2
+ local config_file
3
+ if [ -n "$XDG_CONFIG_HOME" ]; then
4
+ config_file="${XDG_CONFIG_HOME}/wtx/config.json"
5
+ else
6
+ config_file="${HOME}/.config/wtx/config.json"
7
+ fi
8
+ if [ -f "$config_file" ]; then
9
+ if command -v jq >/dev/null 2>&1; then
10
+ jq -r '.repos | keys[]' "$config_file" 2>/dev/null
11
+ else
12
+ grep -E '^ "[^"]+":' "$config_file" 2>/dev/null | sed 's/^ "//; s/":.*//'
13
+ fi
14
+ fi
15
+ }
16
+
17
+ _wtx_get_branches() {
18
+ local config_file root postfix
19
+ if [ -n "$XDG_CONFIG_HOME" ]; then
20
+ config_file="${XDG_CONFIG_HOME}/wtx/config.json"
21
+ else
22
+ config_file="${HOME}/.config/wtx/config.json"
23
+ fi
24
+ if [ -f "$config_file" ] && command -v jq >/dev/null 2>&1; then
25
+ root=$(jq -r '.root' "$config_file" 2>/dev/null)
26
+ root="${root/#\~/$HOME}"
27
+ postfix=$(jq -r '.postfix // "-wt"' "$config_file" 2>/dev/null)
28
+ for repo in $(jq -r '.repos | keys[]' "$config_file" 2>/dev/null); do
29
+ local wt_dir="${root}/${repo}${postfix}"
30
+ if [ -d "$wt_dir" ]; then
31
+ git -C "${root}/${repo}" worktree list --porcelain 2>/dev/null | \
32
+ grep '^branch refs/heads/' | sed 's|^branch refs/heads/||'
33
+ fi
34
+ done | sort -u
35
+ fi
36
+ }
37
+
38
+ _wtx_completions() {
39
+ local cur prev cword
40
+ _init_completion 2>/dev/null || {
41
+ cur="${COMP_WORDS[COMP_CWORD]}"
42
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
43
+ cword=$COMP_CWORD
44
+ }
45
+
46
+ local subcommands="config create remove prune open rebase fetch sync deps ls cd status prs pull init skill terminal mcp exec"
47
+ local config_subcommands="init show set add-repo remove-repo"
48
+ local skill_subcommands="show path list"
49
+ local skill_names="opencode cursor claude"
50
+ local config_set_keys="root postfix ide default_main_branch"
51
+ local ides="cursor code vscode code-insiders vscodium idea webstorm zed vim nvim emacs"
52
+
53
+ local subcommand="" subsubcommand=""
54
+ local i=1
55
+ while [ $i -lt $cword ]; do
56
+ local w="${COMP_WORDS[i]}"
57
+ [[ "$w" == -* ]] && { i=$((i + 1)); continue; }
58
+ if [ -z "$subcommand" ]; then
59
+ subcommand="$w"
60
+ elif { [ "$subcommand" = "config" ] || [ "$subcommand" = "skill" ]; } && [ -z "$subsubcommand" ]; then
61
+ subsubcommand="$w"
62
+ fi
63
+ i=$((i + 1))
64
+ done
65
+
66
+ if [ "$prev" = "--repo" ] || [ "$prev" = "-r" ]; then
67
+ local repos=$(_wtx_get_repos)
68
+ if [[ "$cur" == *,* ]]; then
69
+ local prefix="${cur%,*},"
70
+ local suffix="${cur##*,}"
71
+ COMPREPLY=($(compgen -P "$prefix" -W "$repos" -- "$suffix"))
72
+ else
73
+ COMPREPLY=($(compgen -W "$repos" -- "$cur"))
74
+ fi
75
+ return 0
76
+ fi
77
+
78
+ if [ "$prev" = "--ide" ]; then
79
+ COMPREPLY=($(compgen -W "$ides" -- "$cur"))
80
+ return 0
81
+ fi
82
+
83
+ if [ "$prev" = "--base" ]; then
84
+ COMPREPLY=($(compgen -W "main master develop dev" -- "$cur"))
85
+ return 0
86
+ fi
87
+
88
+ if [[ "$cur" == -* ]]; then
89
+ local flags=""
90
+ case "$subcommand" in
91
+ create) flags="-r --repo --base --open --ide --track --agent --prompt -q --quiet --verbose --dry-run --help" ;;
92
+ remove) flags="-f --force -y --yes -r --repo -q --quiet --verbose --dry-run --help" ;;
93
+ prune) flags="-f --force -y --yes -r --repo -q --quiet --verbose --dry-run --help" ;;
94
+ open) flags="-r --repo --ide -q --quiet --verbose --dry-run --help" ;;
95
+ rebase) flags="--repo -q --quiet --verbose --dry-run --help" ;;
96
+ fetch) flags="--repo -q --quiet --verbose --dry-run --help" ;;
97
+ sync) flags="--repo -q --quiet --verbose --dry-run --help" ;;
98
+ deps) flags="-r --repo --install --symlink --json -q --quiet --verbose --dry-run --help" ;;
99
+ pull) flags="-r --repo -q --quiet --verbose --dry-run --help" ;;
100
+ ls) flags="-r --repo --pr --json -q --quiet --verbose --dry-run --help" ;;
101
+ status) flags="-r --repo --json -q --quiet --verbose --dry-run --help" ;;
102
+ prs) flags="-r --repo --json --all -q --quiet --verbose --dry-run --help" ;;
103
+ config)
104
+ case "$subsubcommand" in
105
+ add-repo) flags="--sync-files --post-create --post-sync --help" ;;
106
+ *) flags="--help" ;;
107
+ esac
108
+ ;;
109
+ *) flags="-q --quiet --verbose --dry-run --help" ;;
110
+ esac
111
+ COMPREPLY=($(compgen -W "$flags" -- "$cur"))
112
+ return 0
113
+ fi
114
+
115
+ if [ -z "$subcommand" ]; then
116
+ COMPREPLY=($(compgen -W "$subcommands" -- "$cur"))
117
+ return 0
118
+ fi
119
+
120
+ case "$subcommand" in
121
+ config)
122
+ if [ -z "$subsubcommand" ]; then
123
+ COMPREPLY=($(compgen -W "$config_subcommands" -- "$cur"))
124
+ return 0
125
+ fi
126
+ case "$subsubcommand" in
127
+ set)
128
+ [ "$prev" = "set" ] && COMPREPLY=($(compgen -W "$config_set_keys" -- "$cur")) && return 0
129
+ ;;
130
+ remove-repo)
131
+ COMPREPLY=($(compgen -W "$(_wtx_get_repos)" -- "$cur"))
132
+ return 0
133
+ ;;
134
+ esac
135
+ ;;
136
+ init)
137
+ COMPREPLY=($(compgen -W "bash zsh fish" -- "$cur"))
138
+ return 0
139
+ ;;
140
+ skill)
141
+ if [ -z "$subsubcommand" ]; then
142
+ COMPREPLY=($(compgen -W "$skill_subcommands" -- "$cur"))
143
+ return 0
144
+ fi
145
+ case "$subsubcommand" in
146
+ show|path)
147
+ COMPREPLY=($(compgen -W "$skill_names" -- "$cur"))
148
+ return 0
149
+ ;;
150
+ esac
151
+ ;;
152
+ cd)
153
+ [ "$prev" = "cd" ] && COMPREPLY=($(compgen -W "$(_wtx_get_repos)" -- "$cur")) && return 0
154
+ ;;
155
+ rebase|open|status|remove|sync|deps)
156
+ [ "$prev" = "$subcommand" ] && COMPREPLY=($(compgen -W "$(_wtx_get_branches)" -- "$cur")) && return 0
157
+ ;;
158
+ esac
159
+
160
+ COMPREPLY=()
161
+ return 0
162
+ }
163
+
164
+ complete -F _wtx_completions wtx
@@ -0,0 +1,123 @@
1
+ function _wtx_get_repos
2
+ set -l config_file
3
+ if set -q XDG_CONFIG_HOME
4
+ set config_file "$XDG_CONFIG_HOME/wtx/config.json"
5
+ else
6
+ set config_file "$HOME/.config/wtx/config.json"
7
+ end
8
+ if test -f "$config_file"
9
+ if type -q jq
10
+ jq -r '.repos | keys[]' "$config_file" 2>/dev/null
11
+ else
12
+ grep -E '^ "[^"]+":' "$config_file" 2>/dev/null | sed 's/^ "//; s/":.*//'
13
+ end
14
+ end
15
+ end
16
+
17
+ function _wtx_get_branches
18
+ set -l config_file
19
+ if set -q XDG_CONFIG_HOME
20
+ set config_file "$XDG_CONFIG_HOME/wtx/config.json"
21
+ else
22
+ set config_file "$HOME/.config/wtx/config.json"
23
+ end
24
+ if test -f "$config_file"; and type -q jq
25
+ set -l root (jq -r '.root' "$config_file" 2>/dev/null | sed "s|^~/|$HOME/|")
26
+ set -l postfix (jq -r '.postfix // "-wt"' "$config_file" 2>/dev/null)
27
+ for repo in (jq -r '.repos | keys[]' "$config_file" 2>/dev/null)
28
+ if test -d "$root/$repo"
29
+ git -C "$root/$repo" worktree list --porcelain 2>/dev/null | grep '^branch refs/heads/' | sed 's|^branch refs/heads/||'
30
+ end
31
+ end | sort -u
32
+ end
33
+ end
34
+
35
+ complete -c wtx -f
36
+
37
+ # Global Options
38
+ complete -c wtx -s q -l quiet -d "Suppress output"
39
+ complete -c wtx -l verbose -d "Show git commands"
40
+ complete -c wtx -l dry-run -d "Show what would happen"
41
+ complete -c wtx -s h -l help -d "Display help for command"
42
+
43
+ # Subcommands
44
+ set -l commands config create remove prune open rebase fetch sync deps ls cd status prs pull init skill terminal mcp exec
45
+
46
+ # Setup completions for commands
47
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "config" -d "Manage configuration"
48
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "create" -d "Create worktrees"
49
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "remove" -d "Remove worktrees"
50
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "prune" -d "Remove worktrees with merged PRs"
51
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "open" -d "Open worktree in IDE"
52
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "rebase" -d "Fetch and rebase vs main"
53
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "pull" -d "Fetch a PR and create its worktree"
54
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "fetch" -d "Fetch origin main"
55
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "sync" -d "Re-copy sync files and run post_sync"
56
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "deps" -d "Manage node_modules strategy"
57
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "ls" -d "List worktrees with status"
58
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "cd" -d "Change directory to worktree"
59
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "status" -d "Show worktree status"
60
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "prs" -d "Show pull request status across worktrees"
61
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "init" -d "Output shell integration code"
62
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "skill" -d "Manage AI agent skills"
63
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "terminal" -d "Interactive terminal dashboard"
64
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "mcp" -d "Run MCP server exposing worktree tools"
65
+ complete -c wtx -n "not __fish_seen_subcommand_from $commands" -a "exec" -d "Execute commands across worktrees"
66
+
67
+ # Dynamically complete branch arguments
68
+ complete -c wtx -n "__fish_seen_subcommand_from create open rebase sync deps status remove" -a "(_wtx_get_branches)"
69
+
70
+ # Flags
71
+ complete -c wtx -n "__fish_seen_subcommand_from create remove prune open rebase fetch sync deps ls status prs pull" -s r -l repo -xa "(_wtx_get_repos)" -d "Target specific repo(s)"
72
+
73
+ # create flags
74
+ complete -c wtx -n "__fish_seen_subcommand_from create" -l base -xa "main master develop dev" -d "Base ref"
75
+ complete -c wtx -n "__fish_seen_subcommand_from create" -s o -l open -d "Open worktree in IDE after creation"
76
+ complete -c wtx -n "__fish_seen_subcommand_from create open" -l ide -xa "cursor code vscode code-insiders vscodium idea webstorm zed vim nvim emacs" -d "IDE to open with"
77
+ complete -c wtx -n "__fish_seen_subcommand_from create" -l track -d "Track remote branch even if it belongs to someone else"
78
+ complete -c wtx -n "__fish_seen_subcommand_from create" -l agent -d "AI agent to delegate work to"
79
+ complete -c wtx -n "__fish_seen_subcommand_from create" -l prompt -d "Prompt for AI agent"
80
+
81
+ # remove/prune flags
82
+ complete -c wtx -n "__fish_seen_subcommand_from remove prune" -s f -l force -d "Force removal"
83
+ complete -c wtx -n "__fish_seen_subcommand_from remove prune" -s y -l yes -d "Skip confirmation prompt"
84
+
85
+ # deps flags
86
+ complete -c wtx -n "__fish_seen_subcommand_from deps" -l install -d "Switch to independent node_modules"
87
+ complete -c wtx -n "__fish_seen_subcommand_from deps" -l symlink -d "Switch to symlinked node_modules"
88
+
89
+ # json flag
90
+ complete -c wtx -n "__fish_seen_subcommand_from ls status prs deps" -l json -d "Output machine-readable JSON"
91
+
92
+ # ls flags
93
+ complete -c wtx -n "__fish_seen_subcommand_from ls" -l pr -d "Include pull request status column"
94
+
95
+ # prs flags
96
+ complete -c wtx -n "__fish_seen_subcommand_from prs" -l all -d "Include drafts and closed/merged PRs"
97
+
98
+ # config subcommands
99
+ set -l config_commands init show set add-repo remove-repo
100
+ complete -c wtx -n "__fish_seen_subcommand_from config; and not __fish_seen_subcommand_from $config_commands" -a "init" -d "Initialize configuration"
101
+ complete -c wtx -n "__fish_seen_subcommand_from config; and not __fish_seen_subcommand_from $config_commands" -a "show" -d "Show current configuration"
102
+ complete -c wtx -n "__fish_seen_subcommand_from config; and not __fish_seen_subcommand_from $config_commands" -a "set" -d "Set a configuration key"
103
+ complete -c wtx -n "__fish_seen_subcommand_from config; and not __fish_seen_subcommand_from $config_commands" -a "add-repo" -d "Add or update a repo"
104
+ complete -c wtx -n "__fish_seen_subcommand_from config; and not __fish_seen_subcommand_from $config_commands" -a "remove-repo" -d "Remove a repo"
105
+
106
+ # config flags
107
+ complete -c wtx -n "__fish_seen_subcommand_from add-repo" -l sync-files -d "Files to sync"
108
+ complete -c wtx -n "__fish_seen_subcommand_from add-repo" -l post-create -d "Post-create commands"
109
+ complete -c wtx -n "__fish_seen_subcommand_from add-repo" -l post-sync -d "Post-sync commands"
110
+ complete -c wtx -n "__fish_seen_subcommand_from remove-repo" -xa "(_wtx_get_repos)"
111
+
112
+ # skill subcommands
113
+ set -l skill_commands show path list
114
+ complete -c wtx -n "__fish_seen_subcommand_from skill; and not __fish_seen_subcommand_from $skill_commands" -a "show" -d "Show skill content"
115
+ complete -c wtx -n "__fish_seen_subcommand_from skill; and not __fish_seen_subcommand_from $skill_commands" -a "path" -d "Show skill file path"
116
+ complete -c wtx -n "__fish_seen_subcommand_from skill; and not __fish_seen_subcommand_from $skill_commands" -a "list" -d "List available skills"
117
+ complete -c wtx -n "__fish_seen_subcommand_from show path" -xa "opencode cursor claude"
118
+
119
+ # init
120
+ complete -c wtx -n "__fish_seen_subcommand_from init" -xa "bash zsh fish"
121
+
122
+ # cd
123
+ complete -c wtx -n "__fish_seen_subcommand_from cd" -xa "(_wtx_get_repos)"