dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 19480bcf06bef3ba81cba5d9f5e3862b261deb73
parent 73f657bf57f789c45da78cd623163df1567424ea
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Thu, 25 Jul 2019 18:25:43 +0200

Shell script improvements

Diffstat:
D.local/bin/colors.sh | 26--------------------------
M.local/bin/currency | 16+++++++++-------
2 files changed, 9 insertions(+), 33 deletions(-)

diff --git a/.local/bin/colors.sh b/.local/bin/colors.sh @@ -1,26 +0,0 @@ -#!/bin/bash -# -# This file echoes a bunch of color codes to the -# terminal to demonstrate what's available. Each -# line is the color code of one forground color, -# out of 17 (default + 16 escapes), followed by a -# test use of that color on all nine background -# colors (default + 8 escapes). -# - -T='gYw' # The test text - -echo -e "\n 40m 41m 42m 43m\ - 44m 45m 46m 47m"; - -for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \ - '1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \ - ' 36m' '1;36m' ' 37m' '1;37m'; - do FG=${FGs// /} - echo -en " $FGs \033[$FG $T " - for BG in 40m 41m 42m 43m 44m 45m 46m 47m; - do echo -en "$EINS \033[$FG\033[$BG $T \033[0m"; - done - echo; -done -echo diff --git a/.local/bin/currency b/.local/bin/currency @@ -1,10 +1,12 @@ -#!/bin/bash +#!/bin/sh set -e if [ $# -lt 1 ]; then - echo -e "Usage: $0 [amount] [currency1] [currency2]\n" + echo "Usage: $0 [amount] [currency1] [currency2]" + echo echo "If currency1 and currency2 and are not defined they default to USD and DKK, respectively." - echo -e "Currency strings are not case sensitive. The amount defaults to 1.\n" + echo "Currency strings are not case sensitive. The amount defaults to 1." + echo echo "Example 1: $0 USD GBP" echo "Example 2: $0 42" echo "Example 3: $0 14 GBP EUR" @@ -12,13 +14,13 @@ if [ $# -lt 1 ]; then fi toUpper() { - echo $@ | tr "[:lower:]" "[:upper:]" + echo "$@" | tr "[:lower:]" "[:upper:]" } if [ -n "$1" ]; then A=$1; else A=1; fi if [ -n "$2" ]; then FROM=$(echo "$2" | awk '{print toupper($0)}'); else FROM=USD; fi if [ -n "$3" ]; then TO=$(echo "$3" | awk '{print toupper($0)}'); else TO=DKK; fi -if [ $TO == $FROM ]; then echo "Nothing to do!"; exit 2; fi +if [ "$TO" = "$FROM" ]; then echo "Nothing to do!"; exit 2; fi #CONVERTER="https://finance.google.com/finance/converter?a=$A&from=$FROM&to=$TO" CONVERTER="https://free.currencyconverterapi.com/api/v6/convert?q=${FROM}_${TO}&compact=ultra&apiKey=$(pass Online/currencyconverterapi.com-apikey)" @@ -27,7 +29,7 @@ CONVERTER="https://free.currencyconverterapi.com/api/v6/convert?q=${FROM}_${TO}& GETCMD="wget --no-verbose" #if command -v torsocks >/dev/null 2>/dev/null; then -# GETCMD="torsocks $GETCMD" +# GETCMD="torsocks $GETCMD" #fi # google finance @@ -43,4 +45,4 @@ RESULT=$($GETCMD -O - "$CONVERTER" 2>/dev/null | sed 's/.*://' | sed 's/\}$//') #echo $RESULT # currencyconverterapi -echo $A $FROM = $(echo "${RESULT}*${A}" | bc -l) $TO +echo "$A $FROM = $(echo "${RESULT}*${A}" | bc -l) $TO"