diff --git a/code/templates/flip b/code/templates/flip index f91001c..dd21ffb 100755 --- a/code/templates/flip +++ b/code/templates/flip @@ -30,6 +30,7 @@ _help() { echo my data | $SELF 1 # writes data with name: 1 $SELF 1 | cat - # prints the contents of file: 1 $SELF w file.ext # sends file keeping its name + $SELF r file.ext # download file with same name Config: set: FLEES_ROOTURL, FLEES_SHARE, FLEES_TOKEN @@ -104,14 +105,23 @@ _write_stdin() { # name } _read() { - [[ -z "$FILE" ]] && stream_out=1 + [[ "$FILE" = "-" ]] && stream_out=1 [ -t 1 ] || stream_out=1 - [[ "$stream_out" -eq 1 ]] && { _read_stdout "$NAME" - } || { - _read_file "$NAME" "$FILE" + return } + # no file mentioned, use the name as file + [[ -z "$FILE" ]] && { + [[ -n "$NAME" ]] && { + FILE=$( basename "$NAME" ) + } + [[ -e "$FILE" ]] && { + echo "'$FILE' already exists, not overwriting" + exit 1 + } + } + _read_file "$NAME" "$FILE" } _read_file() { # name, file