-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.zsh
75 lines (71 loc) · 1.44 KB
/
dev.zsh
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
74
75
# infer tool from current directory
get_tool() {
if [[ -f pyproject.toml ]]; then
echo "uv"
elif [[ -f package.json ]]; then
echo "bun"
elif [[ -f Package.swift ]]; then
echo "swift"
elif [[ -f main.go ]]; then
echo "go"
elif [[ -f compose.yml || -f compose.yaml ]]; then
echo "docker-compose"
elif [[ -f docker-compose.yml || -f docker-compose.yaml ]]; then
echo "docker-compose"
else
echo ""
fi
}
# Define the command for each tool & operation (+-«»)
map_tool_command() {
local tool=$1
local operation=$2
case $tool in
uv)
case $operation in
+) echo "add" ;;
-) echo "remove" ;;
») echo "run" ;;
«) echo "sync" ;;
esac
;;
bun|swift|go)
case $operation in
+) echo "add" ;;
-) echo "remove" ;;
») echo "run" ;;
«) echo "update" ;;
esac
;;
docker-compose)
case $operation in
+) echo "pull" ;;
-) echo "down" ;;
») echo "up" ;;
«) echo "pull" ;;
esac
;;
brew)
case $operation in
+) echo "install" ;;
-) echo "uninstall" ;;
») echo "upgrade" ;;
«) echo "update" ;;
esac
;;
esac
}
run_tool_command() {
local operation=$1
shift
local tool=$(get_tool)
echo $tool
tool=${tool:-brew}
command=$(map_tool_command $tool $operation)
echo "$tool $command" "$@"
$tool $command "$@"
}
+() { run_tool_command + "$@" }
-() { run_tool_command - "$@" }
«() { run_tool_command « "$@" }
»() { run_tool_command » "$@" }