Skip to content

Commit 455a8e3

Browse files
committed
refactor: Rename 'dbDir' to 'db_dir'
1 parent 41e0bf6 commit 455a8e3

File tree

5 files changed

+37
-37
lines changed

5 files changed

+37
-37
lines changed

completions/choose.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# shellcheck shell=bash
22

3-
dbDir="${CHOOSE_DB_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/choose/db}"
3+
db_dir="${CHOOSE_DB_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/choose/db}"
44

55
_in_arr() {
66
for e in "${@:2}"; do
@@ -15,12 +15,12 @@ _choose-set() {
1515
local cur="${COMP_WORDS[COMP_CWORD]}"
1616

1717
local -a dirs=()
18-
readarray -d $'\0' dirs < <(find "$dbDir" -maxdepth 1 -mindepth 1 -type d -printf '%f\0')
18+
readarray -d $'\0' dirs < <(find "$db_dir" -maxdepth 1 -mindepth 1 -type d -printf '%f\0')
1919

2020
# if we are completing the second element
2121
if _in_arr "${COMP_WORDS[2]}" "${dirs[@]}"; then
2222
local -a files=()
23-
readarray -d $'\0' files < <(find "$dbDir/${COMP_WORDS[2]}" -maxdepth 1 -mindepth 1 -type f -printf '%f\0')
23+
readarray -d $'\0' files < <(find "$db_dir/${COMP_WORDS[2]}" -maxdepth 1 -mindepth 1 -type f -printf '%f\0')
2424

2525
# remove _.current
2626
local -a files_filtered=()
@@ -43,7 +43,7 @@ _choose-launch() {
4343
local cur="${COMP_WORDS[COMP_CWORD]}"
4444

4545
local -a dirs=()
46-
readarray dirs < <(plumbing_list_dir "$dbDir")
46+
readarray dirs < <(plumbing_list_dir "$db_dir")
4747

4848
# shellcheck disable=SC2207
4949
COMPREPLY=($(IFS=' ' compgen -W "${dirs[*]}" -- "$cur"))

convert.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ set -e
77
shopt -s nullglob extglob globstar
88

99
main() {
10-
local dbDir="${CHOOSE_DB_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/choose/db}"
10+
local db_dir="${CHOOSE_DB_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/choose/db}"
1111

12-
for categoryDir in "$dbDir"/*; do
12+
for categoryDir in "$db_dir"/*; do
1313
if [ ! -d "$categoryDir" ]; then
1414
printf "%s\n" "Warning: Category dir '$categoryDir' is not a directory. Skipping"
1515
continue

pkg/lib/cmd/choose.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ source "$PROGRAM_LIB_DIR/helper.sh"
99
source "$PROGRAM_LIB_DIR/plumbing.sh"
1010
source "$PROGRAM_LIB_DIR/util.sh"
1111

12-
dbDir="${CHOOSE_DB_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/choose/db}"
12+
db_dir="${CHOOSE_DB_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/choose/db}"
1313

1414
main() {
1515
declare -A args=()

pkg/lib/do.sh

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ do_set() {
1919

2020
# -------------------------- set ------------------------- #
2121
# Source category pre
22-
if [ -f "$dbDir/$category/set-pre.sh" ]; then
23-
sh "$dbDir/$category/set-pre.sh" "$dbDir/$category" "$program"
22+
if [ -f "$db_dir/$category/set-pre.sh" ]; then
23+
sh "$db_dir/$category/set-pre.sh" "$db_dir/$category" "$program"
2424
fi
2525

2626
# Source program pre
27-
if [ -f "$dbDir/$category/$program/set-pre.sh" ]; then
28-
sh "$dbDir/$category/$program/set-pre.sh" "$dbDir/$category" "$program"
27+
if [ -f "$db_dir/$category/$program/set-pre.sh" ]; then
28+
sh "$db_dir/$category/$program/set-pre.sh" "$db_dir/$category" "$program"
2929
fi
3030

3131
# Actually set
32-
printf "%s" "$program" >| "$dbDir/$category/_.current"
32+
printf "%s" "$program" >| "$db_dir/$category/_.current"
3333

3434
# Source program post
35-
if [ -f "$dbDir/$category/$program/set-post.sh" ]; then
36-
sh "$dbDir/$category/$program/set-post.sh" "$dbDir/$category" "$program"
35+
if [ -f "$db_dir/$category/$program/set-post.sh" ]; then
36+
sh "$db_dir/$category/$program/set-post.sh" "$db_dir/$category" "$program"
3737
fi
3838

3939
# Source category post
40-
if [ -f "$dbDir/$category/set-post.sh" ]; then
41-
sh "$dbDir/$category/set-post.sh" "$dbDir/$category" "$program"
40+
if [ -f "$db_dir/$category/set-post.sh" ]; then
41+
sh "$db_dir/$category/set-post.sh" "$db_dir/$category" "$program"
4242
fi
4343

4444
log.info "Category '$category' defaults to '$program'"
@@ -54,11 +54,11 @@ do_launch() {
5454
category="$REPLY"
5555

5656
# Check to ensure category is set
57-
if [ ! -f "$dbDir/$category/_.current" ]; then
57+
if [ ! -f "$db_dir/$category/_.current" ]; then
5858
log.die "$gui" "Program for '$category' is not set. Please set with 'choose set'"
5959
fi
6060

61-
program="$(<"$dbDir/$category/_.current")"
61+
program="$(<"$db_dir/$category/_.current")"
6262

6363
# ensure variable (we already use 'ensure_has_dot_current' in
6464
# helper_get_category_filter; this is another safeguard)
@@ -68,40 +68,40 @@ do_launch() {
6868

6969
# ------------------------ launch ------------------------ #
7070
# Source category pre
71-
if [ -f "$dbDir/$category/launch-pre.sh" ]; then
72-
sh "$dbDir/$category/launch-pre.sh" "$dbDir/$category" "$program"
71+
if [ -f "$db_dir/$category/launch-pre.sh" ]; then
72+
sh "$db_dir/$category/launch-pre.sh" "$db_dir/$category" "$program"
7373
fi
7474

7575
# Source program pre
76-
if [ -f "$dbDir/$category/$program/launch-pre.sh" ]; then
77-
sh "$dbDir/$category/$program/launch-pre.sh" "$dbDir/$category" "$program"
76+
if [ -f "$db_dir/$category/$program/launch-pre.sh" ]; then
77+
sh "$db_dir/$category/$program/launch-pre.sh" "$db_dir/$category" "$program"
7878
fi
7979

8080
# Source launch if it exists. If otherwise, infer
8181
# the launch command from the program name
82-
if [ -f "$dbDir/$category/$program/launch.sh" ]; then
83-
if ! sh "$dbDir/$category/$program/launch.sh" "$dbDir/$category" "$program"; then
82+
if [ -f "$db_dir/$category/$program/launch.sh" ]; then
83+
if ! sh "$db_dir/$category/$program/launch.sh" "$db_dir/$category" "$program"; then
8484
log.die "$gui" "Source failed"
8585
fi
8686
else
8787
log.die "$gui" "launch.sh for program '$program' does not exist"
8888
fi
8989

9090
# Source program post
91-
if [ -f "$dbDir/$category/$program/launch-post.sh" ]; then
92-
sh "$dbDir/$category/$program/launch-post.sh" "$dbDir/$category" "$program"
91+
if [ -f "$db_dir/$category/$program/launch-post.sh" ]; then
92+
sh "$db_dir/$category/$program/launch-post.sh" "$db_dir/$category" "$program"
9393
fi
9494

9595
# Source category post
96-
if [ -f "$dbDir/$category/launch-post.sh" ]; then
97-
sh "$dbDir/$category/launch-post.sh" "$dbDir/$category" "$program"
96+
if [ -f "$db_dir/$category/launch-post.sh" ]; then
97+
sh "$db_dir/$category/launch-post.sh" "$db_dir/$category" "$program"
9898
fi
9999
}
100100

101101
do_print() {
102102
local category="$1"
103103

104-
program="$(<"$dbDir/$category/_.current")"
104+
program="$(<"$db_dir/$category/_.current")"
105105

106106
# ensure variable (we already use 'ensure_has_dot_current' in
107107
# helper_get_category_filter; this is another safeguard)

pkg/lib/helper.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ helper_get_category() {
2626
helper_get_cmd "$gui"
2727
local cmd="$REPLY"
2828

29-
if ! category="$(plumbing_list_dir "$dbDir" | $cmd)"; then
29+
if ! category="$(plumbing_list_dir "$db_dir" | $cmd)"; then
3030
log.die "$gui" "Did not complete previous selection properly"
3131
fi
3232
fi
3333

3434
# validate
35-
if [ ! -d "$dbDir/$category" ]; then
35+
if [ ! -d "$db_dir/$category" ]; then
3636
log.die "$gui" "Application category '$category' does not exist"
3737
fi
3838

@@ -52,14 +52,14 @@ helper_get_category_filter() {
5252

5353
ensure_has_dot_current() {
5454
while IFS= read -r dir; do
55-
if [ -f "$dbDir/$dir/_.current" ]; then
55+
if [ -f "$db_dir/$dir/_.current" ]; then
5656
echo "$dir"
5757
fi
5858
done
5959
}
6060

6161
if ! category="$(
62-
plumbing_list_dir "$dbDir" \
62+
plumbing_list_dir "$db_dir" \
6363
| ensure_has_dot_current \
6464
| grep "\S" \
6565
| $userSelectCmd
@@ -69,9 +69,9 @@ helper_get_category_filter() {
6969
fi
7070

7171
# validate
72-
if [ ! -d "$dbDir/$category" ]; then
72+
if [ ! -d "$db_dir/$category" ]; then
7373
log.die "$gui" "Application category '$category' does not exist"
74-
elif [ ! -s "$dbDir/$category/_.current" ]; then
74+
elif [ ! -s "$db_dir/$category/_.current" ]; then
7575
log.die "$gui" "Application category '$category' does not have a default program associated with it"
7676
fi
7777

@@ -90,7 +90,7 @@ helper_get_program() {
9090
userSelectCmd="$REPLY"
9191

9292
if ! program="$(
93-
plumbing_list_dir "$dbDir/$category" \
93+
plumbing_list_dir "$db_dir/$category" \
9494
| grep -v "_.current" \
9595
| $userSelectCmd
9696
)"; then
@@ -99,7 +99,7 @@ helper_get_program() {
9999
fi
100100

101101
# validate variable
102-
if [ ! -d "$dbDir/$category/$program" ]; then
102+
if [ ! -d "$db_dir/$category/$program" ]; then
103103
log.die "$gui" "Application '$program' does not exist"
104104
fi
105105

0 commit comments

Comments
 (0)