CLI Url Shortener
wrote a little URL Shortener in Python with FastAPI and a wrapper script for cli usage. needs httpie & jq packages. python backend is under development, cli wrapper for different os right here …
Usage
somehost$ ./myurlshort
usage: /usr/local/bin/myurlshort http://veeeeeeeeeeeeeeeeeeeeeeeeeery.long.url.to
anyhost$ ./myurlshort http://my-url-to-short.egal.world.planet.universe
https://url.stoege.net/xXxXx
CLI Wrappers
OpenBSD
cat << 'EOF' > myurlshort
#!/usr/bin/env bash
# url shortener for openbsd, v1.0, 2022-09-12, by @stoege
which jq >/dev/null || ( echo -e "*** jq not installed ***\ndoas pkg_add jq\n"; )
which https >/dev/null || ( echo -e "*** httpie not installed ***\ndoas pkg_add httpie\n"; )
if [[ $# -ne 1 ]]; then
echo -e "\nusage: $0 http://veeeeeeeeeeeeeeeeeeeeeeeeeery.long.url.to\n"
exit 1
fi
url="$1"
# check if http/https set
if ! ( [[ $1 == http* ]] || [[ $1 == https* ]] ); then
url="https://$1"
echo "adding https:// ... -> $url"
fi
https post url.stoege.net/url target_url="$url" |jq -r '.url'
exit 0
EOF
chmod 755 myurlshort
macOS
cat << 'EOF' > myurlshort
#!/usr/bin/env bash
# url shortener for macos, v1.0, 2022-09-12, by @stoege
which jq >/dev/null || ( echo -e "*** jq not installed ***\nbrew install jq\n"; )
which https >/dev/null || ( echo -e "*** httpie not installed ***\nbrew install httpie\n"; )
if [[ $# -ne 1 ]]; then
echo -e "\nusage: $0 http://veeeeeeeeeeeeeeeeeeeeeeeeeery.long.url.to\n"
exit 1
fi
url="$1"
# check if http/https set
if ! ( [[ $1 == http* ]] || [[ $1 == https* ]] ); then
url="https://$1"
echo "adding https:// ... -> $url"
fi
https post url.stoege.net/url target_url="$url" |jq -r '.url'
exit 0
EOF
chmod 755 myurlshort
Alpine
cat << 'EOF' > myurlshort
#!/usr/bin/env bash
# url shortener for alpine, v1.0, 2022-09-12, by @stoege
which jq >/dev/null || ( echo -e "*** jq not installed ***\napk add jq\n"; )
which https >/dev/null || ( echo -e "*** httpie not installed ***\napk add httpie\n"; )
if [[ $# -ne 1 ]]; then
echo -e "\nusage: $0 http://veeeeeeeeeeeeeeeeeeeeeeeeeery.long.url.to\n"
exit 1
fi
url="$1"
# check if http/https set
if ! ( [[ $1 == http* ]] || [[ $1 == https* ]] ); then
url="https://$1"
echo "adding https:// ... -> $url"
fi
https post url.stoege.net/url target_url="$url" |jq -r '.url'
exit 0
EOF
chmod 755 myurlshort
Any Comments ?
sha256: 75b0a781fd4569791f3d43932694e155a9443a739f0bf43b0e0904ce299eec3e