Last active
September 12, 2023 15:28
-
-
Save 0xkarambit/bb60148db2deeffeb8ae1f820fcf2588 to your computer and use it in GitHub Desktop.
bash function to upload files to 0x0.st (with fzf)
This file contains hidden or 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 paste() | |
{ | |
if [[ $# -gt 1 ]]; then | |
echo "USAGE: paste [File]" | |
return 1 | |
fi | |
file=$1 | |
# if no argument passed... | |
if [[ -z $file ]]; then | |
# Allow user to select file from $HOME using fzf | |
file=$(find $HOME -type f | fzf) | |
# Check if user decided to select nothing... | |
if [[ -z $file ]]; then | |
return 1 | |
fi | |
# check $file exists and can be read | |
elif [[ ! -r "$file" ]]; then | |
echo "[ERROR]: Cannot read file `$file`" | |
return 1 | |
fi; | |
# Upload to 0x0.st | |
curl -F"file=@$file" http://0x0.st | |
} |
Version without fzf
function paste()
{
if [[ $# -ne 1 ]]; then
echo "USAGE: paste [File]"
return 1
fi
$file=$1
# check $file exists and can be read
if [[ ! -r "$file" ]]; then
echo "[ERROR]: Cannot read file `$file`"
return 1
fi;
# Upload to 0x0.st
curl -F"file=@$file" http://0x0.st
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use globally
..or move the code outside the function and place the script in any folder in $PATH
Usage
USAGE: paste [File]