2023-03-29 23:45:54 +02:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
# spmenu_profile
|
|
|
|
|
|
2023-04-03 14:54:44 +02:00
|
|
|
|
CONFDIR="${XDG_CONFIG_HOME:-$HOME/.config}"
|
|
|
|
|
PREFIX="${PREFIX:-/usr}"
|
|
|
|
|
|
2023-03-29 23:45:54 +02:00
|
|
|
|
load_profile() {
|
2023-04-03 14:54:44 +02:00
|
|
|
|
[ -f "${CONFDIR}/spmenu/.profile" ] && PROFILE="$(cat "${CONFDIR}/spmenu/.profile")"
|
2023-03-31 00:37:16 +02:00
|
|
|
|
[ -n "$PROFILE" ] && xrdb -override "$PROFILE"
|
2023-03-29 23:45:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_profile() {
|
|
|
|
|
pgrep -x spmenu && pkill -x spmenu
|
2023-04-03 14:54:44 +02:00
|
|
|
|
profiles="$(find "${CONFDIR}/spmenu/profiles" -type f)"
|
|
|
|
|
profilec="$(find "${CONFDIR}/spmenu/profiles" -type f | wc -l)"
|
2023-03-29 23:45:54 +02:00
|
|
|
|
|
2023-04-03 14:54:44 +02:00
|
|
|
|
sel="$(list_profiles list | spmenu --lines 20 --columns 1 --prompt "Profile settings" --hide-match-count --hide-left-arrow --hide-right-arrow --hide-input --hide-image --hide-mode --hide-cursor --hide-highlighting --normal | sed -e 's/\x1b\[[0-9;]*m//g')"
|
2023-03-29 23:45:54 +02:00
|
|
|
|
|
|
|
|
|
check
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
add_profile() {
|
2023-04-03 14:54:44 +02:00
|
|
|
|
selprofile="$(printf "" | spmenu --lines 20 --columns 1 --prompt "Enter a name for the profile:" --hide-mode --hide-match-count --hide-left-arrow --hide-right-arrow --hide-image --hide-highlighting --insert | tr -d ' ' | sed -e 's/\x1b\[[0-9;]*m//g')"
|
|
|
|
|
[ -f "${DESTDIR}${PREFIX}/share/spmenu/example.Xresources" ] && cp "${DESTDIR}${PREFIX}/share/spmenu/example.Xresources" "${CONFDIR}/spmenu/profiles/$selprofile"
|
2023-03-29 23:45:54 +02:00
|
|
|
|
|
|
|
|
|
set_profile
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
remove_profile() {
|
2023-04-03 14:54:44 +02:00
|
|
|
|
selprofile="$(list_profiles noopts | spmenu --lines 20 --columns 1 --prompt "Select a profile to remove" --hide-mode --hide-match-count --hide-left-arrow --hide-right-arrow --hide-image --hide-highlighting --normal | sed -e 's/\x1b\[[0-9;]*m//g')"
|
|
|
|
|
[ ! -f "${CONFDIR}/spmenu/profiles/$selprofile" ] && return
|
|
|
|
|
rm -f "${CONFDIR}/spmenu/profiles/$selprofile" "${CONFDIR}/spmenu/.profile"
|
2023-03-29 23:45:54 +02:00
|
|
|
|
|
|
|
|
|
set_profile
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
check() {
|
|
|
|
|
case "$sel" in
|
|
|
|
|
"Add") add_profile ;;
|
|
|
|
|
"Remove") remove_profile ;;
|
2023-04-03 14:54:44 +02:00
|
|
|
|
"Default") printf "%s/.config/spmenu/spmenurc\n" "$HOME" > "${CONFDIR}/spmenu/.profile" && set_profile ;;
|
2023-03-29 23:45:54 +02:00
|
|
|
|
"") exit 0 ;;
|
|
|
|
|
*) profile="$sel" && write_profile && set_profile ;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
write_profile() {
|
2023-04-03 14:54:44 +02:00
|
|
|
|
printf "%s/%s\n" "${CONFDIR}/spmenu/profiles/" "$profile" > "${CONFDIR}/spmenu/.profile"
|
|
|
|
|
[ ! -f "${CONFDIR}/spmenu/profiles/$profile" ] && rm -f "${CONFDIR}/spmenu/.profile"
|
2023-03-29 23:45:54 +02:00
|
|
|
|
load_profile
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list_profiles() {
|
2023-04-03 14:54:44 +02:00
|
|
|
|
profiles="$(find "${CONFDIR}/spmenu/profiles" -type f)"
|
|
|
|
|
profilec="$(find "${CONFDIR}/spmenu/profiles" -type f | wc -l)"
|
2023-03-29 23:45:54 +02:00
|
|
|
|
|
2023-04-03 14:54:44 +02:00
|
|
|
|
[ "$1" != "noopts" ] && [ -f "${CONFDIR}/spmenu/.profile" ] && printf "\033[1;33m%s\n" "Current profile: $(basename "$(cat "${CONFDIR}/spmenu/.profile")")" | sed "s/spmenurc/Default/g"
|
2023-03-29 23:45:54 +02:00
|
|
|
|
|
|
|
|
|
for i in $(seq "$profilec"); do
|
|
|
|
|
curprofile="$(basename "$(printf "%s" "$profiles" | sed "${i}q;d")")"
|
2023-04-01 23:36:22 +02:00
|
|
|
|
printf "\033[1;34m%s\033[0m\n" "$curprofile"
|
2023-03-29 23:45:54 +02:00
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
[ "$1" != "noopts" ] && list_ex_options
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list_ex_options() {
|
2023-03-30 20:27:59 +02:00
|
|
|
|
printf "\nDefault\nAdd\nRemove\n"
|
2023-03-29 23:45:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main() {
|
|
|
|
|
command -v xrdb > /dev/null || exit 1
|
2023-04-03 14:54:44 +02:00
|
|
|
|
[ ! -d "${CONFDIR}/spmenu/profiles" ] && mkdir -p "${CONFDIR}/spmenu/profiles"
|
|
|
|
|
[ ! -f "${CONFDIR}/spmenu/spmenurc" ] && [ -e "${DESTDIR}${PREFIX}/share/spmenu/example.Xresources" ] && \
|
|
|
|
|
cp "${DESTDIR}${PREFIX}/share/spmenu/example.Xresources" "${CONFDIR}/spmenu/spmenurc"
|
2023-03-29 23:45:54 +02:00
|
|
|
|
|
|
|
|
|
[ "$1" = "--spmenu-load-default-profile" ] && load_profile
|
|
|
|
|
[ "$1" = "--spmenu-set-profile" ] && set_profile
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main "$@"
|