flip read to file if its not a pipe

This commit is contained in:
2019-02-02 22:40:38 +02:00
parent 097e81c049
commit 5baf6dcbee

View File

@@ -30,6 +30,7 @@ _help() {
echo my data | $SELF 1 # writes data with name: 1 echo my data | $SELF 1 # writes data with name: 1
$SELF 1 | cat - # prints the contents of file: 1 $SELF 1 | cat - # prints the contents of file: 1
$SELF w file.ext # sends file keeping its name $SELF w file.ext # sends file keeping its name
$SELF r file.ext # download file with same name
Config: Config:
set: FLEES_ROOTURL, FLEES_SHARE, FLEES_TOKEN set: FLEES_ROOTURL, FLEES_SHARE, FLEES_TOKEN
@@ -104,14 +105,23 @@ _write_stdin() { # name
} }
_read() { _read() {
[[ -z "$FILE" ]] && stream_out=1 [[ "$FILE" = "-" ]] && stream_out=1
[ -t 1 ] || stream_out=1 [ -t 1 ] || stream_out=1
[[ "$stream_out" -eq 1 ]] && { [[ "$stream_out" -eq 1 ]] && {
_read_stdout "$NAME" _read_stdout "$NAME"
} || { return
_read_file "$NAME" "$FILE"
} }
# 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 _read_file() { # name, file