You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote a bash function that makes it easy to use the CLI, It is tested on bash and zsh
config
vim ~/.bashrc, Attention, please replace <YOURL_MICROBIN_URL> with your own Microbin URL.
mb() {
mbclean() {
perl -lne 's!/upload/!/p/!; print $1 if /^location: (.*)$/i'
}
upload_file() {
curl -is -X POST https://<YOURL_MICROBIN_URL>/upload -F "file=@$1" | mbclean
}
upload_text() {
curl -is -X POST https://<YOURL_MICROBIN_URL>/upload -F "content=$1" | mbclean
}
# Check if an argument is provided
if [[ -n $1 ]]; then
# Check if the argument is a file
if [[ -f $1 ]]; then
# Prompt user for choice
echo "File detected. Choose an option:"
echo "1. Upload file (default)"
echo "2. Upload text from file"
echo "Enter choice (1 or 2): "
read choice
choice=${choice:-1}
case $choice in
1) upload_file "$1" ;;
2) upload_text "@$1" ;;
*) echo "Invalid choice"; return 1 ;;
esac
# Check if the argument is a directory
elif [[ -d $1 ]]; then
echo "Error: '$1' is a directory. This script can only handle files and text."
return 1
else
# If it's not a file or directory, assume it's a string and upload the string
upload_text "$1"
fi
elif [[ ! -t 0 ]]; then
# If no argument is provided and stdin is not from the terminal, read from stdin
upload_text "@/dev/stdin"
else
# If no input is provided, print usage instructions
echo "Error: No input provided."
echo "Usage:"
echo " mb <text_string>"
echo " mb <file_path>"
echo " mb < file_path"
echo " echo \"hello world\" | mb"
echo " command | mb (e.g., 'python test.py | mb')"
echo " command 2>&1 | mb (e.g., 'python test.py 2>&1 | mb')"
echo " command 2>&1 | tee /dev/tty | mb (e.g., 'python test.py 2>&1 | tee /dev/tty | mb')"
return 1
fi
}
Don't forget source ~/.bashrc
how to use?
mb "hello world"
mb test.py # It will ask you whether to directly upload the file or upload the text inside the file
mb < test.py
echo "hello world" | mb
python test | mb
I wrote a bash function that makes it easy to use the CLI, It is tested on bash and zsh
config
vim ~/.bashrc
, Attention, please replace <YOURL_MICROBIN_URL> with your own Microbin URL.Don't forget
source ~/.bashrc
how to use?
Thanks for the suggestions provided by @vaskozl. #170 (comment)
The text was updated successfully, but these errors were encountered: