Skip to content

Instantly share code, notes, and snippets.

@jrd
Created March 16, 2020 21:16
Show Gist options
  • Save jrd/f70c3c1f60f9dc4d2f515ee7dc426a5a to your computer and use it in GitHub Desktop.
Save jrd/f70c3c1f60f9dc4d2f515ee7dc426a5a to your computer and use it in GitHub Desktop.
Allow to select 0 A.D. mods at start
#!/bin/bash
set -e
CACHE=${XDG_CACHE_HOME:-$HOME/.cache}
DATA=${XDG_DATA_HOME:-$HOME/.local/share}
def_mods=$(cat $CACHE/0ad/default_mods 2>/dev/null || echo '')
mods="$(for f in $(find $DATA/0ad/mods -type f -name mod.json 2>/dev/null|sort); do basename $(dirname $f); done)"
[ -n "$mods" ] || exit 0
yad_list=$(for mod in $mods; do
echo "$def_mods" | grep -q "\<$mod\>" && echo True || echo False
echo $mod
jq .label -r $DATA/0ad/mods/$mod/mod.json
jq .url -r $DATA/0ad/mods/$mod/mod.json|sed -r 's/^null$//'
jq .description -r $DATA/0ad/mods/$mod/mod.json
done)
sel_mods=($(echo "$yad_list" | yad \
--title "0 A.D. mods" \
--height 500 \
--width 1200 \
--center \
--list \
--column= --column=Mod --column=Title --column=URL --column=Description:HD \
--tooltip-column=5 \
--checklist --no-selection \
--separator='' --print-column=2))
if [ ${#sel_mods[*]} -gt 0 ]; then
sorted=()
to_sort=()
while [ ${#sel_mods[*]} -gt 0 ]; do
for i in ${!sel_mods[*]}; do
mod=${sel_mods[$i]}
unset sel_mods[$i]
excludes='\<0ad\>'
for excluded_mod in ${sorted[*]}; do
excludes="$excludes|\<$excluded_mod\>"
done
deps=($(jq .dependencies[] -r $DATA/0ad/mods/$mod/mod.json|cut -d= -f1|grep -vE "$excludes"||true))
if [ ${#deps[*]} -eq 0 ]; then
sorted+=($mod)
else
for dep in ${deps[*]}; do
if ! echo "$sel_mods"|grep -qE "\<$dep\>"; then
sel_mods+=($dep)
fi
done
to_sort+=($mod:$(echo "$deps"|tr '\n' ','|sed 's/,$//'))
fi
done
done
while [ ${#to_sort[*]} -gt 0 ]; do
excludes='\<0ad\>'
for excluded_mod in ${sorted[*]}; do
excludes="$excludes|\<$excluded_mod\>"
done
for i in ${!to_sort[*]}; do
mod=$(echo "${to_sort[$i]}"|cut -d: -f1)
deps=$(echo "${to_sort[$i]}"|cut -d: -f2|sed -r "s/$excludes//"|sed -r 's/,+/,/g; s/^,//; s/,$//;')
if [ -z "$deps" ]; then
sorted+=($mod)
unset to_sort[$i]
else
to_sort[$i]="$mod:$deps"
fi
done
done
sel_mods="${sorted[*]}"
fi
mkdir -p $CACHE/0ad
echo "$sel_mods" > $CACHE/0ad/default_mods
for mod in public $sel_mods; do
echo "-mod=$mod"
done
# vim: set et sw=2 sts=2 ts=2:
Modification Exec du .desktop en :
bash -e -c "mods=$(0ad-mod-sels); exec 0ad $mods"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment