2016-07-22 14:01:35 +00:00
|
|
|
#!/bin/zsh
|
|
|
|
|
2019-02-11 14:36:37 +00:00
|
|
|
typeset -Ax conf_locations
|
|
|
|
|
2016-07-22 14:01:35 +00:00
|
|
|
conf() {
|
2019-02-11 14:36:37 +00:00
|
|
|
if [[ $1 == -r ]]; then
|
|
|
|
local confconf=$(zdotfile confs)
|
|
|
|
if [[ -e $confconf ]]; then
|
|
|
|
conf_locations[conf]=$confconf
|
|
|
|
conf_locations+=( $(<$confconf) )
|
|
|
|
fi
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z $1 ]]; then
|
|
|
|
echo "Available configs:"
|
|
|
|
for k v in ${(kv)conf_locations}; do
|
|
|
|
printf "%-20s %s\n" ${k}: ${(e)v}
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
local target=${(e)conf_locations[${1}]}
|
2016-07-22 14:01:35 +00:00
|
|
|
if [[ -d ${target} ]]; then
|
|
|
|
cd ${target}
|
|
|
|
if ! [[ -w ${target} ]]; then
|
|
|
|
su
|
|
|
|
fi
|
|
|
|
elif [[ -f ${target} ]]; then
|
|
|
|
if ! [[ -w ${target} ]]; then
|
|
|
|
sudoedit ${target}
|
|
|
|
else
|
|
|
|
$EDITOR ${target}
|
|
|
|
fi
|
|
|
|
elif [[ -n ${target} ]]; then
|
|
|
|
echo "Conf target for $1 missing: $target"
|
|
|
|
else
|
|
|
|
echo "Unknown conf target: $1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
2019-02-11 14:36:37 +00:00
|
|
|
|
|
|
|
conf -r
|