This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmenu_drun
executable file
·137 lines (128 loc) · 5.01 KB
/
dmenu_drun
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
##############################################################
# dmenu_drun - dmenu script that simulates 'rofi -show drun' #
# #
# Author: q3aql <[email protected]> #
# Last update: 29-07-2022 #
##############################################################
# Configuration variables
load_theme_path="${HOME}/.dmenu"
load_themes="${load_theme_path}/themes"
load_theme_file="${load_theme_path}/load_theme"
load_desktop_files="${HOME}/.dmenu/desktop"
desktop_files="/usr/share/applications"
desktop_files_local="/usr/local/share/applications"
desktop_files_home="${HOME}/.local/share/applications"
desktop_files_flatpak="/var/lib/flatpak/exports/share/applications"
desktop_files_snap="/var/lib/snapd/desktop/applications"
function load_theme() {
if [ -f "${load_theme_file}" ] ; then
source "${load_theme_file}"
else
mkdir -p "${load_theme_path}"
mkdir -p "${load_themes}"
echo "#!/bin/bash" > ${load_theme_file}
echo "" >> ${load_theme_file}
echo "NFCOLOR=\"#bbbbbb\"" >> ${load_theme_file}
echo "NBCOLOR=\"#1f1f35\"" >> ${load_theme_file}
echo "SFCOLOR=\"#eeeeee\"" >> ${load_theme_file}
echo "SBCOLOR=\"#664477\"" >> ${load_theme_file}
source "${load_theme_file}"
fi
}
function list_desktop_files() {
if [ -d "${desktop_files}" ] ; then
ls -1 "${desktop_files}/" | grep ".desktop"
fi
if [ -d "${desktop_files_local}" ] ; then
ls -1 "${desktop_files_local}/" | grep ".desktop"
fi
if [ -d "${desktop_files_home}" ] ; then
ls -1 "${desktop_files_home}/" | grep ".desktop"
fi
if [ -d "${desktop_files_flatpak}" ] ; then
ls -1 "${desktop_files_flatpak}/" | grep ".desktop"
fi
if [ -d "${desktop_files_snap}" ] ; then
ls -1 "${desktop_files_snap}/" | grep ".desktop"
fi
}
function list_desktop_icons() {
echo " Scan/Update Desktop Files"
ls -1 "${load_desktop_files}/" | while read current_desktop ; do
echo " ${current_desktop}"
done
}
function rundesk () {
if [ -z ${1} ] ; then
echo "No file entry"
else
if [ -f "${1}" ] ; then
eval "$(awk -F= '$1=="Exec"{$1=""; print}' "$1" | head -1)"
else
echo "File does not exist"
fi
fi
}
function create_list_files() {
mkdir -p ${load_desktop_files}
if [ ! -f ${HOME}/.dmenu/read_list ] ; then
echo "0" > ${HOME}/.dmenu/read_list
fi
exec_list=$(cat ${HOME}/.dmenu/read_list)
if [ ${exec_list} -eq 0 ] ; then
rm -rf ${load_desktop_files}/*
list_desktop_files | while read current_file ; do
if [ -f "${desktop_files}/${current_file}" ] ; then
name_show=$(cat "${desktop_files}/${current_file}" | grep "Name=" | grep -v "GenericName=" | head -1 | cut -d "=" -f 2 | sed 's/\//|/g')
if [ ! -z "${name_show}" ] ; then
echo "${desktop_files}/${current_file}" > "${load_desktop_files}/${name_show}"
fi
fi
if [ -f "${desktop_files_local}/${current_file}" ] ; then
name_show=$(cat "${desktop_files_local}/${current_file}" | grep "Name=" | grep -v "GenericName=" | head -1 | cut -d "=" -f 2 | sed 's/\//|/g')
if [ ! -z "${name_show}" ] ; then
echo "${desktop_files_local}/${current_file}" > "${load_desktop_files}/${name_show}"
fi
fi
if [ -f "${desktop_files_home}/${current_file}" ] ; then
name_show=$(cat "${desktop_files_home}/${current_file}" | grep "Name=" | grep -v "GenericName=" | head -1 | cut -d "=" -f 2 | sed 's/\//|/g')
if [ ! -z "${name_show}" ] ; then
echo "${desktop_files_home}/${current_file}" > "${load_desktop_files}/${name_show}"
fi
fi
if [ -f "${desktop_files_flatpak}/${current_file}" ] ; then
name_show=$(cat "${desktop_files_flatpak}/${current_file}" | grep "Name=" | grep -v "GenericName=" | head -1 | cut -d "=" -f 2 | sed 's/\//|/g')
if [ ! -z "${name_show}" ] ; then
echo "${desktop_files_flatpak}/${current_file}" > "${load_desktop_files}/${name_show} (Flatpak)"
fi
fi
if [ -f "${desktop_files_snap}/${current_file}" ] ; then
name_show=$(cat "${desktop_files_snap}/${current_file}" | grep "Name=" | grep -v "GenericName=" | head -1 | cut -d "=" -f 2 | sed 's/\//|/g')
if [ ! -z "${name_show}" ] ; then
echo "${desktop_files_snap}/${current_file}" > "${load_desktop_files}/${name_show} (Snap)"
fi
fi
done
echo "1" > ${HOME}/.dmenu/read_list
fi
}
if [ -f /usr/bin/dex ] ; then
runDesktop="dex"
else
runDesktop="rundesk"
fi
load_theme
create_list_files
list_output=$(list_desktop_icons | dmenu -i -nb "${NBCOLOR}" -nf "${NFCOLOR}" -sb "${SBCOLOR}" -sf "${SFCOLOR}" -l 18 -p " drun:")
run_output=$(echo ${list_output} | cut -c 5-999)
if [ ! -z "${run_output}" ] ; then
if [ "${run_output}" == "Scan/Update Desktop Files" ] ; then
echo "0" > ${HOME}/.dmenu/read_list
create_list_files
$0
else
run_desktop_file=$(cat "${load_desktop_files}/${run_output}")
${runDesktop} "${run_desktop_file}"
fi
fi