Created
March 27, 2023 13:53
-
-
Save chamik/d47be181e71629aa7f7896f2ff8bb7db to your computer and use it in GitHub Desktop.
Fish script for vault.chamik.eu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function vault | |
set VAULT_PATH ~/vault | |
set URL "https://vault.chamik.eu" | |
argparse --ignore-unknown 'x/random' 'q/qr-code' 'p/public=' -- $argv | |
if test -z "$_flag_x"; and test -z "$_flag_p" | |
echo (set_color red)You have to set -x or -p (set_color normal) | |
return 1 | |
end | |
if test -n "$_flag_x"; and test -n "$_flag_p" | |
echo (set_color red)Can\'t have both -x or -p stupid (set_color normal) | |
return 1 | |
end | |
if set -q _flag_x | |
set -l HASH "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 20 | head -n 1)" | |
set WEB_PATH "x/$HASH/" | |
set SYSTEM_PATH "$VAULT_PATH/x/$HASH" | |
mkdir "$SYSTEM_PATH" | |
else if set -q _flag_p | |
set WEB_PATH "public/$_flag_p/" | |
set SYSTEM_PATH "$VAULT_PATH/public/$_flag_p" | |
mkdir -p "$SYSTEM_PATH" | |
end | |
for file in $argv | |
cp "$file" "$SYSTEM_PATH" | |
end | |
syncvault | |
echo "Files available at $URL/$WEB_PATH" | |
if set -q _flag_q | |
qrencode -m 2 -t ansiutf8 "$URL/$WEB_PATH" | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment