Skip to content

Commit 6d769e6

Browse files
committed
Refactored mode switching
- Replaced all mode variables with a single variable that holds a string
1 parent 8fa1843 commit 6d769e6

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

vims

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ vim_cmds=()
55

66
PRINT_ALL=1
77
DISABLE_VIMRC=0
8-
EXE_MODE=0
9-
INVERSE_EXE_MODE=0
10-
SIMPLE_MODE=0
11-
LINE_EXE_MODE=0
8+
MODE=none
129

1310
while (($# > 0)); do
1411
arg="$1"
@@ -22,67 +19,52 @@ while (($# > 0)); do
2219
shift
2320
;;
2421
-e|--exe-mode)
25-
EXE_MODE=1
26-
SIMPLE_MODE=0
27-
INVERSE_EXE_MODE=0
28-
LINE_EXE_MODE=0
22+
MODE=exe
2923
shift
3024
;;
3125
-r|--inverse-exe-mode)
32-
INVERSE_EXE_MODE=1
33-
SIMPLE_MODE=0
34-
EXE_MODE=0
35-
LINE_EXE_MODE=0
26+
MODE=inverse-exe
3627
shift
3728
;;
3829
-l|--line-exe-mode)
39-
LINE_EXE_MODE=1
40-
SIMPLE_MODE=0
41-
INVERSE_EXE_MODE=0
42-
EXE_MODE=0
30+
MODE=line-exe
4331
shift
4432
;;
4533
-s|--simple-mode)
46-
SIMPLE_MODE=1
47-
INVERSE_EXE_MODE=0
48-
EXE_MODE=0
49-
LINE_EXE_MODE=0
34+
MODE=simple
5035
shift
5136
;;
5237
-t|--turn-off-mode)
53-
SIMPLE_MODE=0
54-
INVERSE_EXE_MODE=0
55-
EXE_MODE=0
56-
LINE_EXE_MODE=0
38+
MODE=none
5739
shift
5840
;;
5941
*)
60-
if [ "$EXE_MODE" -eq "0" ] && [ "$INVERSE_EXE_MODE" -eq "0" ] && [ "$SIMPLE_MODE" -eq "0" ] && [ "$LINE_EXE_MODE" -eq "0" ]; then
42+
if [ "$MODE" = "none" ]; then
6143
vim_cmds+=(-c "$1")
6244
shift
63-
elif [ "$EXE_MODE" -eq "1" ] && [ "$INVERSE_EXE_MODE" -eq "0" ] && [ "$SIMPLE_MODE" -eq "0" ] && [ "$LINE_EXE_MODE" -eq "0" ]; then
45+
elif [ "$MODE" = "exe" ]; then
6446
SEARCH="$1"
6547
CMD="$2"
6648
vim_cmds+=(-c "%g/${SEARCH}/exe \"norm ${CMD}\"")
6749
shift
6850
shift
69-
elif [ "$EXE_MODE" -eq "0" ] && [ "$INVERSE_EXE_MODE" -eq "1" ] && [ "$SIMPLE_MODE" -eq "0" ] && [ "$LINE_EXE_MODE" -eq "0" ]; then
51+
elif [ "$MODE" = "inverse-exe" ]; then
7052
SEARCH="$1"
7153
CMD="$2"
7254
vim_cmds+=(-c "%v/${SEARCH}/exe \"norm ${CMD}\"")
7355
shift
7456
shift
75-
elif [ "$EXE_MODE" -eq "0" ] && [ "$INVERSE_EXE_MODE" -eq "0" ] && [ "$SIMPLE_MODE" -eq "1" ] && [ "$LINE_EXE_MODE" -eq "0" ]; then
57+
elif [ "$MODE" = "simple" ]; then
7658
CMD="$1"
7759
vim_cmds+=(-c ":exe \"norm gg""${CMD}""\"")
7860
shift
79-
elif [ "$EXE_MODE" -eq "0" ] && [ "$INVERSE_EXE_MODE" -eq "0" ] && [ "$SIMPLE_MODE" -eq "0" ] && [ "$LINE_EXE_MODE" -eq "1" ]; then
61+
elif [ "$MODE" = "line-exe" ]; then
8062
CMD="$1"
8163
vim_cmds+=(-c ":%g/.*/exe \"norm ""${CMD}""\"")
8264
shift
8365
else
84-
echo "Mode conflict for vims! Please select only one mode."
85-
echo "Modes enabled: exe-mode? $EXE_MODE, inverse-exe-mode? $INVERSE_EXE_MODE, simple-mode? $SIMPLE_MODE, line-exe-mode? $LINE_EXE_MODE"
66+
echo "Mode not known to vims! Please select a known mode."
67+
echo "Mode selected: $MODE"
8668
exit 1
8769
fi
8870
;;

0 commit comments

Comments
 (0)