102 lines
2.6 KiB
Plaintext
102 lines
2.6 KiB
Plaintext
|
|
# Copyright 1999-2018 Gentoo Foundation
|
||
|
|
# Distributed under the terms of the GNU General Public License v2
|
||
|
|
# $Id: $
|
||
|
|
|
||
|
|
DESCRIPTION="Select AwesomeWM theme"
|
||
|
|
MAINTAINER="James Campbell"
|
||
|
|
VERSION="20180116"
|
||
|
|
|
||
|
|
find_targets() {
|
||
|
|
local f
|
||
|
|
for f in "${HOME}"/.config${EPREFIX}/awesome/themes/*
|
||
|
|
do
|
||
|
|
[[ -d ${f} ]] && basename "${f}"
|
||
|
|
done
|
||
|
|
}
|
||
|
|
|
||
|
|
remove_symlink() {
|
||
|
|
rm "${HOME}/.config${EPREFIX}/awesome/themes/selected"
|
||
|
|
}
|
||
|
|
|
||
|
|
set_symlink() {
|
||
|
|
local target=$1
|
||
|
|
|
||
|
|
if is_number "${target}"
|
||
|
|
then
|
||
|
|
local targets=( $(find_targets) )
|
||
|
|
target=${targets[target-1]}
|
||
|
|
fi
|
||
|
|
|
||
|
|
[[ -z ${target} || ! -d ${HOME}/.config${EPREFIX}/awesome/themes/${target} ]] \
|
||
|
|
&& die -q "Target \"$1\" does not appear to be valid!"
|
||
|
|
|
||
|
|
ln -s "${target}" "${HOME}/.config${EPREFIX}/awesome/themes/selected"
|
||
|
|
}
|
||
|
|
|
||
|
|
### show action
|
||
|
|
|
||
|
|
describe_show() {
|
||
|
|
echo "Show the current theme"
|
||
|
|
}
|
||
|
|
|
||
|
|
do_show() {
|
||
|
|
write_list_start "Current theme:"
|
||
|
|
if [[ -L "${HOME}/.config${EPREFIX}/awesome/themes/selected" ]]; then
|
||
|
|
local theme=$(canonicalise "${HOME}/.config${EPREFIX}/awesome/themes/selected")
|
||
|
|
write_kv_list_entry "${theme%/}" ""
|
||
|
|
else
|
||
|
|
write_kv_list_entry "(unset)" ""
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
### list action ###
|
||
|
|
|
||
|
|
describe_list() {
|
||
|
|
echo "List available themes"
|
||
|
|
}
|
||
|
|
|
||
|
|
do_list() {
|
||
|
|
local i targets=( $(find_targets) )
|
||
|
|
|
||
|
|
write_list_start "Available themes:"
|
||
|
|
for (( i = 0; i < ${#targets[@]}; i++ )); do
|
||
|
|
# highlight the target where the symlink is pointing to
|
||
|
|
[[ ${targets[i]} = \
|
||
|
|
$(basename "$(canonicalise "${HOME}/.config${EPREFIX}/awesome/themes/selected")") ]] \
|
||
|
|
&& targets[i]=$(highlight_marker "${targets[i]}")
|
||
|
|
done
|
||
|
|
write_numbered_list -m "(none found)" "${targets[@]}"
|
||
|
|
}
|
||
|
|
|
||
|
|
### set action ###
|
||
|
|
|
||
|
|
describe_set() {
|
||
|
|
echo "Set the theme"
|
||
|
|
}
|
||
|
|
|
||
|
|
describe_set_parameters() {
|
||
|
|
echo "<target>"
|
||
|
|
}
|
||
|
|
|
||
|
|
describe_set_options() {
|
||
|
|
echo "target : Target name or number (from 'list' action)"
|
||
|
|
}
|
||
|
|
|
||
|
|
do_set() {
|
||
|
|
[[ -z $1 ]] && die -q "You didn't tell me what to set the symlink to"
|
||
|
|
[[ $# -gt 1 ]] && die -q "Too many parameters"
|
||
|
|
|
||
|
|
if [[ -L ${HOME}/.config${EPREFIX}/awesome/themes/selected ]]; then
|
||
|
|
# existing symlink
|
||
|
|
remove_symlink || die -q "Couldn't remove existing symlink"
|
||
|
|
set_symlink "$1" || die -q "Couldn't set a new symlink"
|
||
|
|
elif [[ -e ${HOME}/.config${EPREFIX}/awesome/themes/selected ]]; then
|
||
|
|
# we have something strange
|
||
|
|
die -q "${HOME}/.config${EPREFIX}/awesome/themes/selected exists but is not a symlink"
|
||
|
|
else
|
||
|
|
set_symlink "$1" || die -q "Couldn't set a new symlink"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
# vim: ts=4 sw=4 noet fdm=marker
|