├── install.sh ├── LICENSE ├── src └── pb.sh └── README.md /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | 5 | fetch_source () { 6 | curl -Lo- https://github.com/ptpb/pb_cli/archive/master.tar.gz \ 7 | | tar xz -C "$tmpdir" --strip-components=1 8 | } 9 | 10 | 11 | order66 () { 12 | local tmpdir="$(mktemp -d)" 13 | 14 | cd "$tmpdir" 15 | 16 | fetch_source "$tmpdir" 17 | 18 | install -Dm755 src/pb.sh /usr/local/bin/pb 19 | } 20 | 21 | 22 | order66 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2019 by the respective authors; see AUTHORS. 2 | All rights reserved. 3 | 4 | pb is free software: you can redistribute it and/or modify it under 5 | the terms of the GNU General Public License as published by the Free 6 | Software Foundation, either version 3 of the License, or (at your 7 | option) any later version. 8 | 9 | pb is distributed in the hope that it will be useful, but WITHOUT ANY 10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | See the GNU General Public License for 14 | more details. 15 | -------------------------------------------------------------------------------- /src/pb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | endpoint="${PB_ENDPOINT:-https://0x0.st}" 4 | jq_args="${PB_JSON:--r .url}" 5 | private="${PB_PRIVATE:-0}" 6 | clipboard="${PB_CLIPBOARD}" 7 | clipboard_tool="${PB_CLIPBOARD_TOOL:-xclip}" 8 | 9 | pb_ () { 10 | local filename extension 11 | 12 | filename="${1:--}" 13 | extension="${2:-}" 14 | 15 | shift 2 16 | 17 | data=$(curl -sF "file=@$filename" "$@" "$endpoint") 18 | if [[ ! -z $clipboard ]]; then 19 | printf "${data}" | "${clipboard_tool}" 20 | fi 21 | echo "${data}" 22 | } 23 | 24 | pb_png () { 25 | maim -s | pb_ - .png 26 | } 27 | 28 | pb_gif () { 29 | capture gif - | pb_ - .gif 30 | } 31 | 32 | pb_webm () { 33 | capture webm - | pb_ - .webm 34 | } 35 | 36 | pb () { 37 | local command="$1" 38 | 39 | case $command in 40 | png) 41 | shift 42 | pb_png "$@" 43 | ;; 44 | gif) 45 | shift 46 | pb_gif "$@" 47 | ;; 48 | webm) 49 | shift 50 | pb_webm "$@" 51 | ;; 52 | private) 53 | shift 54 | private=1 55 | pb_ "$@" 56 | ;; 57 | *) 58 | pb_ "$@" 59 | ;; 60 | esac 61 | } 62 | 63 | pb "$@" 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pb_cli 2 | 3 | `pb_cli` is a no bullshit [pb](https://github.com/ptpb/pb) client. 4 | 5 | ## installation 6 | 7 | An install script is provided for convenience. 8 | 9 | ```sh 10 | $ curl -Lo- "https://raw.githubusercontent.com/ptpb/pb_cli/master/install.sh" | sudo bash 11 | ``` 12 | 13 | This is just a handful of trivial commands to install `pb` in 14 | `/usr/local/bin`. Feel free to copy-paste instead if you wish. 15 | 16 | ## dependencies 17 | 18 | Dependencies are not considered during installation; you need to make these 19 | exist on your own. 20 | 21 | - `curl` 22 | - `bash>4.0` 23 | - `jq` 24 | - [`capture`](https://github.com/buhman/capture) (optional, for screen capture) 25 | - `maim` (optional, for screenshots) 26 | - `xclip` (optional, for clipboard manipulation) 27 | 28 | ## usage 29 | 30 | Maximum simple: 31 | 32 | ```sh 33 | $ pb <<< 'hello world' 34 | https://ptpb.pw/DtUR 35 | ``` 36 | 37 | The url is provided on stdout to make `pb` easy to use in pipelines/scripting. 38 | 39 | ### files 40 | 41 | If you don't have the PhD in bash like `#bash` presumes, this might not be 42 | obvious to you: 43 | 44 | ```sh 45 | pb < /path/to/my/file 46 | ``` 47 | 48 | ### private 49 | 50 | Create a "private" paste (disables short url). 51 | 52 | ```sh 53 | pb private 54 | ``` 55 | 56 | ### screenshot 57 | 58 | This uses `maim` to create a screenshot. You can either click-drag a bounding 59 | box for a region, or click a window for the entire window. 60 | 61 | ```sh 62 | pb png 63 | ``` 64 | 65 | ### screen capture 66 | 67 | This uses [`capture`](https://github.com/buhman/capture) to create a screen 68 | capture, convert to webm or gif, and upload to pb. Usage is very similar to `pb 69 | png`--both use slop for window/region selection. 70 | 71 | ```sh 72 | pb webm 73 | ``` 74 | 75 | ```sh 76 | pb gif 77 | ``` 78 | 79 | When you are done, press `q` once to stop recording. 80 | 81 | ### clipboard 82 | 83 | When set, by default, `PB_CLIPBOARD` will put the paste url in the X11 `primary` buffer. You can modify this behavior by setting `PB_CLIPBOARD_TOOL`, possibly with additional arguments. 84 | 85 | ```sh 86 | PB_CLIPBOARD=1 pb … 87 | ``` 88 | 89 | For usability, you'll likely want to export this variable in your shell rc file if this is a feature you want to use regularly. 90 | 91 | ## advanced usage 92 | 93 | If you have more complex scripting needs (like capturing the uuid for 94 | updates/deletes), you can use the `PB_JSON` environment variables to get the raw 95 | json: 96 | 97 | ```sh 98 | $ PB_JSON='.' pb <<< test 99 | { 100 | "status": "already exists", 101 | "url": "https://ptpb.pw/f5-D", 102 | "short": "f5-D", 103 | "size": 5, 104 | "long": "AE4SQ70ixm52wrqe3cH5E5Tlf5-D", 105 | "date": "2015-02-28T14:45:23.444000+00:00", 106 | "digest": "4e1243bd22c66e76c2ba9eddc1f91394e57f9f83" 107 | } 108 | ``` 109 | 110 | So, for example: 111 | 112 | ```sh 113 | $ eval "$(PB_JSON='.' pb <<< test | jq -r '@sh "url=\(.url) short=\(.short)"')" 114 | $ echo $short 115 | f5-D 116 | $ echo $url 117 | https://ptpb.pw/f5-D 118 | ``` 119 | --------------------------------------------------------------------------------