pb script for easy paste to 0x0.st
This commit is contained in:
parent
b9e33ca269
commit
ad1713254e
98
_scripts/pb
Executable file
98
_scripts/pb
Executable file
@ -0,0 +1,98 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# $HOME/.local/bin/pb
|
||||||
|
# upload files to 0x0.st
|
||||||
|
# 0x0 - client for 0x0.st
|
||||||
|
# Usage: `0x0.sh file`
|
||||||
|
|
||||||
|
me=${0##*/}
|
||||||
|
host=https://0x0.st
|
||||||
|
|
||||||
|
if [[ ! -t 1 ]];then
|
||||||
|
quiet=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
help() {
|
||||||
|
cat >&2 <<EOF
|
||||||
|
Usage: ${me} [-f <file>] [-s <url>] [-u <url>] [file]
|
||||||
|
Client for interacting with 0x0.st.
|
||||||
|
If no file is given, upload stdin.
|
||||||
|
-f <file> - upload <file>
|
||||||
|
-s <url> - shorten <url>
|
||||||
|
-u <url> - upload content of <url>
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
clip() {
|
||||||
|
if command -v xclip >/dev/null 2>&1;then
|
||||||
|
echo "$@" | xclip -selection c
|
||||||
|
notify-send "0x0" "Successfully uploaded.\nURL: $@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
file_upload() {
|
||||||
|
local curl_opts="-s" file="$1" type
|
||||||
|
[[ "${progress_quiet}" ]] || curl_opts="-#"
|
||||||
|
[[ "${quiet}" ]] || printf "uploading \"%s\"...\n" "${file}" >&2
|
||||||
|
[[ "$#" -gt 1 ]] && printf "%s ... " "${url}"
|
||||||
|
url=$(curl ${curl_opts} -F "file=@${file}" "${host}")
|
||||||
|
printf '%s' "${url}"
|
||||||
|
[ -t 1 ] && printf '\n'
|
||||||
|
clip "${url}"
|
||||||
|
}
|
||||||
|
|
||||||
|
shorten_url() {
|
||||||
|
local curl_opts="-s" url="$1" shortened
|
||||||
|
[[ "${progress_quiet}" ]] || curl_opts="-#"
|
||||||
|
[[ "${quiet}" ]] || printf "shortening \"${url}\"...\n" >&2
|
||||||
|
[[ "$#" -gt 1 ]] && printf "%s ... " "${url}"
|
||||||
|
shortened=$(curl ${curl_opts} -F "shorten=${url}" "${host}")
|
||||||
|
printf '%s' "${shortened}"
|
||||||
|
[ -t 1 ] && printf '\n'
|
||||||
|
clip "${shortened}"
|
||||||
|
}
|
||||||
|
|
||||||
|
upload_url() {
|
||||||
|
local curl_opts="-s" url="$1" uploaded
|
||||||
|
[[ "${progress_quiet}" ]] || curl_opts="-#"
|
||||||
|
[[ "${quiet}" ]] || printf "uploading \"%s\"...\n" "${url}" >&2
|
||||||
|
[[ "$#" -gt 1 ]] && printf "%s ... " "${url}"
|
||||||
|
uploaded=$(curl ${curl_opts} -F "url=${url}" "${host}")
|
||||||
|
printf '%s' "${uploaded}"
|
||||||
|
[ -t 1 ] && printf '\n'
|
||||||
|
clip "${uploaded}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 1KiB = 1024 bytes
|
||||||
|
# 1MiB = 1024 KiB
|
||||||
|
# max size - 256MiB
|
||||||
|
|
||||||
|
max_size=$(( (1024*1024) * 256 ))
|
||||||
|
|
||||||
|
if [[ -f "$1" || "$#" -lt 1 ]];then
|
||||||
|
mode="default"
|
||||||
|
else
|
||||||
|
mode="$1"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$mode" in
|
||||||
|
default)
|
||||||
|
if [[ "$#" -gt 0 ]];then
|
||||||
|
file_upload "${@}"
|
||||||
|
else
|
||||||
|
cat | quiet=true file_upload "/dev/stdin"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
-f)
|
||||||
|
file_upload "${@}"
|
||||||
|
;;
|
||||||
|
-u)
|
||||||
|
upload_url "${@}"
|
||||||
|
;;
|
||||||
|
-s)
|
||||||
|
shorten_url "${@}"
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
help
|
||||||
|
;;
|
||||||
|
esac
|
@ -8,7 +8,7 @@ git clone --recurse https://git.insomniac.pl/ftpd/dotfiles ~/.local/repos/dotfil
|
|||||||
# clean + prepare local dirs
|
# clean + prepare local dirs
|
||||||
rm -rf ~/.cache ~/.config/_cache ~/.config/vim ~/.config/zsh
|
rm -rf ~/.cache ~/.config/_cache ~/.config/vim ~/.config/zsh
|
||||||
rm -rf ~/.fdignore ~/.fzf.bash ~/.fzf.zsh ~/.gitconfig ~/.gitignore ~/.history ~/.tmux.conf ~/.vim* ~/.zcomp* ~/.zsh*
|
rm -rf ~/.fdignore ~/.fzf.bash ~/.fzf.zsh ~/.gitconfig ~/.gitignore ~/.history ~/.tmux.conf ~/.vim* ~/.zcomp* ~/.zsh*
|
||||||
mkdir -p ~/.cache/ ~/.config ~/.local/settings
|
mkdir -p ~/.cache/ ~/.config ~/.local/bin ~/.local/settings
|
||||||
|
|
||||||
## neovim
|
## neovim
|
||||||
rm -rf ~/.config/nvim
|
rm -rf ~/.config/nvim
|
||||||
@ -28,6 +28,11 @@ ln -sf ~/.local/repos/dotfiles/tmux ~/.config/
|
|||||||
rm -rf ~/.config/htop
|
rm -rf ~/.config/htop
|
||||||
ln -sf ~/.local/repos/dotfiles/htop ~/.config/
|
ln -sf ~/.local/repos/dotfiles/htop ~/.config/
|
||||||
|
|
||||||
|
## scripts
|
||||||
|
for i in ~/.local/repos/dotfiles/_scripts/*; do
|
||||||
|
ln -sf $i ~/.local/bin/
|
||||||
|
done
|
||||||
|
|
||||||
## zsh
|
## zsh
|
||||||
echo "skip_global_compinit=1" > $HOME/.zshenv
|
echo "skip_global_compinit=1" > $HOME/.zshenv
|
||||||
echo "export XDG_DATA_HOME=$HOME/.local/share" >> $HOME/.zshenv
|
echo "export XDG_DATA_HOME=$HOME/.local/share" >> $HOME/.zshenv
|
||||||
|
Loading…
Reference in New Issue
Block a user