-
Notifications
You must be signed in to change notification settings - Fork 1
/
emojis.sh
executable file
·114 lines (95 loc) · 3.02 KB
/
emojis.sh
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
# SCRIPT VARIABLES
full_path=$(echo "${BASH_SOURCE:-$0}" | xargs realpath)
script_name=$(basename "$0")
path="${full_path%"/$script_name"}"
emojis_path="$path/emojis"
[ -d "$emojis_path" ] || mkdir "$emojis_path"
# emotify_path="$path/emotify.sh"
icon_path="/usr/share/icons/iconify"
create="Create new emoji"
create_icon="\0icon\x1fadd"
create_bg_remove="Create emoji and remove its bg"
delete_emoji="Delete emoji"
# SCRIPT FUNCTIONS
get_emoji(){
if [ -f "$emojis_path/$1.png" ];
then
# If emoji already exists
xclip -selection clipboard -t image/png -i "$emojis_path/$1.png"
fi
}
delete_emoji(){
rm -f "$emojis_path/$1.png"
rm -f "$icon_path/$1.png"
}
create_emoji(){
# Create new emoji
# if not from filename : dl from url
# If no emoji name
if [ "$2" == "" ];
then
exit
fi
from="/tmp/emotify"
to="$emojis_path/$2.png"
if [ ! -f "$1" ];
then
wget "$1" -O "$from"
else
from="$1"
fi
# Create new emoji & remove background
if [ -n "$3" ];
then
echo "Removing background : $3"
convert "$from" -define format:png -fuzz 20%% -transparent "$3" -resize 60x60 "$to"
else
convert "$from" -resize 60x60 -define format:png "$to"
fi
cp "$to" "$icon_path/"
xclip -selection clipboard -t image/png -i "$to"
# convert u3.png -resize 100x100 u.png
}
# SCRIPT START
icons_emojis=""
# find . -printf "%T@ %f\n" | sort -nr | cut -d " " -f 2-
# for e in $(find "$emojis_path" -type f -name "*.png" -printf '%f\n' | sed "s/\.png//g"); do
for e in $(find "$emojis_path" -type f -name "*.png" -printf '%T@ %f\n' | sort -nr | cut -d " " -f 2- | sed "s/\.png//g"); do
icons_emojis="$icons_emojis$e\0icon\x1f$e\n"
done
chosen="$(echo -e "$create$create_icon\n$create_bg_remove\n$delete_emoji$create_icon\n$icons_emojis" | rofi -p -dmenu -show-icons -icon-theme "iconify")"
# -selected-row 2
# Escaped
if [ "$chosen" = "" ];
then
exit
fi
case "$chosen" in
"")
exit
;;
"$create")
emoji_name=$(rofi -dmenu -i -no-fixed-num-lines -p "Emoji name ?" \
-theme "$path/confirm.rasi")
create_emoji "$(xclip -selection clipboard -o -r)" "$emoji_name"
# $emotify_path "$(xclip -selection clipboard -o -r)" "$emoji_name"
;;
"$create_bg_remove")
emoji_name=$(rofi -dmenu -i -no-fixed-num-lines -p "Emoji name ?" \
-theme "$path/confirm.rasi")
bg_color=$(rofi -dmenu -i -no-fixed-num-lines -p "Background color ?" \
-theme "$path/confirm.rasi")
create_emoji "$(xclip -selection clipboard -o -r)" "$emoji_name" "$bg_color"
# $emotify_path "$(xclip -selection clipboard -o -r)" "$emoji_name" "$bg_color"
;;
"$delete_emoji")
emoji_name=$(rofi -dmenu -i -no-fixed-num-lines -p "Emoji name ?" \
-theme "$path/confirm.rasi")
delete_emoji "$emoji_name"
# $emotify_path "delete" "$emoji_name"
;;
*)
get_emoji "$chosen"
# $emotify_path "$chosen";
esac