Last active
August 4, 2025 14:50
-
-
Save alifeee/c3bf377a2701a62c3f103e908ad83ea8 to your computer and use it in GitHub Desktop.
quickly upload a file to a remote server (Gnome desktop launcher)
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 | |
| # add to /usr/bin/upload-file.sh | |
| # run/add keyboard shortcut to run file | |
| # quickly upload a file to custom location | |
| # uses clipboard, which can be | |
| # screenshot: to copy latest screenshot | |
| # file: to upload last copied file | |
| # clipboard: to upoad clipboard as txt file | |
| # 2. attempt to upload the file | |
| # 3. attempt to put file URL in clipboard | |
| # made by alifeee | |
| # version 0.2.0 | |
| # https://gist.github.com/alifeee/c3bf377a2701a62c3f103e908ad83ea8 | |
| set -eou pipefail | |
| echo "==== File Uploader ====" | |
| echo "you're probably wanting to share a file over IRC..." | |
| ## guess file based on clipboard type ## | |
| clip_targets=$(xclip -selection clipboard -t TARGETS -o) | |
| echo "got targets:" | |
| echo "${clip_targets}" | |
| echo "" | |
| now=$(date '+%s') | |
| filestub="/tmp/ircfileupload_${now}" | |
| if echo "${clip_targets}" | grep "^image/png$" > /dev/null; then | |
| file="${filestub}.png" | |
| echo "uploading image from clipboard" | |
| xclip -selection clipboard -t image/png -o \ | |
| > "${file}" | |
| elif echo "${clip_targets}" | grep "^text/uri-list$" > /dev/null; then | |
| echo "uploading first file in clipboard" | |
| file=$(xclip -selection clipboard -t TEXT -o | head -n1) | |
| else | |
| file="${filestub}.txt" | |
| echo "uploading plaintext clipboard item" | |
| xclip -selection clipboard -t TEXT -o \ | |
| > "${file}" | |
| fi | |
| ## upload file ## | |
| # zenity shows a progress bar on X/Gnome/etc | |
| scp "${file}" server:/var/www/static/ircfiles/ \ | |
| | zenity --progress \ | |
| --title="Upload file" \ | |
| --text="uploading…" \ | |
| --auto-close | |
| ## output ## | |
| baseurl="https://server.alifeee.net/static/ircfiles/" | |
| filename=$(basename "${file}") | |
| remote_file="${baseurl}${filename}" | |
| remote_file=$( | |
| echo "${remote_file}" \ | |
| | sed "s/\x25/%25/g;s/\x20/%20/g;s/\x21/%21/g;s/\x22/%22/g;s/\x23/%23/g;s/\x5c\x24/%24/g;\ | |
| s/\x26/%26/g;s/\x27/%27/g;s/\x28/%28/g;s/\x29/%29/g;s/\x2A/%2A/g;s/\x2B/%2B/g;\ | |
| s/\x2C/%2C/g;s/\x3F/%3F/g;s/\x7C/%7C/g;s/\x5c\x5B/%5B/g" | |
| ) | |
| echo "got file: ${remote_file}" | |
| echo "${remote_file}" | xclip -selection clipboard | |
| notify-send "uploaded ${remote_file} and copied URL! :]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment