mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-20 15:06:15 -04:00
pairdrop-cli now working on windows via bash pairdrop
or git bash
This commit is contained in:
parent
8f0e465b8e
commit
3cb4e6d476
1 changed files with 29 additions and 11 deletions
|
@ -7,13 +7,15 @@ set -e
|
||||||
help()
|
help()
|
||||||
{
|
{
|
||||||
# Display Help
|
# Display Help
|
||||||
echo "Send files or text with PairDrop via commandline."
|
echo "Send files or text with PairDrop via command-line interface."
|
||||||
echo "Current domain: ${DOMAIN}"
|
echo "Current domain: ${DOMAIN}"
|
||||||
echo
|
echo
|
||||||
echo "Usage:"
|
echo "Usage:"
|
||||||
|
echo -e "Open PairDrop:\t\t$(basename "$0")"
|
||||||
echo -e "Send files:\t\t$(basename "$0") file/directory"
|
echo -e "Send files:\t\t$(basename "$0") file/directory"
|
||||||
echo -e "Send text:\t\t$(basename "$0") -t \"text\""
|
echo -e "Send text:\t\t$(basename "$0") -t \"text\""
|
||||||
echo -e "Specify domain:\t$(basename "$0") -d \"https://pairdrop.net/\""
|
echo -e "Specify domain:\t\t$(basename "$0") -d \"https://pairdrop.net/\""
|
||||||
|
echo -e "Show this help text:\t$(basename "$0") (-h|--help)"
|
||||||
}
|
}
|
||||||
|
|
||||||
openPairDrop()
|
openPairDrop()
|
||||||
|
@ -57,8 +59,8 @@ setOs()
|
||||||
specifyDomain()
|
specifyDomain()
|
||||||
{
|
{
|
||||||
[[ ! $1 = http* ]] || [[ ! $1 = */ ]] && echo "Incorrect format. Specify domain like https://pairdrop.net/" && exit
|
[[ ! $1 = http* ]] || [[ ! $1 = */ ]] && echo "Incorrect format. Specify domain like https://pairdrop.net/" && exit
|
||||||
echo "DOMAIN=${1}" > "${SCRIPTPATH}/.pairdrop-cli-config"
|
echo "DOMAIN=${1}" > "$CONFIGPATH"
|
||||||
echo -e "Domain is now set to:\n$1"
|
echo -e "Domain is now set to:\n$1\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
sendText()
|
sendText()
|
||||||
|
@ -143,12 +145,27 @@ sendFiles()
|
||||||
############################################################
|
############################################################
|
||||||
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||||
|
|
||||||
[ ! -f "${SCRIPTPATH}/.pairdrop-cli-config" ] &&
|
pushd . > '/dev/null';
|
||||||
specifyDomain "https://pairdrop.net/" &&
|
SCRIPTPATH="${BASH_SOURCE[0]:-$0}";
|
||||||
[ ! -f "${SCRIPTPATH}/.pairdrop-cli-config" ] &&
|
|
||||||
echo "Could not create config file. Add 'DOMAIN=https://pairdrop.net/' to a file called .pairdrop-cli-config in the same file as this pairdrop bash file"
|
|
||||||
|
|
||||||
[ ! -f "${SCRIPTPATH}/.pairdrop-cli-config" ] || export "$(grep -v '^#' "${SCRIPTPATH}/.pairdrop-cli-config" | xargs)"
|
while [ -h "$SCRIPTPATH" ];
|
||||||
|
do
|
||||||
|
cd "$( dirname -- "$SCRIPTPATH"; )";
|
||||||
|
SCRIPTPATH="$( readlink -f -- "$SCRIPTPATH"; )";
|
||||||
|
done
|
||||||
|
|
||||||
|
cd "$( dirname -- "$SCRIPTPATH"; )" > '/dev/null';
|
||||||
|
SCRIPTPATH="$( pwd; )";
|
||||||
|
popd > '/dev/null';
|
||||||
|
|
||||||
|
CONFIGPATH="${SCRIPTPATH}/.pairdrop-cli-config"
|
||||||
|
|
||||||
|
[ ! -f "$CONFIGPATH" ] &&
|
||||||
|
specifyDomain "https://pairdrop.net/" &&
|
||||||
|
[ ! -f "$CONFIGPATH" ] &&
|
||||||
|
echo "Could not create config file. Add 'DOMAIN=https://pairdrop.net/' to a file called .pairdrop-cli-config in the same file as this 'pairdrop' bash file"
|
||||||
|
|
||||||
|
[ ! -f "$CONFIGPATH" ] || export "$(grep -v '^#' "$CONFIGPATH" | xargs)"
|
||||||
|
|
||||||
setOs
|
setOs
|
||||||
############################################################
|
############################################################
|
||||||
|
@ -157,8 +174,9 @@ setOs
|
||||||
# Get the options
|
# Get the options
|
||||||
# open PairDrop if no options are given
|
# open PairDrop if no options are given
|
||||||
[[ $# -eq 0 ]] && openPairDrop && exit
|
[[ $# -eq 0 ]] && openPairDrop && exit
|
||||||
|
|
||||||
# display help and exit if first argument is "--help" or more than 2 arguments are given
|
# display help and exit if first argument is "--help" or more than 2 arguments are given
|
||||||
[ "$1" = "--help" ] | [[ $# -gt 2 ]] && help && exit
|
[ "$1" == "--help" ] || [[ $# -gt 2 ]] && help && exit
|
||||||
|
|
||||||
while getopts "d:ht:*" option; do
|
while getopts "d:ht:*" option; do
|
||||||
case $option in
|
case $option in
|
||||||
|
@ -177,5 +195,5 @@ done
|
||||||
# Send file(s)
|
# Send file(s)
|
||||||
# display help and exit if 2 arguments are given or if file does not exist
|
# display help and exit if 2 arguments are given or if file does not exist
|
||||||
[[ $# -eq 2 ]] || [[ ! -a $1 ]] && help && exit
|
[[ $# -eq 2 ]] || [[ ! -a $1 ]] && help && exit
|
||||||
|
|
||||||
sendFiles "$1"
|
sendFiles "$1"
|
||||||
exit
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue