santree 0.0.1 → 0.0.3

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,10 @@
1
+ import { z } from "zod/v4";
2
+ export declare const args: z.ZodTuple<[z.ZodDefault<z.ZodEnum<{
3
+ zsh: "zsh";
4
+ bash: "bash";
5
+ }>>], null>;
6
+ type Props = {
7
+ args: z.infer<typeof args>;
8
+ };
9
+ export default function ShellInit({ args }: Props): null;
10
+ export {};
@@ -0,0 +1,108 @@
1
+ import { argument } from "pastel";
2
+ import { z } from "zod/v4";
3
+ export const args = z.tuple([
4
+ z
5
+ .enum(["zsh", "bash"])
6
+ .default("zsh")
7
+ .describe(argument({ name: "shell", description: "Shell type (zsh or bash)" })),
8
+ ]);
9
+ const ZSH_INIT = `# Santree shell integration
10
+ # Add to your .zshrc: eval "$(santree shell-init zsh)"
11
+
12
+ function santree() {
13
+ # Check if current directory exists (might have been deleted by clean/remove)
14
+ if [[ ! -d "$(pwd 2>/dev/null)" ]]; then
15
+ local current_path="$(pwd 2>/dev/null)"
16
+ if [[ "$current_path" == */.santree/worktrees/* ]]; then
17
+ local main_repo="\${current_path%%/.santree/worktrees/*}"
18
+ if [[ -d "$main_repo" ]]; then
19
+ echo "⚠ Worktree directory deleted. Returning to main repo."
20
+ cd "$main_repo" || cd ~ || return 1
21
+ else
22
+ cd ~ || return 1
23
+ fi
24
+ else
25
+ echo "⚠ Current directory no longer exists. Returning to home."
26
+ cd ~ || return 1
27
+ fi
28
+ fi
29
+
30
+ # create/switch need output capture for cd
31
+ if [[ "$1" == "create" || "$1" == "switch" || "$1" == "sw" ]]; then
32
+ local output
33
+ output=$(command santree "$@" 2>&1)
34
+ local exit_code=$?
35
+
36
+ if [[ "$output" == *SANTREE_CD:* ]]; then
37
+ echo "$output" | grep -v "SANTREE_CD:" | grep -v "SANTREE_WORK:"
38
+ local target_dir=$(echo "$output" | sed 's/\\x1b\\[[0-9;]*m//g' | grep "SANTREE_CD:" | sed 's/.*SANTREE_CD://')
39
+ if [[ -n "$target_dir" && -d "$target_dir" ]]; then
40
+ cd "$target_dir" && echo "Switched to: $target_dir"
41
+ fi
42
+
43
+ if [[ "$output" == *SANTREE_WORK:* ]]; then
44
+ local work_mode=$(echo "$output" | sed 's/\\x1b\\[[0-9;]*m//g' | grep "SANTREE_WORK:" | sed 's/.*SANTREE_WORK://')
45
+ [[ "$work_mode" == "plan" ]] && command santree work --plan || command santree work
46
+ fi
47
+ else
48
+ echo "$output"
49
+ fi
50
+ return $exit_code
51
+ fi
52
+
53
+ command santree "$@"
54
+ }
55
+ `;
56
+ const BASH_INIT = `# Santree shell integration
57
+ # Add to your .bashrc: eval "$(santree shell-init bash)"
58
+
59
+ function santree() {
60
+ # Check if current directory exists (might have been deleted by clean/remove)
61
+ if [[ ! -d "$(pwd 2>/dev/null)" ]]; then
62
+ local current_path="$(pwd 2>/dev/null)"
63
+ if [[ "$current_path" == */.santree/worktrees/* ]]; then
64
+ local main_repo="\${current_path%%/.santree/worktrees/*}"
65
+ if [[ -d "$main_repo" ]]; then
66
+ echo "⚠ Worktree directory deleted. Returning to main repo."
67
+ cd "$main_repo" || cd ~ || return 1
68
+ else
69
+ cd ~ || return 1
70
+ fi
71
+ else
72
+ echo "⚠ Current directory no longer exists. Returning to home."
73
+ cd ~ || return 1
74
+ fi
75
+ fi
76
+
77
+ # create/switch need output capture for cd
78
+ if [[ "$1" == "create" || "$1" == "switch" || "$1" == "sw" ]]; then
79
+ local output
80
+ output=$(command santree "$@" 2>&1)
81
+ local exit_code=$?
82
+
83
+ if [[ "$output" == *SANTREE_CD:* ]]; then
84
+ echo "$output" | grep -v "SANTREE_CD:" | grep -v "SANTREE_WORK:"
85
+ local target_dir=$(echo "$output" | sed 's/\\x1b\\[[0-9;]*m//g' | grep "SANTREE_CD:" | sed 's/.*SANTREE_CD://')
86
+ if [[ -n "$target_dir" && -d "$target_dir" ]]; then
87
+ cd "$target_dir" && echo "Switched to: $target_dir"
88
+ fi
89
+
90
+ if [[ "$output" == *SANTREE_WORK:* ]]; then
91
+ local work_mode=$(echo "$output" | sed 's/\\x1b\\[[0-9;]*m//g' | grep "SANTREE_WORK:" | sed 's/.*SANTREE_WORK://')
92
+ [[ "$work_mode" == "plan" ]] && command santree work --plan || command santree work
93
+ fi
94
+ else
95
+ echo "$output"
96
+ fi
97
+ return $exit_code
98
+ fi
99
+
100
+ command santree "$@"
101
+ }
102
+ `;
103
+ export default function ShellInit({ args }) {
104
+ const [shell] = args;
105
+ const script = shell === "zsh" ? ZSH_INIT : BASH_INIT;
106
+ console.log(script);
107
+ return null;
108
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "santree",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Git worktree manager with Linear integration",
5
5
  "license": "MIT",
6
6
  "author": "Santiago Toscanini",