Split curl scripts

This commit is contained in:
Hoang Nguyen 2021-03-13 18:34:45 +03:00
parent 21885bb001
commit 0823dfb1e6
No known key found for this signature in database
GPG Key ID: 813CF484F4993419
22 changed files with 138 additions and 23 deletions

View File

@ -43,7 +43,7 @@
- **Shell prompt:** [starship](https://starship.rs/)
- **Anime/Manga/Wallpaper:** [gallery-dl](https://github.com/mikf/gallery-dl) / [mangadl-bash](https://github.com/Akianonymus/mangadl-bash), [anime-downloader](https://github.com/anime-dl/anime-downloader) + [trackma](https://github.com/z411/trackma) + [adl](https://github.com/RaitaroH/adl) / [anigrab](https://github.com/ngomile/anigrab)
- **CLI/TUI for the Internet:** [translate-shell](https://github.com/soimort/translate-shell) / [argos-translate](https://github.com/argosopentech/argos-translate), [ddgr](https://github.com/jarun/ddgr), [howdoi](https://github.com/gleitz/howdoi), [amfora](https://github.com/makeworld-the-better-one/amfora), [cointop](https://github.com/miguelmota/cointop), [newsboat](https://github.com/newsboat/newsboat), [youtube-dl](https://github.com/ytdl-org/youtube-dl) + [ytmdl](https://github.com/deepjyoti30/ytmdl), [github-cli](https://github.com/cli/cli), [pup](https://github.com/ericchiang/pup), [weechat](https://github.com/weechat/weechat), [curl](https://curl.haxx.se) / [wget](https://www.gnu.org/software/wget/wget.html) / [aria2](https://github.com/aria2/aria2), [tremc](https://github.com/tremc/tremc) + [transmission](https://github.com/transmission/transmission) / [rtorrent](https://github.com/rakshasa/rtorrent), [goaccess](https://github.com/allinurl/goaccess)
- **CLI/TUI for other things:** [tt](https://github.com/runrin/tt), [forgit](https://github.com/wfxr/forgit), [borg](https://github.com/borgbackup/borg), [wendy](https://git.z3bra.org/wendy/log.html), [tokei](https://github.com/XAMPPRocky/tokei), [onefetch](https://github.com/o2sh/onefetch), [calcurse](https://github.com/lfos/calcurse), [qalculate](https://github.com/Qalculate/libqalculate), [fzf](https://github.com/junegunn/fzf), [fd](https://github.com/sharkdp/fd), [ripgrep](https://github.com/BurntSushi/ripgrep), [atool](http://www.nongnu.org/atool/), [rsync](https://rsync.samba.org/), [bottom](https://github.com/clementtsang/bottom), [hyperfine](https://github.com/sharkdp/hyperfine), [delta](https://github.com/dandavison/delta), [bat](https://github.com/sharkdp/bat), [glow](https://github.com/charmbracelet/glow) / [mdcat](https://github.com/lunaryorn/mdcat) / [mdr](https://github.com/MichaelMure/mdr), [exa](https://github.com/ogham/exa), [pandoc](https://github.com/jgm/pandoc), [csview](https://github.com/wfxr/csview), [libsixel](https://github.com/saitoha/libsixel), [buku](https://github.com/jarun/buku), [jq](https://github.com/stedolan/jq), [zoxide](https://github.com/ajeetdsouza/zoxide) / [z.lua](https://github.com/skywind3000/z.lua), [xlsx2csv](https://github.com/dilshod/xlsx2csv), sysstat, psmisc, wireless_tools, tree, renameutils
- **CLI/TUI for other things:** [tt](https://github.com/runrin/tt), [forgit](https://github.com/wfxr/forgit), [borg](https://github.com/borgbackup/borg), [wendy](https://git.z3bra.org/wendy/log.html), [tokei](https://github.com/XAMPPRocky/tokei), [onefetch](https://github.com/o2sh/onefetch), [calcurse](https://github.com/lfos/calcurse), [qalculate](https://github.com/Qalculate/libqalculate), [fzf](https://github.com/junegunn/fzf), [fd](https://github.com/sharkdp/fd), [ripgrep](https://github.com/BurntSushi/ripgrep), [atool](http://www.nongnu.org/atool/), [rsync](https://rsync.samba.org/), [bottom](https://github.com/clementtsang/bottom), [hyperfine](https://github.com/sharkdp/hyperfine), [delta](https://github.com/dandavison/delta), [bat](https://github.com/sharkdp/bat), [glow](https://github.com/charmbracelet/glow) / [mdcat](https://github.com/lunaryorn/mdcat) / [mdr](https://github.com/MichaelMure/mdr), [exa](https://github.com/ogham/exa), [pandoc](https://github.com/jgm/pandoc), [csview](https://github.com/wfxr/csview), [libsixel](https://github.com/saitoha/libsixel), [buku](https://github.com/jarun/buku), [jq](https://github.com/stedolan/jq), [zoxide](https://github.com/ajeetdsouza/zoxide) / [z.lua](https://github.com/skywind3000/z.lua), [xlsx2csv](https://github.com/dilshod/xlsx2csv), [qrencode](https://github.com/fukuchi/libqrencode), sysstat, psmisc, wireless_tools, tree, renameutils
- **Selfhosted service:** [LibreTranslate](https://github.com/uav4geo/LibreTranslate), [searx](https://github.com/searx/searx), [yacy](https://github.com/yacy/yacy_search_server), [synapse](https://github.com/matrix-org/synapse), [mastodon](https://github.com/tootsuite/mastodon), [gitea](https://gitea.io/)
> `Emacs` deserves its own set of dependencies listed, but I'm lazy -> Check my Doom config for details

View File

@ -1,12 +1,12 @@
#!/bin/sh
echo "Shell (bash/zsh/fish): "
echo "Shell (bash/zsh/fish): " | tr -d '\n'
read -r shell
if [ -z "${shell}" ]
then exit
fi
echo "Display server (wayland/x11): "
echo "Display server (wayland/x11): " | tr -d '\n'
read -r server
if [ -z "${server}" ]
then exit

View File

@ -384,8 +384,6 @@ alias mv="mv -vi"
alias rm="rm -vr"
alias mkdir="mkdir -pv"
alias no="grep -viP"
alias wttr="curl wttr.in"
alias myip="curl ipinfo.io/geo"
# alias latest_pkg="expac --timefmt='%Y-%m-%d %T' '%l\t%n' | sort | tail -n 30"
alias yarn="yarn --use-yarnrc $XDG_CONFIG_HOME/yarn/config"
alias tmux="TERM=screen-256color tmux"

View File

@ -21,7 +21,6 @@ abbr no 'grep -viP'
alias yarn='yarn --use-yarnrc $HOME/.config/yarn/config'
abbr tmux 'TERM=screen-256color command tmux'
alias catc='bat --style plain --color=always'
alias myip='curl ipinfo.io/geo'
# colorizing
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'

View File

@ -4,6 +4,5 @@ oakninja/MakeMeFish
jorgebucaran/bax.fish
laughedelic/pisces
wfxr/forgit
oh-my-fish/plugin-wttr
jorgebucaran/gitio.fish
oh-my-fish/plugin-license

View File

@ -155,7 +155,7 @@ zinit light hlissner/zsh-autopair
# Git thingy
zinit light wfxr/forgit
# zinit light kazhala/dotbare
zinit light unixorn/git-extra-commands
# zinit light unixorn/git-extra-commands
# Abbreviations
zinit light olets/zsh-abbr

View File

@ -11,12 +11,10 @@ alias mv="mv -vi"
alias rm="rm -vr"
alias mkdir="mkdir -pv"
alias no="grep -viP"
alias wttr="curl wttr.in"
# alias latest_pkg="expac --timefmt='%Y-%m-%d %T' '%l\t%n' | sort | tail -n 30"
alias yarn="yarn --use-yarnrc $HOME/.config/yarn/config"
alias tmux="TERM=screen-256color tmux"
alias catc="bat --style plain --color=always"
alias myip="curl ipinfo.io/geo"
# colorizing
alias grep="grep --color=auto"
alias fgrep="fgrep --color=auto"

3
home/.local/bin/cheat Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
curl "https://cheat.sh/$1"

10
home/.local/bin/crypt Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
if [ "$1" = "-e" ]; then
openssl enc -aes-256-cbc -salt -a -in "$2" -out "$3" || { echo "File not found"; return 1; }
elif [ "$1" = "-d" ]; then
openssl enc -aes-256-cbc -d -a -in "$2" -out "$3" || { echo "File not found"; return 1; }
else
echo "Wrong 1st argument. Need -d or -e."
return 1
fi

7
home/.local/bin/cryptorate Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
if [ -n "$2" ]; then
curl "$2.rate.sx/$1"
else
curl "rate.sx/$1"
fi

View File

@ -1,13 +0,0 @@
#!/bin/sh
case $1 in
--weather) curl wttr.in/$2;;
--moon) curl wttr.in/Moon;;
--qr) curl qrenco.de/$2;;
--cheat) curl https://cht.sh/$2;;
--crypto) curl rate.sx/$2;;
--url) curl -F 'shorten='$2'' https://0x0.st;;
--news) curl getnews.tech/$2;;
--dict) curl dict://dict.org/d:$2;;
*) ;;
esac

