Created
June 18, 2021 21:02
-
-
Save matheusfillipe/0bc688b2a502d1c6ba8f2e8fe3592f34 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 | |
| # Wrapper for gist, pc, imgur.sh using rofi (-g) or fzf | |
| # if fromGUI rofi else fzf | |
| function rofilaunch { | |
| rofi -dmenu -p "$1" -i | |
| } | |
| function fzflauch { | |
| fzf | |
| } | |
| function dieempty { | |
| [[ -z $1 ]] && exit 0 | |
| } | |
| function getfile { | |
| if [[ -e "$1" && -f "$1" ]] | |
| then | |
| printf "%s" "$1" | |
| elif [[ -e "$2" && -f "$2" ]] | |
| then | |
| printf "%s" "$2" | |
| fi | |
| printf "None" | |
| } | |
| if [[ "$1" == "-g" ]] | |
| then | |
| cmd=rofilaunch | |
| else | |
| cmd=fzflauch | |
| fi | |
| type=$(printf "paste\ngist\nimgur" | $cmd Type) | |
| dieempty "$type" | |
| filename=$(getfile "$@") | |
| echo "File $filename" | |
| case $type in | |
| paste) | |
| backend=$(pc list-backends | $cmd "Paste Backend") | |
| if [[ "$filename" == "None" ]] | |
| then | |
| xclip -o | pc "$backend" | xclip -selection c | |
| else | |
| pc "$backend" < "$filename" | xclip -selection c | |
| fi | |
| ;; | |
| gist) | |
| if [[ "$filename" == "None" ]] | |
| then | |
| gist -P -c -o | xclip -selection c | |
| else | |
| gist -c -o "$filename" | xclip -selection c | |
| fi | |
| ;; | |
| imgur) | |
| # Paste uri file path, take screenshot or from clipboard | |
| if [[ "$filename" == "None" ]] | |
| then | |
| imgur=$(printf "Screenshot\nClipboard" | $cmd "imgur") | |
| else | |
| imgur=$filename | |
| fi | |
| case $imgur in | |
| Screenshot) | |
| import png:- | imgur.sh | |
| ;; | |
| Clipboard) | |
| xclip -t image/jpeg -o | imgur.sh | |
| ;; | |
| *) | |
| imgur.sh "$imgur" | |
| ;; | |
| esac | |
| ;; | |
| *) | |
| exit 0 | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment