2022-05-26 21:38:45 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-05-29 16:41:06 +02:00
|
|
|
##############################################################
|
|
|
|
# dmenu_drun - dmenu script that simulates 'rofi -show drun' #
|
|
|
|
# #
|
|
|
|
# Author: q3aql <q3aql@duck.com> #
|
2022-11-20 12:30:12 +01:00
|
|
|
# Last update: 20-11-2022 #
|
2022-05-29 16:41:06 +02:00
|
|
|
##############################################################
|
|
|
|
|
2022-07-10 17:02:20 +02:00
|
|
|
# Configuration variables
|
|
|
|
load_theme_path="${HOME}/.dmenu"
|
|
|
|
load_themes="${load_theme_path}/themes"
|
|
|
|
load_theme_file="${load_theme_path}/load_theme"
|
2022-07-16 13:28:07 +02:00
|
|
|
load_desktop_files="${HOME}/.dmenu/desktop"
|
2022-05-26 21:38:45 +02:00
|
|
|
desktop_files="/usr/share/applications"
|
|
|
|
desktop_files_home="${HOME}/.local/share/applications"
|
|
|
|
|
2022-07-10 17:02:20 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-11-20 12:30:12 +01:00
|
|
|
function generate_spaces() {
|
|
|
|
num_spaces=${1}
|
|
|
|
count_spaces=1
|
|
|
|
while [ ${count_spaces} -le ${num_spaces} ] ; do
|
|
|
|
echo -n " "
|
|
|
|
count_spaces=$(expr ${count_spaces} + 1)
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-07-10 17:02:20 +02:00
|
|
|
function list_desktop_files() {
|
2022-05-26 21:38:45 +02:00
|
|
|
if [ -d "${desktop_files}" ] ; then
|
2022-05-26 23:26:07 +02:00
|
|
|
ls -1 "${desktop_files}/" | grep ".desktop"
|
2022-05-26 21:38:45 +02:00
|
|
|
fi
|
|
|
|
if [ -d "${desktop_files_home}" ] ; then
|
2022-05-26 23:26:07 +02:00
|
|
|
ls -1 "${desktop_files_home}/" | grep ".desktop"
|
2022-05-26 21:38:45 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-07-10 17:02:20 +02:00
|
|
|
function list_desktop_icons() {
|
2022-11-20 11:46:41 +01:00
|
|
|
echo " Scan New Desktop Files"
|
2022-07-16 13:28:07 +02:00
|
|
|
ls -1 "${load_desktop_files}/" | while read current_desktop ; do
|
2022-11-20 11:46:41 +01:00
|
|
|
echo " ${current_desktop}"
|
2022-05-26 23:26:07 +02:00
|
|
|
done
|
2022-11-20 12:30:12 +01:00
|
|
|
generate_spaces 75
|
2022-05-26 23:26:07 +02:00
|
|
|
}
|
|
|
|
|
2022-11-20 11:46:41 +01:00
|
|
|
rundesk () {
|
2022-05-26 21:38:45 +02:00
|
|
|
if [ -z ${1} ] ; then
|
|
|
|
echo "No file entry"
|
|
|
|
else
|
|
|
|
if [ -f "${1}" ] ; then
|
2022-07-10 17:02:20 +02:00
|
|
|
eval "$(awk -F= '$1=="Exec"{$1=""; print}' "$1" | head -1)"
|
2022-05-26 21:38:45 +02:00
|
|
|
else
|
|
|
|
echo "File does not exist"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-07-16 13:28:07 +02:00
|
|
|
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
|
2022-11-20 11:46:41 +01:00
|
|
|
name_show=$(cat "${desktop_files}/${current_file}" | grep "Name=" | head -1 | cut -d "=" -f 2 | sed 's/\//|/g')
|
2022-07-16 13:28:07 +02:00
|
|
|
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
|
2022-11-20 11:46:41 +01:00
|
|
|
name_show=$(cat "${desktop_files_home}/${current_file}" | grep "Name=" | head -1 | cut -d "=" -f 2 | sed 's/\//|/g')
|
2022-07-16 13:28:07 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-05-26 21:38:45 +02:00
|
|
|
if [ -f /usr/bin/dex ] ; then
|
|
|
|
runDesktop="dex"
|
|
|
|
else
|
|
|
|
runDesktop="rundesk"
|
|
|
|
fi
|
|
|
|
|
2022-07-10 17:02:20 +02:00
|
|
|
load_theme
|
2022-07-16 13:28:07 +02:00
|
|
|
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
|
2022-11-20 11:46:41 +01:00
|
|
|
if [ "${run_output}" == "Scan New Desktop Files" ] ; then
|
2022-07-16 13:28:07 +02:00
|
|
|
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
|
2022-05-26 21:38:45 +02:00
|
|
|
fi
|