3 Commits

Author SHA1 Message Date
  Alois Mahdal 3d339ede0e Drop extraneous today's date URI element 3 years ago
  Alois Mahdal 4903a49feb Drop `which` in favor of the more standard `command -v` 3 years ago
  Alois Mahdal 1cc61972fd Add support for float currency values 3 years ago
2 changed files with 9 additions and 13 deletions
  1. 8
    12
      bin/czkrates
  2. 1
    1
      bin/mdvimb

+ 8
- 12
bin/czkrates View File

@@ -33,15 +33,12 @@ usage() {
33 33
 
34 34
 type_of() {
35 35
     #
36
-    # Print 'int' if $1 is an integer, 'nil' if empty; 'str' otherwise
36
+    # Print 'num' if $1 is a number (float or integer), 'nil' if empty; 'str' otherwise
37 37
     #
38
-    local es_p es_n
39 38
     test -z "$1" && echo nil && return
40
-    test "$1" -ge 0 2>/dev/null; es_p=$?    # assuming positive
41
-    test "$1" -lt 0 2>/dev/null; es_n=$?    # assuming negative
42
-    test $es_p -eq 2 && echo str && return
43
-    test $es_n -eq 2 && echo str && return
44
-    echo int
39
+    grep -qxEe '-?[0-9]*[.][0-9]+' <<<"$1" && echo num && return
40
+    grep -qxEe '-?[0-9]+' <<<"$1"          && echo num && return
41
+    echo str
45 42
 }
46 43
 
47 44
 parse_rate1() {
@@ -103,7 +100,6 @@ main() {
103 100
     local Mult
104 101
     local Date=now
105 102
     Uri=$CZKRATES_URL
106
-    Uri+="?date=$(date +%d.%m.%Y)"
107 103
     #shellcheck disable=SC2034
108 104
     while true; do case "$1" in
109 105
         -D|--date)    Date=$2;  shift 2 || usage ;;
@@ -114,11 +110,11 @@ main() {
114 110
     esac done
115 111
     Uri+="?date=$(date -d "$Date" +%d.%m.%Y)"
116 112
     case "$(type_of "$1"):$(type_of "$2")" in
117
-        int:int|str:str)    usage ;;
118
-        int:nil|nil:int)    Mult="$1$2"          ;;
113
+        num:num|str:str)    usage ;;
114
+        num:nil|nil:num)    Mult="$1$2"          ;;
119 115
         str:nil|nil:str)    Curr="$1$2"          ;;
120
-        str:int)            Curr="$1"; Mult="$2" ;;
121
-        int:str)            Curr="$2"; Mult="$1" ;;
116
+        str:num)            Curr="$1"; Mult="$2" ;;
117
+        num:str)            Curr="$2"; Mult="$1" ;;
122 118
     esac
123 119
     Curr="${Curr:-$CZKRATES_DEFAULT_CURRENCY}"
124 120
     Curr="${Curr^^}"

+ 1
- 1
bin/mdvimb View File

@@ -140,7 +140,7 @@ main() {
140 140
     MdFile=$1; shift
141 141
     debug -v MDVIMB__CONVERTER MDVIMB__CONFIG_HOME MDVIMB__STYLE
142 142
     debug -v MdFile converter NoOpen Wrap Style ConfigHome
143
-    converterpath=$(which "$converter") \
143
+    converterpath=$(command -v "$converter") \
144 144
      || die "converter not available: $converter"
145 145
     debug -v converterpath
146 146
     think "using converter: $converter"