Created
April 1, 2013 15:31
-
-
Save khurshid-alam/5285588 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Send your files to another machine using SCP | |
# REQUIRED | |
# - Nautilus (doh!) | |
# - scp | |
# - notify-send (from package notify-bin, libnotify - for messages) | |
# - xclip (to automaticaly set your clipboard to the URL of the file) | |
# To use (for single server): | |
# 1. Copy to ${HOME}/.gnome2/nautilus-scripts | |
# 2. Rename to "Send to MYSERVER" and make executable (chmod a+x) | |
# 3. Change the options below | |
# | |
# To use (for multiple servers): | |
# 1. Copy to your ${HOME}/.gnome2/nautilus-scripts directory | |
# 2. Make a file named "Send to MYSERVER" in the same directory | |
# 3. Put this into it: | |
# --------------- | |
# #!/bin/bash | |
# | |
# SCP_URL="[email protected]:public_html/rot/`hostname`/" | |
# HTTP_URL="http://odin.s0.no/rot/`hostname`/" | |
# PROGNAME=`basename "$0"` | |
# dir=`dirname "$0"` | |
# | |
# export SCP_URL HTTP_URL PROGNAME | |
# source $dir/send_via_scp | |
# --------------- | |
# | |
# 4. Make it executable (you don't have to make send_via_scp executable) | |
# Author: Odin Hørthe Omdal < odin.omdal at gmail [dot] com > | |
# Version: 1.1 | |
# Based upon the script to make symbolic links by | |
# Author: Jon Green < g-scripts [at] green-lines [dot] com > | |
# Version: 1.0 | |
if [ "x$SCP_URL" == "x" ]; then | |
# OPTIONS, edit these | |
SCP_URL="user@domain:public_html/folder/" | |
HTTP_URL="http://domain/folder/" | |
# This is the name it will use for notifications | |
PROGNAME=`basename "$0"` | |
fi | |
#### You don't have to edit below here ### | |
warning() { | |
notify-send -i gtk-dialog-error "$PROGNAME" "$*" | |
} | |
message() { | |
notify-send -i gtk-dialog-info "$PROGNAME" "$*" | |
} | |
declare -a NAUTFILES | |
export IX=0 | |
while read FILE; do | |
if [ "x${FILE}" != "x" -a "x${FILE}" != 'x"' ]; then | |
NAUTFILES[${IX}]="${FILE}" | |
IX=$[ ${IX} + 1 ] | |
fi | |
done <<EOF | |
${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS[@]} | |
EOF | |
if [ 0 -eq ${IX} ]; then | |
URI="${NAUTILUS_SCRIPT_CURRENT_URI}" | |
METHOD="${URI:0:7}" | |
if [ "file://" == "${METHOD}" ]; then | |
NAUTFILES[0]="${URI:7}" | |
IX=1 | |
fi | |
fi | |
if [ 0 == "${#NAUTFILES[@]}" ]; then | |
warning "Nothing to do" | |
exit | |
fi | |
for FILE in "${NAUTFILES[@]}"; do | |
FILE_NAME=`basename "${FILE}"`; | |
if ! scp "${FILE}" "$SCP_URL"; then | |
warning "Couldn't send ${FILE_NAME}" | |
else | |
message "Uploaded to <a href='${HTTP_URL}${FILE_NAME}'>${HTTP_URL}${FILE_NAME}</a>" | |
fi | |
# Save the URL to the clip board | |
echo "${HTTP_URL}${FILE_NAME}" | xclip | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment