dotfiles/.config/shell/bin/sitepath

29 lines
914 B
Text
Raw Normal View History

#!/bin/bash
2022-04-19 19:29:30 -07:00
# Requires: urlencode # if you need this, I am using dead10ck/urlencode (`cargo install urlencode`)
# usage: sitepath <path to file>
# usage: sitepath <file to find>
# usage: sitepath
# usage: sitepath <fd commands> -- you can search with 'fd' if you put in a command
2022-04-19 19:29:30 -07:00
BASE_URL="https://blakenorth.net"
SITE_DIR="/home/blake/docker/blakenorth.net/site"
SEPERATOR='~' # Make this a character you don't use in filenames. It's for sed.
# account for if there is no urlencode command
URLENCODE=urlencode
if ! command -v urlencode > /dev/null 2>&1;then
URLENCODE=cat
fi
# If there is no input, make the input the current directory
2022-04-19 19:29:30 -07:00
[ -z ${1+x} ] && set -- "$(pwd)"
FILEPATH="$( ([ -e "$1" ] && readlink -f "$1") || fd "$@")"
# change all file paths into urls
echo "$FILEPATH" |
grep -o 'site.*' |
2022-04-19 19:29:30 -07:00
sed "s${SEPERATOR[0]}^${SITE_DIR##*/}${SEPERATOR[0]}$BASE_URL${SEPERATOR[0]}g" |
$URLENCODE