-
Notifications
You must be signed in to change notification settings - Fork 26
/
teiler_helper
executable file
·90 lines (81 loc) · 3.47 KB
/
teiler_helper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
source $HOME/.config/teiler/config
if [[ "$img_ul" == "s3" || "$img_ul" == "scp" ]]; then
source $HOME/.config/teiler/uploader/$img_ul
fi
if [[ "$vid_ul" == "s3" || "$vid_ul" == "scp" ]]; then
source $HOME/.config/teiler/uploader/$vid_ul
fi
if [[ "$paste_ul" == "s3" || "$paste_ul" == "scp" ]]; then
source $HOME/.config/teiler/uploader/$paste_ul
fi
# define uploaders
# images
if [[ $img_ul == "fb" ]]; then
imageUpload () {
if [[ $(echo "$files" | wc -w) -gt 1 ]]; then
cd "${img_path}"; fb -m ${@}; x_clip; notify-send -a "teiler" "Image Uploaded" "$(xclip -o)"
else
cd "${img_path}"; fb ${@}; x_clip; notify-send -a "teiler" "Image Uploaded" "$(xclip -o)";
fi
}
elif [[ $img_ul == "scp" ]]; then
imageUpload () { for x in $files; do scpUpload "Image" "${img_path}" "$x" "${scp_host}" "${scp_path_img}" "${http_img}"; done; }
elif [[ $img_ul == "imgur" ]]; then
imageUpload () { cd "${img_path}"; for x in $files; do imgurbash2 "${x}"; x_clip; notify-send -a "teiler" "Image Uploaded" "$(xclip -o)"; done; }
elif [[ $img_ul == "s3" ]]; then
imageUpload () { cd "${img_path}"; s3cmd --no-progress put "${1}" "s3://${s3_bucket}/${s3_path_img}/"; notify-send -a "teiler" "Image Uploaded" "${s3_http_img}/${1}"; echo -n "${s3_http_img}/${1}" | xclip; x_clip; }
else
imageUpload () { echo "No image uploader set. check example config"; }
fi
# Videos
if [[ $vid_ul == "fb" ]]; then
videoUpload () { cd "${vid_path}"; fb "${1}"; x_clip; notify-send -a "teiler" "Video Uploaded" "$(xclip -o)"; }
elif [[ $vid_ul == "scp" ]]; then
videoUpload () { scpUpload "Video" "${vid_path}" "$1" "${scp_host}" "${scp_path_vid}" "${http_vid}"; }
elif [[ $vid_ul == "s3" ]]; then
videoUpload () { cd "${vid_path}"; s3cmd --no-progress put "${1}" "s3://${s3_bucket}/${s3_path_vid}/"; notify-send -a "teiler" "Video Uploaded" "${s3_http_vid}/${1}"; echo -n "${s3_http_vid}/${1}" | xclip; x_clip; }
else
videoUpload () { echo "No video uploader set. Check example config"; }
fi
# text
if [[ $paste_ul == "fb" ]]; then
clipUpload () { cd "${paste_path}"; fb "${1}"; x_clip; notify-send -a "teiler" "Paste Uploaded" "$(xclip -o)"; }
elif [[ $paste_ul == "scp" ]]; then
clipUpload () { scpUpload "Paste" "${paste_path}" "$1" "${scp_host}" "${scp_path_paste}" "${http_paste}"; }
elif [[ $paste_ul == "ix" ]]; then
clipUpload () { xclip -o 2>&1 | curl -F 'f:1=<-' ix.io | tr -d "\n" | xclip; x_clip; notify-send -a "teiler" "Paste Uploaded" "$(xclip -o)"; }
else
clipUpload () { echo "No text uploader set. Check example config"; }
fi
scpUpload() {
fileType="$1";
path="$2";
filename="$3";
scp_host="$4";
scp_path="$5";
http="$6";
cd "${path}";
scpResult="$(scp "$filename" "${scp_host}:/${scp_path}/${filename}" 2>&1)";
if [[ "$?" == 0 ]]; then
notify-send -a "teiler" "${fileType} Uploaded" "${http}/${filename}";
echo -n "${http}/${filename}" | xclip;
x_clip;
else
notify-send -a "teiler" "${fileType} upload failed" "$scpResult";
fi;
}
x_clip () {
if [[ $img_ul == "imgur" ]]; then
(xclip -o -selection clipboard) | xclip
else
(xclip -o) | xclip -selection clipboard
fi
}
if [[ $1 == "--upload" ]]; then
files=$(echo "$@" | cut -d ' ' -f3-)
if [[ $2 == "image" ]]; then imageUpload "${files}"
elif [[ $2 == "video" ]]; then videoUpload "${files}"
elif [[ $2 == "text" ]]; then clipUpload "${files}"
fi
fi