-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwt-wrapper.sh
More file actions
executable file
·55 lines (45 loc) · 1.39 KB
/
wt-wrapper.sh
File metadata and controls
executable file
·55 lines (45 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# wt wrapper function for automatic directory changing
# Add this to your ~/.zshrc or ~/.bashrc:
#
# source /path/to/wt-manager/wt-wrapper.sh
#
wt() {
local wt_bin="${HOME}/.cargo/bin/wt"
# If binary doesn't exist in ~/.cargo/bin, try current directory
if [[ ! -f "$wt_bin" ]]; then
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
wt_bin="$script_dir/target/release/wt"
fi
if [[ ! -f "$wt_bin" ]]; then
echo "Error: wt binary not found. Run ./install.sh first."
return 1
fi
# Create temporary file for output
local tmp_output=$(mktemp)
# Run wt and capture output
"$wt_bin" "$@" | tee "$tmp_output"
local exit_code=${PIPESTATUS[0]}
# Look for "cd " command in output
local cd_line=$(grep "^ cd " "$tmp_output" | head -n1)
if [[ -n "$cd_line" ]]; then
# Extract directory path
local target_dir=$(echo "$cd_line" | sed 's/^ cd //')
# Change to directory
if [[ -d "$target_dir" ]]; then
cd "$target_dir" || {
rm -f "$tmp_output"
return 1
}
echo ""
echo "✓ Changed to: $(pwd)"
fi
fi
rm -f "$tmp_output"
return $exit_code
}
# For zsh compatibility
if [[ -n "$ZSH_VERSION" ]]; then
# Function already defined above
:
fi