Skip to content

Instantly share code, notes, and snippets.

@chamik
Created March 27, 2023 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chamik/d47be181e71629aa7f7896f2ff8bb7db to your computer and use it in GitHub Desktop.
Save chamik/d47be181e71629aa7f7896f2ff8bb7db to your computer and use it in GitHub Desktop.
Fish script for vault.chamik.eu
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