Fix composer completions on Python 3

Some distros (Arch) use python command for Python 3, so we need to update the scripts to work with it. We cannot just switch to python3 command because MacOS does not ship it.
This commit is contained in:
Jan Tojnar 2019-10-18 16:26:15 +02:00 committed by Fabian Homborg
parent b89a6451a3
commit 9d1ccf8110

View file

@ -22,18 +22,21 @@ end
function __fish_composer_required_packages function __fish_composer_required_packages
test -f composer.json; or return test -f composer.json; or return
set -l python (__fish_anypython); or return
echo " echo "
import itertools
import json import json
json_data = open('composer.json') json_data = open('composer.json')
data = json.load(json_data) data = json.load(json_data)
json_data.close() json_data.close()
packages = data['require'].keys() + data['require-dev'].keys() packages = itertools.chain(data['require'].keys(), data['require-dev'].keys())
print \"\n\".join(packages) print(\"\n\".join(packages))
" | python " | $python
end end
function __fish_composer_installed_packages function __fish_composer_installed_packages
test -f composer.lock; or return test -f composer.lock; or return
set -l python (__fish_anypython); or return
echo " echo "
import json import json
json_data = open('composer.lock') json_data = open('composer.lock')
@ -44,20 +47,21 @@ for package in data['packages']:
installed_packages.append(package['name']) installed_packages.append(package['name'])
for package in data['packages-dev']: for package in data['packages-dev']:
installed_packages.append(package['name']) installed_packages.append(package['name'])
print \"\n\".join(installed_packages) print(\"\n\".join(installed_packages))
" | python " | $python
end end
function __fish_composer_scripts function __fish_composer_scripts
test -f composer.json; or return test -f composer.json; or return
set -l python (__fish_anypython); or return
echo " echo "
import json import json
json_data = open('composer.json') json_data = open('composer.json')
data = json.load(json_data) data = json.load(json_data)
json_data.close() json_data.close()
if 'scripts' in data and data['scripts']: if 'scripts' in data and data['scripts']:
print \"\n\".join(data['scripts'].keys()) print(\"\n\".join(data['scripts'].keys()))
" | python " | $python
end end
# add cmds list # add cmds list