@@ -31,18 +31,29 @@ main(){
31
31
32
32
(( _o[verbose])) || _qflag=' -q'
33
33
34
- # mode is first arg, size|move|x|0-9 -> s|m|x|0-9
35
- _next_mode=" ${1: 0: 1} " ; _next_mode=" ${_next_mode,,} "
34
+ [[ ${_next_mode:= ${1,,} } =~ ^(l| r| u| d| left| right| up| down| [0-9]| size| move| s| m| x)$ ]] \
35
+ || ERX " i3Kornhe: mode ('$1 ') is not valid!"
36
+
37
+ _next_mode=${_next_mode: 0: 1} ; mode=$1
38
+ shift
39
+
40
+ [[ ! $_next_mode =~ s| m && ${#@ } -gt 0 ]] \
41
+ && ERX " i3Kornhe: mode ('$mode ') expected 0 arguments got '($* )'"
42
+
43
+ [[ $_next_mode =~ s| m && ${#@ } -gt 1 ]] \
44
+ && ERX " i3Kornhe: mode ('$mode ') expected 0-1 arguments got '($* )'"
36
45
37
- __lastarg=${!# }
38
- # last arg is direction, left|right|up|down -> l|r|u|d
39
- _direction=${__lastarg: 0: 1} ; _direction=${_direction,,}
46
+ [[ ${_direction:= ${1,,} } ]] && {
47
+ [[ ${_direction} =~ ^(l| r| u| d| left| right| up| down| [0-9])$ ]] \
48
+ || ERX " i3Kornhe: direction ('$_direction ') is not valid!" \
49
+ " ( left|right|up|down|l|r|u|d|0-9 )"
50
+ }
51
+
52
+ : " ${_direction:= $_next_mode } " ; _direction=${_direction: 0: 1}
40
53
41
- # remove all none digits from --speed arg
42
54
_speed=${_o[speed]// [!0-9]}
43
55
(( _speed >= 0 )) || _speed=10
44
56
45
-
46
57
_margin=${_o[margin]// [!0-9]}
47
58
(( _margin >= 0 )) || _margin=5
48
59
@@ -71,7 +82,6 @@ main(){
71
82
rm -f " $I3_KORNHE_FIFO_FILE "
72
83
mkdir -p " ${I3_KORNHE_FIFO_FILE%/* } "
73
84
mkfifo " $I3_KORNHE_FIFO_FILE "
74
-
75
85
echo " $_direction $_next_mode $_speed $_margin " >> " $I3_KORNHE_FIFO_FILE " &
76
86
trap ' CLEANUP' EXIT INT HUP
77
87
0 commit comments