3
home/.local/bin/currency Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
curl -s "https://api.exchangeratesapi.io/latest?base=$1" | jq .

7
home/.local/bin/dict Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
if [ -z "$1" ]; then
aspell dump master | sort | fzf --no-multi | xargs dict
else
curl "dict://dict.org/d:$1"
fi

6
home/.local/bin/imdb Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
apiKey=946f500a
movie=$( (echo "$@" | tr " " + ) | sed 's/-d+//g' )
curl -s "http://www.omdbapi.com/?t=$movie&apikey=$apiKey" | jq .

5
home/.local/bin/ipinfo Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
# $1=geo for verbose look up
curl "https://ipinfo.io/$1"

16
home/.local/bin/lyrics Executable file
View File

@ -0,0 +1,16 @@
#!/bin/sh
echo "Artist: " | tr -d '\n'
read -r artist
echo "Song: " | tr -d '\n'
read -r song
# Nice look
echo "========================
"
artist=$(echo "$artist" | sed s/" "/%20/g | sed s/"&"/%26/g | sed s/,/%2C/g | sed s/-/%2D/g)
song=$(echo "$song" | sed s/" "/%20/g | sed s/"&"/%26/g | sed s/,/%2C/g | sed s/-/%2D/g)
curl -s "https://api.lyrics.ovh/v1/$artist/$song" | jq -r ".lyrics"

