Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ $ make install bindir=/path/to/bin
$ transfer --help
Usage:
transfer download [<url> [file]]
[--decrypt|-d] [--file|-f <file>] [--password|-p <password>] [--trace|-x]
[--decrypt|-d] [--save|--cat] [--file|-f <file>] [--password|-p <password>] [--trace|-x]
[--url|-u <url>]

transfer upload [<file> [slug]]
Expand All @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions src/transfer
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

# CONFIGURABLE OPTIONS #################################################################################
use_stdout="yes"

# COMMAND PARSING #################################################################################
cmd="${1}" ; shift

Expand All @@ -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 ;;
Expand Down Expand Up @@ -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)

Expand All @@ -77,7 +84,7 @@ function help() {
echo ' [--url|-u <url>]'
echo
echo " ${bin} upload [<file> [slug]]"
echo ' [--encrypt|-e] [--file|-f <file>] [--password|-p <password>] [--slug|-s <slug>]'
echo ' [--encrypt|-e] [--max-days|-y <days>] [--max-downloads|-l <dls>] [--file|-f <file>] [--password|-p <password>] [--slug|-s <slug>]'
echo ' [--trace|-x]'
echo
echo 'Commands:'
Expand Down Expand Up @@ -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
}

Expand Down