├── LICENSE ├── README.md └── pushblast /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Caleb Xu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | pushblast 2 | ========= 3 | 4 | Get PushBullet notifications when a shell program exits. 5 | 6 | ## Usage 7 | 8 | ``` 9 | pushblast "some_command" 10 | ``` 11 | 12 | pushblast will then execute the command given and push a notification via PushBullet to a device of the user's choice once the command finishes. 13 | 14 | ![pushblast demo](https://dl.dropboxusercontent.com/u/17915390/pushblast.gif) 15 | 16 | -------------------------------------------------------------------------------- /pushblast: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | PB_PREFIX=/usr/local/share/pushblast 4 | 5 | if [[ $1 = "" ]] ; then 6 | echo "usage: pushblast \"command_to_be_executed\"" 7 | exit 1 8 | fi 9 | 10 | if [ ! -d $PB_PREFIX/deps ] ; then 11 | mkdir -p $PB_PREFIX/deps 12 | fi 13 | 14 | if [ ! -e $PB_PREFIX/deps/pushbullet ] ; then 15 | echo "Downloading helper file 1 of 1:" 16 | curl -# https://raw.githubusercontent.com/Red5d/pushbullet-bash/master/pushbullet > $PB_PREFIX/deps/pushbullet 17 | fi 18 | 19 | chmod +x $PB_PREFIX/deps/pushbullet 20 | 21 | if [ ! -e $PB_PREFIX/pushblastrc ] ; then 22 | touch $PB_PREFIX/pushblastrc 23 | echo "Welcome to PushBlast! Before I get started, I'll need a few things from you regarding your PushBullet account." 24 | echo -e "\nPlease provide your PushBullet API key, also known as an access token. I need this to be able to push stuff: " 25 | read API_KEY 26 | echo -e "\nPlease provide the device name you wish to push to. Device names are case sensitive, so be careful: " 27 | read DEV_NAME 28 | echo -e "\nPlease name this computer. Computer names are shown on the notification so you know where a notification came from." 29 | read COMP_NAME 30 | echo "API_KEY=\"$API_KEY\"" >> $PB_PREFIX/pushblastrc 31 | echo "DEV_NAME=\"$DEV_NAME\"" >> $PB_PREFIX/pushblastrc 32 | echo "COMP_NAME=\"$COMP_NAME\"" >> $PB_PREFIX/pushblastrc 33 | echo -e "\nLooks like we're all good to go. I'll go ahead and run the command you gave.\n" 34 | fi 35 | 36 | API_KEY_OLD=$API_KEY 37 | DEV_NAME_OLD=$DEV_NAME 38 | COMP_NAME_OLD=$COMP_NAME 39 | 40 | source $PB_PREFIX/pushblastrc 41 | 42 | if [[ $API_KEY = "" && $API_KEY_OLD = "" ]] ; then 43 | echo "Invalid API key. Find your access token at https://www.pushbullet.com/account." 44 | exit 1 45 | fi 46 | 47 | if [[ $API_KEY_OLD != "" ]] ; then 48 | API_KEY=$API_KEY_OLD 49 | fi 50 | 51 | touch ~/.config/pushbullet > /dev/null 2>&1 52 | if [[ $? -gt 0 ]] ; then 53 | echo "Can't create ~/.config/pushbullet" 54 | exit 1 55 | fi 56 | 57 | echo "PB_API_KEY=$API_KEY" > ~/.config/pushbullet 58 | 59 | if [[ $DEV_NAME = "" && $DEV_NAME_OLD = "" ]] ; then 60 | echo "Invalid target device name. Find your list of devices at https://www.pushbullet.com." 61 | exit 1 62 | fi 63 | 64 | if [[ $DEV_NAME_OLD != "" ]] ; then 65 | DEV_NAME=$DEV_NAME_OLD 66 | fi 67 | 68 | if [[ $COMP_NAME = "" && $COMP_NAME_OLD = "" ]] ; then 69 | echo "Invalid computer name. Enter a name for this computer (it does not have to be unique or in use with Pushbullet)." 70 | exit 1 71 | fi 72 | 73 | if [[ $COMP_NAME_OLD != "" ]] ; then 74 | COMP_NAME=$COMP_NAME_OLD 75 | fi 76 | 77 | ($PB_PREFIX/deps/pushbullet list | grep $DEV_NAME) >/dev/null 2>&1 78 | 79 | if [ $? != 0 ] ; then 80 | echo "The device $DEV_NAME does not exist or is unusable." 81 | $PB_PREFIX/deps/pushbullet list 82 | exit 1 83 | fi 84 | 85 | EXECUTE=$1 86 | $1 87 | EXIT=$? 88 | 89 | $PB_PREFIX/deps/pushbullet push $DEV_NAME note "The task \"$EXECUTE\" on \"$COMP_NAME\" finished with exit code $EXIT." >/dev/null 2>&1 90 | rm ~/.config/pushbullet 91 | exit $EXIT 92 | --------------------------------------------------------------------------------