-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_cargo.sh
executable file
·80 lines (59 loc) · 1.5 KB
/
run_cargo.sh
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
76
77
78
#!/usr/bin/env bash
commands=`echo "build check clean doc new init add run test select_test bench update publish custom" | tr ' ' '\n'`
selected=`printf "$commands" | fzf`
function read_query() {
local query_message=$1
read -p "$query_message: " query
if [[ -z $query ]]; then
exit
fi
return query
}
# Go to crate root
cd $1
# Exit if nothing selected
if [[ -z $selected ]]; then
exit
# Search crates
elif [ $selected = "search" ]; then
query=$(read_query "Search")
cargo $selected $query
# Install binary
elif [ $selected = "install" ]; then
query=$(read_query "Install")
cargo $selected $query
# Create new crate
elif [ $selected = "new" ]; then
query=$(read_query "New")
cargo $selected $query
# Add dependency
elif [ $selected = "add" ]; then
query=$(read_query "Add")
cargo $selected $query
# Parse all tests and do fzf
elif [ $selected = "select_test" ]; then
tests=`cargo test -- --list --format=terse 2> /dev/null | sed 's/: .*//g'`
test=`printf "$tests" | fzf`
# Exit if nothing selected
if [[ -z $test ]]; then
exit
else
cargo test $test
fi
# Run all tests and enter copy mode
elif [ $selected = "test" ]; then
cargo $selected
# Read custom command
elif [ $selected = "custom" ]; then
query=$(read_query "Enter cargo arguments")
cargo $query
# Just run selected command
else
cargo $selected
fi
echo
echo "COMPLETE"
tmux copy-mode
tmux send-keys 'k0'
# Prevent window to close
read -n 1 -s