dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 1c816b3b20df1e3049fec56656888040b437e7d4
parent 4bc992e8005abff49de9a9c9de73e43706e59227
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed, 12 Jun 2019 21:27:19 +0200

Add notification capabilities to upload script, use from nnn

Diffstat:
M.config/nnn/plugins/upload | 2+-
M.config/nnn/plugins/upload-resize-image | 2+-
M.local/bin/upload | 15+++++++++++----
3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/.config/nnn/plugins/upload b/.config/nnn/plugins/upload @@ -1,4 +1,4 @@ #!/bin/sh if [ -n "$1" ]; then - upload "$1" + upload --notify "$1" fi diff --git a/.config/nnn/plugins/upload-resize-image b/.config/nnn/plugins/upload-resize-image @@ -1,4 +1,4 @@ #!/bin/sh if [ -n "$1" ]; then - upload --border --resize --sharpen "$1" + upload --notify --border --resize --sharpen "$1" fi diff --git a/.local/bin/upload b/.local/bin/upload @@ -16,6 +16,7 @@ function show_help { echo "OPTIONS are one or more of the following:" echo " -h, --help show this message" echo " -v, --version show version and license information" + echo " -n, --notify also show diagnostic output with notify-send" echo " -- do not consider any following arguments as options" echo " -b, --border if an image, add a 10% white border to FILES" echo " -r, --resize if an image, resize FILES to fit 800x800 pixels" @@ -69,12 +70,14 @@ function upload_file { "${user}@${host}:${remotedir}/$newbasename" url="https://$host/files_nonpub/${newbasename}" echo - echo -e "$(tput setaf 2)Uploaded to $url (copied to clipboard)$(tput sgr0)" + msg="Uploaded to $url (copied to clipboard)" + printf "%s\n" "$msg" + [ "$notify" = 1 ] && notify-send "$msg" if [ "$(uname)" = "Darwin" ]; then - echo -n "$url" | pbcopy + printf "%s" "$url" | pbcopy else - echo -n "$url" | xclip + printf "%s" "$url" | xclip fi } @@ -84,6 +87,7 @@ function die { } # parse input arguments (http://mywiki.wooledge.org/BashFAQ/035) +notify=0 border=0 resize=0 sharpen=0 @@ -97,6 +101,9 @@ while :; do show_version exit 0 ;; + -n|--notify) + notify=1 + ;; -b|--border) border=1 ;; @@ -122,7 +129,7 @@ done if [ $# -lt 1 ]; then msg="$(cat)" tempfile="$(mktemp)" - echo -e -n "$msg" > "$tempfile" + printf "%s" "$msg" > "$tempfile" upload_file "$tempfile" "${tempfile##*.}" else # loop over FILE[S]