Skip to content

Commit 2a4ef2b

Browse files
committed
feat: Add 'post' and 'pre' hooks for 'set' and 'launch'
And rename the ones that already exist
1 parent 14be4bc commit 2a4ef2b

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

pkg/lib/cmd/choose.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ main() {
4848

4949
do_print "$category" "$gui"
5050
;;
51+
*)
52+
log.die "Subcommand '${argsCommands[0]}' not found"
5153
esac
5254
}
5355

pkg/lib/do.sh

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,30 @@ do_set() {
1717
fi
1818
program="$REPLY"
1919

20+
# -------------------------- set ------------------------- #
21+
# Source category pre
22+
if [ -f "$dbDir/$category/set-pre.sh" ]; then
23+
source "$dbDir/$category/set-pre.sh"
24+
fi
25+
26+
# Source program pre
27+
if [ -f "$dbDir/$category/$program/set-pre.sh" ]; then
28+
source "$dbDir/$category/$program/set-pre.sh"
29+
fi
30+
2031
# Actually set
2132
printf "%s" "$program" >| "$dbDir/$category/_.current"
2233

34+
# Source program post
35+
if [ -f "$dbDir/$category/$program/set-post.sh" ]; then
36+
source "$dbDir/$category/$program/set-post.sh"
37+
fi
38+
39+
# Source category post
40+
if [ -f "$dbDir/$category/set-post.sh" ]; then
41+
source "$dbDir/$category/set-post.sh"
42+
fi
43+
2344
log.info "Category '$category' defaults to '$program'"
2445
}
2546

@@ -47,13 +68,13 @@ do_launch() {
4768

4869
# ------------------------ launch ------------------------ #
4970
# Source category pre
50-
if [ -f "$dbDir/$category/pre.sh" ]; then
51-
source "$dbDir/$category/pre.sh"
71+
if [ -f "$dbDir/$category/launch-pre.sh" ]; then
72+
source "$dbDir/$category/launch-pre.sh"
5273
fi
5374

5475
# Source program pre
55-
if [ -f "$dbDir/$category/$program/pre.sh" ]; then
56-
source "$dbDir/$category/$program/pre.sh"
76+
if [ -f "$dbDir/$category/$program/launch-pre.sh" ]; then
77+
source "$dbDir/$category/$program/launch-pre.sh"
5778
fi
5879

5980
# Source launch if it exists. If otherwise, infer
@@ -63,21 +84,17 @@ do_launch() {
6384
log.die "$gui" "Source failed"
6485
fi
6586
else
66-
if ! command -v "$program" &>/dev/null; then
67-
log.die "$gui" "Executable '$program' does not exist or is not in the current environment"
68-
fi
69-
70-
exec "$program"
87+
log.die "$gui" "launch.sh for program '$program' does not exist"
7188
fi
7289

7390
# Source program post
74-
if [ -f "$dbDir/$category/$program/post.sh" ]; then
75-
source "$dbDir/$category/$program/post.sh"
91+
if [ -f "$dbDir/$category/$program/launch-post.sh" ]; then
92+
source "$dbDir/$category/$program/launch-post.sh"
7693
fi
7794

7895
# Source category post
79-
if [ -f "$dbDir/$category/post.sh" ]; then
80-
source "$dbDir/$category/post.sh"
96+
if [ -f "$dbDir/$category/launch-post.sh" ]; then
97+
source "$dbDir/$category/launch-post.sh"
8198
fi
8299
}
83100

0 commit comments

Comments
 (0)