-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathws.bash
More file actions
69 lines (67 loc) · 2.12 KB
/
ws.bash
File metadata and controls
69 lines (67 loc) · 2.12 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
# ws shell integration for bash
# Add to ~/.bashrc: source /path/to/ws.bash
ws() {
if [[ "$1" == "go" && -n "$2" ]]; then
local target
target=$(command ws go "$2" 2>/dev/null)
local exit_code=$?
if [[ $exit_code -eq 0 && -n "$target" && -d "$target" ]]; then
cd "$target" || return 1
else
command ws go "$2"
return $exit_code
fi
elif [[ "$1" == "home" ]]; then
local target
target=$(command ws home 2>/dev/null)
local exit_code=$?
if [[ $exit_code -eq 0 && -n "$target" && -d "$target" ]]; then
cd "$target" || return 1
else
command ws home
return $exit_code
fi
elif [[ "$1" == "new" && -n "$2" ]]; then
command ws "$@"
local exit_code=$?
if [[ $exit_code -eq 0 ]]; then
local target
target=$(command ws go "$2" 2>/dev/null)
if [[ -n "$target" && -d "$target" ]]; then
cd "$target" || return 1
fi
fi
return $exit_code
elif [[ "$1" == "ez" && -n "$2" ]]; then
command ws "$@"
local exit_code=$?
if [[ $exit_code -eq 0 ]]; then
local target
target=$(command ws go "$2" 2>/dev/null)
if [[ -n "$target" && -d "$target" ]]; then
cd "$target" || return 1
local agent_cmd
agent_cmd=$(command ws agent-cmd)
eval "$agent_cmd"
fi
fi
return $exit_code
else
command ws "$@"
fi
}
# Optional: completion
_ws_completions() {
if [[ ${COMP_CWORD} -eq 1 ]]; then
COMPREPLY=($(compgen -W "new ez list go home done fold status prune init" -- "${COMP_WORDS[1]}"))
elif [[ ${COMP_CWORD} -eq 2 ]]; then
case "${COMP_WORDS[1]}" in
go|done|fold|status)
local workspaces
workspaces=$(command ws list --quiet 2>/dev/null)
COMPREPLY=($(compgen -W "$workspaces" -- "${COMP_WORDS[2]}"))
;;
esac
fi
}
complete -F _ws_completions ws