Skip to content

Commit

Permalink
Removed some inactive functions and added encrypt/decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
eko committed Feb 8, 2019
1 parent 56f86f2 commit e0cdbce
Showing 1 changed file with 18 additions and 45 deletions.
63 changes: 18 additions & 45 deletions .functions
Expand Up @@ -25,56 +25,29 @@ function cleanup() {
fd -t d '(cache|log)' ~/dev ~ | grep -E '(app|var)/(cache|log)' | xargs rm -rf
}

# Usage: crypto <money> <currency>
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 <money> <currency> [<wallet amount> [<alert amount>]]
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 <string>
# Then, a password is prompted
function encrypt() {
result=`echo -n "$*" | openssl enc -e -aes-256-cbc -a`

sleep 15
done
echo -e "$result"
echo -e "\nTo decrypt the value, use:"
echo -e "$ echo \"$result\" | openssl base64 -d | openssl enc -d -aes-256-cbc"
}

# Preview CSVs
function csvpreview() {
sed 's/,,/, ,/g;s/,,/, ,/g' "$@" | column -s, -t | less -#2 -N -S
# Usage: decrypt <string>
# Then, a password is prompted
function decrypt() {
echo "$*" | openssl base64 -d | openssl enc -d -aes-256-cbc
}

# Usage: encrypt file <output> (default: file.gpg)
function encrypt() {
# Usage: encryptfile <filepath> <output> (default: file.gpg)
function encryptfile() {
output="$1.gpg"

if [ -n "$2" ]; then
Expand All @@ -84,8 +57,8 @@ function encrypt() {
gpg2 --encrypt --recipient vincent --output $output $1
}

# Usage: decrypt file <output>
function decrypt() {
# Usage: decryptfile <filepath> <output>
function decryptfile() {
command="gpg2 --decrypt $1"

if [ -n "$2" ]; then
Expand Down

0 comments on commit e0cdbce

Please sign in to comment.