diff --git a/README.md b/README.md index b4e76c0..eba4ecb 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ $ make install bindir=/path/to/bin $ transfer --help Usage: transfer download [ [file]] - [--decrypt|-d] [--file|-f ] [--password|-p ] [--trace|-x] + [--decrypt|-d] [--save|--cat] [--file|-f ] [--password|-p ] [--trace|-x] [--url|-u ] transfer upload [ [slug]] @@ -108,6 +108,10 @@ More Information: repo https://github.com/rockymadden/transfer-cli ``` +### Configurable options +Change these variables at the top of the script to change the default behaviour. + * `use_stdout`: set to `no` to save downloaded files by default instead of writing them to standard output (may be less pipe-friendly). This option can be overridden through the `--cat` or `--save` CLI arguments. + ## License ``` The MIT License (MIT) diff --git a/src/transfer b/src/transfer index 69d73a1..35d1ae4 100755 --- a/src/transfer +++ b/src/transfer @@ -1,5 +1,8 @@ #!/usr/bin/env bash +# CONFIGURABLE OPTIONS ################################################################################# +use_stdout="yes" + # COMMAND PARSING ################################################################################# cmd="${1}" ; shift @@ -11,12 +14,14 @@ esac # ARGUMENT AND OPTION PARSING ##################################################################### while (( "$#" )); do case "${1}" in + --cat) use_stdout="yes" ; shift ;; --decrypt|-d) decrypt=0 ; shift ;; --encrypt|-e) encrypt=0 ; shift ;; --file=*) file=${1/--file=/''} ; shift ;; --file*|-f*) file=${2} ; shift ; shift ;; --password=*) password=${1/--password=/''} ; shift ;; --password*|-p*) password=${2} ; shift ; shift ;; + --save) use_stdout="no" ; shift ;; --slug=*) slug=${1/--slug=/''} ; shift ;; --slug*|-s*) slug=${2} ; shift ; shift ;; --trace|-x) trace='set -x' ; shift ;; @@ -53,6 +58,8 @@ esac # COMMAND FUNCTIONS ############################################################################### function download() { + [ -z "${file}" -a "${use_stdout}" == "no" ] && file=${url##*/} + if [ -n "${file}" ]; then local path=$(greadlink -f "${file}" 2> /dev/null || readlink -f "${file}" 2> /dev/null) @@ -77,7 +84,7 @@ function help() { echo ' [--url|-u ]' echo echo " ${bin} upload [ [slug]]" - echo ' [--encrypt|-e] [--file|-f ] [--password|-p ] [--slug|-s ]' + echo ' [--encrypt|-e] [--max-days|-y ] [--max-downloads|-l ] [--file|-f ] [--password|-p ] [--slug|-s ]' echo ' [--trace|-x]' echo echo 'Commands:' @@ -122,7 +129,7 @@ function upload() { curl --progress-bar --upload-file - "https://transfer.sh/${slug}" > ${tmpurl} fi - cat ${tmpurl} + cat ${tmpurl} && [ "${use_stdout}" == "no" ] && echo if type pbcopy &> /dev/null; then cat ${tmpurl} | tr -d '\n' | pbcopy; fi }