From db58a32638f78e8e77b20fa162fe68b85fee9472 Mon Sep 17 00:00:00 2001 From: Vincent Composieux Date: Sat, 9 Feb 2019 00:24:31 +0100 Subject: [PATCH] Removed some inactive functions and added encrypt/decrypt --- .functions | 83 +++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 45 deletions(-) diff --git a/.functions b/.functions index 806b2f2..956b047 100644 --- a/.functions +++ b/.functions @@ -25,56 +25,49 @@ function cleanup() { fd -t d '(cache|log)' ~/dev ~ | grep -E '(app|var)/(cache|log)' | xargs rm -rf } -# Usage: crypto -function crypto() { - curl -s https://api.cryptonator.com/api/ticker/$1-$2 | jq -r '.ticker .price' +# Preview CSVs +function csvpreview() { + sed 's/,,/, ,/g;s/,,/, ,/g' "$@" | column -s, -t | less -#2 -N -S } -# Usage: cryptowatch [ []] -function cryptowatch() { - latest=0 - - while true; do - value=$(crypto $1 $2) - current=`printf "%.2f" $(( value ))` - date=$(date "+%H:%M:%S") - operator="${YELLOW}=${NC}" - walletvalue=0 - - # Find operator - if (( $(echo "$value > $latest" | bc -l) )); then - operator="${GREEN}⬆${NC}" - elif (( $(echo "$value < $latest" | bc -l) )); then - operator="${RED}⬇${NC}" - fi - - latest=$value - - display="$operator | $date | $1: ${YELLOW}$current${NC}" - - if [ -n "$3" ]; then - walletvalue=`printf "%.2f" $(( $3 * $value ))` - display="$display | $2: ${YELLOW}$walletvalue${NC}" - fi - - echo $display - - # Amount reached? Notify - if [ -n "$4" ] && (( $(echo "$value >= $4" | bc -l) )); then - osascript -e "display notification "$value" with title \"Cryptowatch\" subtitle \"Current value:\"" - fi +# Usage: encrypt +# Then, a password is prompted +function encrypt() { + input=$* + if [ -z "$input" ]; then + input=`cat $filename + echo -e "------------\n${YELLOW}Encrypted output has been stored into following file:${NC}" + echo -e "$filename" + echo -e "------------" + echo -e "${YELLOW}To decrypt the value, use:" + echo -e "${GREEN}\$${NC} cat \"$filename\" | openssl base64 -d | openssl enc -d -aes-256-cbc" + else + echo -e "------------\n${YELLOW}Encrypted output:${NC}" + echo -e "$result" + echo -e "------------" + echo -e "${YELLOW}To decrypt the value, use:" + echo -e "${GREEN}\$${NC} echo \"$result\" | openssl base64 -d | openssl enc -d -aes-256-cbc" + fi } -# Preview CSVs -function csvpreview() { - sed 's/,,/, ,/g;s/,,/, ,/g' "$@" | column -s, -t | less -#2 -N -S +# Usage: decrypt +# Then, a password is prompted +function decrypt() { + echo "$*" | openssl base64 -d | openssl enc -d -aes-256-cbc } -# Usage: encrypt file (default: file.gpg) -function encrypt() { +# Usage: encryptfile (default: file.gpg) +function encryptfile() { output="$1.gpg" if [ -n "$2" ]; then @@ -84,8 +77,8 @@ function encrypt() { gpg2 --encrypt --recipient vincent --output $output $1 } -# Usage: decrypt file -function decrypt() { +# Usage: decryptfile +function decryptfile() { command="gpg2 --decrypt $1" if [ -n "$2" ]; then