forked from sayan01/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
splatmoji
executable file
·86 lines (76 loc) · 2.25 KB
/
splatmoji
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
#!/usr/bin/env bash
shopt -s nullglob
# Check subcommand
if [ "${1}" == 'type' ] || [ "${1}" == 'copy' ]; then
subcommand="${1}"
else
echo "Usage: ${0} [copy|type] [DATAFILES*]"
echo "Quickly look up and input emoji and/or emoticons/kaomoji" \
"on your GNU/Linux desktop via pop-up menu."
exit 1
fi
shift
# Determine config files
scriptdir="$( cd "$( dirname "$( readlink -f "${BASH_SOURCE[0]}" )" )" && pwd )"
if [ -f "${XDG_CONFIG_HOME:-${HOME}/.config}/splatmoji/splatmoji.config" ]; then
conffile="${XDG_CONFIG_HOME:-${HOME}/.config}/splatmoji/splatmoji.config"
else
_old_IFS="$IFS"
IFS=":"
for dir in ${XDG_CONFIG_DIRS:-/etc/xdg}; do
if [ -f "$dir/splatmoji/splatmoji.config" ]; then
conffile="$dir/splatmoji/splatmoji.config"
break
fi
done
IFS="$_old_IFS"
fi
# Fallback to script location
if [ -z "${conffile}" ]; then
conffile="${scriptdir}/splatmoji.config"
fi
datafiles_list=()
# Read command line data files
if [ $# -ne 0 ]; then
datafiles="${@:1}"
datafiles_list+=$(IFS=$'\n'; echo "${datafiles[*]}")
fi
# Read per-user data files
if [ -d "${XDG_DATA_HOME:-${HOME}/.local/share}/splatmoji/data" ]; then
datafiles="${XDG_DATA_HOME:-${HOME}/.local/share}/splatmoji/data/*"
datafiles_list+=$'\n'$(IFS=$'\n'; echo "${datafiles[*]}")
fi
# Read global data files
_old_IFS="$IFS"
IFS=":"
for dir in ${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}; do
if [ -d "$dir/splatmoji/data" ]; then
datafiles="$dir/splatmoji/data/*"
datafiles_list+=$'\n'$(IFS=$'\n'; echo "${datafiles[*]}")
fi
done
IFS="$_old_IFS"
# Fallback if we haven't found any data files
if [ -z "${datafiles}" ]; then
datafiles=("${scriptdir}/data/*")
datafiles_list+=$(IFS=$'\n'; echo "${datafiles[*]}")
fi
# Read config
declare -A config
while IFS='' read -r line; do
if [[ -z "${line}" ]] || [ "${line:0:1}" == '#' ]; then
continue
fi
key="${line%%=*}"
val="${line#*=}"
config["${key}"]="${val}"
done < "${conffile}"
# Prompt user for selection
selection=$(cat ${datafiles_list} | eval ${config[rofi_command]})
moji="${selection%%$'\t'*}"
if [ -z "$moji" ]; then exit; fi
# Results to clipboard or selected x window
if [ "${subcommand}" == 'type' ]; then
${config[xdotool_command]} "${moji}"
fi
echo -n "${moji}" | ${config[xsel_command]}