3
home/.local/bin/moon Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
curl -s "https://wttr.in/Moon$1"

3
home/.local/bin/news Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
curl "getnews.tech/$1"

46
home/.local/bin/newton Executable file
View File

@ -0,0 +1,46 @@
#!/bin/sh
# validate expression
originalEquation=$(echo "$2" | sed "s/\[/\(/g" | sed "s/\]/\)/g")
parsedExpression=$(echo "$2" | sed "s/\[/\(/g" | sed "s/\]/\)/g" | grep -Eo "[0-9 + -- / * ^ . a-z A-Z ~ : ( ) ]*")
if [ "$parsedExpression" != "$originalEquation" ]; then
echo "Error: Expression contains invalid characters"
return 1
fi
equation=$(echo "$originalEquation" | sed "s:/:(over):g" | sed "s/~/|/g" | sed "s/-/%2D/g")
operation=$(echo "$1" | tr "[[:upper:]]" "[[:lower:]]")
curl -s https://newton.now.sh/api/v2/$operation/"$equation" | grep -Eo '"result":"[a-z A-Z 0-9 ( ) \^ / -- + , ]*' | sed s/'"result":"'//g | tr '"' " "
# Usage: newton [operation] [expression]
# Examples:
# ===================================================
# |Operations Sample Expression Sample Result|
# |---------------------------------------------------|
# |Simplify [[2x^2]+7]*[4x^2] 8 x^4 + 28 x^2 |
# |Factor x^2 + 2x x (x + 2) |
# |Derive x^2+2x 2 x + 2 |
# |Integrate x^2+2x 1/3 x^3 + x^2 +C|
# |Roots/Zeroes x^2+2x 2, 0 |
# |Tangent 2~x^3 12 x + -16 | (Finding tangent line when x=2 for expression x^3)
# |Area 2:4~x^3 60 | (Finding area under curve from 2 to 4 for expression x^3)
# |Cos pi -1 |
# |Sin pi 0 |
# |Tan pi/4 1 |
# |ArcCos 1 0 |
# |ArcSin 0 0 |
# |ArcTan pi arcsin(pi) |
# |Abs -2 2 |
# |Log 2~8 3 | (Log base 2 of eight)
# ===================================================
# Valid Symbols:
# + add
# - subtract
# [ left parenthesis (you must use brackets bash has a bultin for parenthesis)
# ] right parenthesis (you must use brackets bash has a bultin for parenthesis)
# * multiply
# / divide
# ^ power
# : between the range of left and right side (only for area under curve)
# ~ parameter on right side (only for area, tangent line and log)

6
home/.local/bin/qrgen Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
# When you don't want to install `qrencode` yourself
input=$(printf '%s ' "$@")
input=$(echo "$input" | sed s/" "/%20/g)
curl "qrenco.de/$input"

10
home/.local/bin/urlify Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
if [ "$1" = "-e" ]; then
curl https://unshorten.me/s/"$2"
elif [ "$1" = "-s" ]; then
curl https://tinyurl.com/api-create.php?url="$2"
else
echo "Wrong arguments"
return 1
fi

9
home/.local/bin/wttr Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
if [ "$2" = "-v2" ]; then
curl "https://v2.wttr.in/$1"
elif [ "$2" = "-v3" ]; then
curl "https://v3.wttr.in/$1.sxl"
else
curl "https://wttr.in/$1"
fi