Show Name of Desktop files (dmenu_drun)

This commit is contained in:
q3aql 2022-07-14 00:15:45 +02:00
parent b164e38a46
commit f5fa1c7cbb

View File

@ -11,6 +11,7 @@
load_theme_path="${HOME}/.dmenu" load_theme_path="${HOME}/.dmenu"
load_themes="${load_theme_path}/themes" load_themes="${load_theme_path}/themes"
load_theme_file="${load_theme_path}/load_theme" load_theme_file="${load_theme_path}/load_theme"
load_desktop_files="${HOME}/.dmenu/desktop"
desktop_files="/usr/share/applications" desktop_files="/usr/share/applications"
desktop_files_home="${HOME}/.local/share/applications" desktop_files_home="${HOME}/.local/share/applications"
@ -40,7 +41,8 @@ function list_desktop_files() {
} }
function list_desktop_icons() { function list_desktop_icons() {
list_desktop_files | while read current_desktop ; do echo " Scan New Desktop Files"
ls -1 "${load_desktop_files}/" | while read current_desktop ; do
echo " ${current_desktop}" echo " ${current_desktop}"
done done
} }
@ -57,6 +59,32 @@ rundesk () {
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=" | 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_home}/${current_file}" ] ; then
name_show=$(cat "${desktop_files_home}/${current_file}" | grep "Name=" | 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
done
echo "1" > ${HOME}/.dmenu/read_list
fi
}
if [ -f /usr/bin/dex ] ; then if [ -f /usr/bin/dex ] ; then
runDesktop="dex" runDesktop="dex"
else else
@ -64,12 +92,14 @@ else
fi fi
load_theme load_theme
create_list_files
list_output=$(list_desktop_icons | dmenu -i -nb "${NBCOLOR}" -nf "${NFCOLOR}" -sb "${SBCOLOR}" -sf "${SFCOLOR}" -p " drun:") list_output=$(list_desktop_icons | dmenu -i -nb "${NBCOLOR}" -nf "${NFCOLOR}" -sb "${SBCOLOR}" -sf "${SFCOLOR}" -p " drun:")
run_output=$(echo ${list_output} | cut -c 4-999) run_output=$(echo ${list_output} | cut -c 5-999)
system_file=$(echo -n ${desktop_files}/ ; echo ${run_output}) if [ "${run_output}" == "Scan New Desktop Files" ] ; then
home_file=$(echo -n ${desktop_files_home}/ ; echo ${run_output}) echo "0" > ${HOME}/.dmenu/read_list
if [ -f "${system_file}" ] ; then create_list_files
${runDesktop} "${system_file}" $0
elif [ -f "${home_file}" ] ; then else
${runDesktop} "${home_file}" run_desktop_file=$(cat "${load_desktop_files}/${run_output}")
${runDesktop} "${run_desktop_file}"
fi fi