Skip to content

Commit 124a69f

Browse files
committed
initConfig function moved to central shellmenu.sh for re-use by clients
1 parent dfbd12a commit 124a69f

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

EasyKey.git/ezk-git-functions.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ function atlassiansView() {
287287

288288
function changeProject () {
289289
source $script_dir/../EasyKey.git/ezk-git-loca.sh
290+
noterminate
290291
nowaitonexit
291292
}
292293

EasyKey.git/ezk-git-loca.sh

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,9 @@ function purgDirCache () {
1919
unset gitlocations
2020
}
2121

22-
initConfig () {
23-
# read config to global arrays
24-
INPUT="$script_dir"/"$configfilename"
25-
[ ! -f "$INPUT" ] && { echo "$INPUT file not found"; exit 99; }
26-
i=0
27-
configlines=$(cat "$INPUT")
28-
while read -r configline; do
29-
if echo "$configline" | grep -q "\[.*\]"; then
30-
configsection=$(echo "$configline" | grep -o "\[.*\]")
31-
configsectioname=${configsection:1:${#configsection}-2}
32-
i=0
33-
continue
34-
fi
35-
if [ -n "$configline" ]; then
36-
eval "${configsectioname}+=('$configline')"
37-
fi
38-
((i++))
39-
done <<< "$(echo -e "$configlines")"
40-
}
41-
42-
initConfig
22+
# Reads the config into global array "workspaces"
23+
# The config needs to have that section [workspaces]
24+
initConfig "${script_dir}/${configfilename}"
4325

4426
clear
4527
thekeys=($(echo {a..p}) $(echo {r..z}) $(echo {1..9}) $(echo {A..Z}))
@@ -79,8 +61,6 @@ done
7961
if $uncached; then coloredLog "NEW" "1;42"; else coloredLog "CACHED" "1;42"; fi
8062
submenuHead "Shortcuts"
8163
menuItem X "Purge git dir cache" purgDirCache
82-
echo
83-
menuItem q "Quit" quit
8464
choice
8565

8666
unset locations workspaces

shellmenu.sh

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,4 +635,36 @@ wait_for_keypress() {
635635
stty raw
636636
REPLY=$(dd bs=1 count=1 2> /dev/null)
637637
stty -raw
638-
}
638+
}
639+
640+
######################################################
641+
# A magic function that reads a file with sections
642+
# into global arrays named by this section.
643+
# Sections in the file start with [<section name>].
644+
# After that section heading the config lines follow.
645+
# A new section begins with [<new section name>].
646+
# Arguments:
647+
# $1: the config filename to read
648+
# Outputs:
649+
# Global arrays that have the name of the sections
650+
# in the config file.
651+
######################################################
652+
initConfig () {
653+
# read config to global arrays
654+
INPUT="$1"
655+
[ ! -f "$INPUT" ] && { echo "$INPUT file not found"; exit 99; }
656+
i=0
657+
configlines=$(cat "$INPUT")
658+
while read -r configline; do
659+
if echo "$configline" | grep -q "\[.*\]"; then
660+
configsection=$(echo "$configline" | grep -o "\[.*\]")
661+
configsectioname=${configsection:1:${#configsection}-2}
662+
i=0
663+
continue
664+
fi
665+
if [ -n "$configline" ]; then
666+
eval "${configsectioname}+=('$configline')"
667+
fi
668+
((i++))
669+
done <<< "$(echo -e "$configlines")"
670+
}

0 commit comments

Comments
 (0)