Skip to content

Instantly share code, notes, and snippets.

@HarshitJoshi9152
Last active September 12, 2023 15:28
Show Gist options
  • Save HarshitJoshi9152/bb60148db2deeffeb8ae1f820fcf2588 to your computer and use it in GitHub Desktop.
Save HarshitJoshi9152/bb60148db2deeffeb8ae1f820fcf2588 to your computer and use it in GitHub Desktop.
bash function to upload files to 0x0.st (with fzf)
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
}
@HarshitJoshi9152
Copy link
Author

HarshitJoshi9152 commented Sep 12, 2023

To use globally

# COPY CODE TO ~/filename.sh
echo "if [ -f ~/filename.sh ]; then source ~/filename.sh fi" >> ~/.bashrc
source ~/.bashrc

..or move the code outside the function and place the script in any folder in $PATH

Usage

USAGE: paste [File]

@HarshitJoshi9152
Copy link
Author

HarshitJoshi9152 commented Sep 12, 2023

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