-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·73 lines (64 loc) · 1.88 KB
/
install.sh
File metadata and controls
executable file
·73 lines (64 loc) · 1.88 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
set -e
INSTALL_BIN="$HOME/.local/bin"
# Ensure directory exists
mkdir -p "$INSTALL_BIN"
# Install script
echo "Installing wk to $INSTALL_BIN..."
cp src/wk "$INSTALL_BIN/wk"
chmod +x "$INSTALL_BIN/wk"
# Create worktry symlink
ln -sf "$INSTALL_BIN/wk" "$INSTALL_BIN/worktry"
# Shell function
SHELL_FUNC='# wk (worktry) - cd wrapper for navigation commands
wk() {
if [[ "$1" == "go" || "$1" == "back" || "$1" == "b" || "$1" =~ ^[0-9]$ ]]; then
local target
target=$(command wk "$@")
if [[ -d "$target" ]]; then
cd "$target" && echo "→ $target"
fi
else
command wk "$@"
fi
}
alias worktry=wk'
# Detect shell rc file
if [ -n "$ZSH_VERSION" ] || [ "$SHELL" = "/bin/zsh" ]; then
RC_FILE="$HOME/.zshrc"
elif [ -n "$BASH_VERSION" ] || [ "$SHELL" = "/bin/bash" ]; then
RC_FILE="$HOME/.bashrc"
else
RC_FILE=""
fi
# Add shell function if not already present
if [ -n "$RC_FILE" ]; then
# Check for wk() or old worktry() function
if grep -qE "^(wk|worktry)\(\)" "$RC_FILE" 2>/dev/null || grep -q "# wk (worktry)" "$RC_FILE" 2>/dev/null; then
echo "✓ Shell function already exists in $RC_FILE"
else
echo ""
echo "Navigation commands (wk go/back/0-9) require a shell function."
read -p "Add shell function to $RC_FILE? [Y/n] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
echo "" >> "$RC_FILE"
echo "$SHELL_FUNC" >> "$RC_FILE"
echo "✓ Added wk function to $RC_FILE"
echo " Run 'source $RC_FILE' or restart your terminal to use navigation commands"
else
echo "Skipped. To add manually, append to $RC_FILE:"
echo ""
echo "$SHELL_FUNC"
fi
fi
else
echo ""
echo "Could not detect shell rc file. Add this function to your shell config:"
echo ""
echo "$SHELL_FUNC"
fi
echo ""
echo "✓ wk installed to $INSTALL_BIN (with 'worktry' alias)"
echo ""
echo "Make sure '$INSTALL_BIN' is in your PATH."