3 ms·
This seems insanely over-engineered. So I re-wrote most of them as bash alias one-liners. # Encrypt a file function encrypt() { openssl enc -aes-256-cbc -s
by skanga 9y ago
This seems insanely over-engineered. So I re-wrote most of them as bash alias one-liners.
# Encrypt a file
function encrypt() { openssl enc -aes-256-cbc -salt -a -in $1 -out $2 ; }
# Decrypt a file
function decrypt() { openssl enc -aes-256-cbc -d -a -in $1 -out $2 ; }
# Fetch weather forecast
function weather() { curl "http://wttr.in/$1"; }
# Convert input text into a QR code
function qrify() { curl "http://qrenco.de/$1"; }
# Fetch information about a stock
function stock() { curl -s "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=AAPL&apikey=KPCCCRJVMOGN9L6T" | awk '/\. / {$1=""; gsub("\"|,",""); print $0}'; }
# Conversion rate between currencies
function currency { curl -s "http://api.fixer.io/latest?base=$1&symbols=$2" | grep -Eo "[0-9]*[.][0-9]*"; }
# Fetch movie info
function movie { curl -s "http://www.omdbapi.com/?t=${1/ /+}&apikey=946f500a" | jq ". | {Title, Year, Ratings:[.Ratings[1].Source, .Ratings[1].Value ], Rated, Genre, Director, Actors, Plot}" | awk -F "\"" '/:|%|Tomato/ {print $2 $3 $4}' | sed '/: \[/d' | perl -pe 's/,\n/: /'; }
# Fetch cheatsheet
function cheat() { curl "http://cheat.sh/$1"; }
# Fetches DNS nameserver ???
function dns_nameserver() { cat /etc/resolv.conf | grep -i ^nameserver | cut -d ' ' -f2; }
# Fetches WAN ip address ???
function wan_search() { dig +short myip.opendns.com @resolver1.opendns.com ; }
# Show actual destinatoin of a tinyurl. Eg: untiny "tinyurl.com/savepii"
function untiny() { curl -s "http://x.datasig.io/short?url=http://$1" | awk -F '"' '/d
- aaronchall 9y agoVery nice, but if you lose the function keyword and just use name () {... ; } you'll have greater cross-shell compatibility and they'll be a little shorter.
- skanga 9y agoThanks. Good idea.
- aaronchall 9y agoI see you made the changes in a new post below. Very cool, but maybe a gist or repo on github would be better?
- aoneill 9y agoIn the stock() function, replace AAPL with $1.
- skanga 9y agoThanks. will do.
- stevekemp 9y agoCute rewrites, but I think you could do better a lot of the time. For example rather than using `cat`, `grep`, and `cut`, just use awk: function dns_nameserver() { awk '/nameserver/ {print $2}' /etc/resolv.conf }
- skanga 9y agoNice. Will do.