add fish shell completion (#2363)
This commit is contained in:
5
Makefile
5
Makefile
@@ -24,7 +24,7 @@ test:
|
|||||||
executable:
|
executable:
|
||||||
scripts/pyinstaller.py
|
scripts/pyinstaller.py
|
||||||
|
|
||||||
completion: data/completion/gallery-dl data/completion/_gallery-dl
|
completion: data/completion/gallery-dl data/completion/_gallery-dl data/completion/gallery-dl.fish
|
||||||
|
|
||||||
man: data/man/gallery-dl.1 data/man/gallery-dl.conf.5
|
man: data/man/gallery-dl.1 data/man/gallery-dl.conf.5
|
||||||
|
|
||||||
@@ -46,3 +46,6 @@ data/completion/gallery-dl: gallery_dl/option.py scripts/completion_bash.py
|
|||||||
|
|
||||||
data/completion/_gallery-dl: gallery_dl/option.py scripts/completion_zsh.py
|
data/completion/_gallery-dl: gallery_dl/option.py scripts/completion_zsh.py
|
||||||
$(PYTHON) scripts/completion_zsh.py
|
$(PYTHON) scripts/completion_zsh.py
|
||||||
|
|
||||||
|
data/completion/gallery-dl.fish: gallery_dl/option.py scripts/completion_fish.py
|
||||||
|
$(PYTHON) scripts/completion_fish.py
|
||||||
|
|||||||
45
scripts/completion_fish.py
Executable file
45
scripts/completion_fish.py
Executable file
@@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
|
"""Generate fish completion script from gallery-dl's argument parser"""
|
||||||
|
|
||||||
|
import util
|
||||||
|
from gallery_dl import option
|
||||||
|
|
||||||
|
|
||||||
|
TEMPLATE = """complete -c gallery-dl -x
|
||||||
|
%(opts)s
|
||||||
|
"""
|
||||||
|
|
||||||
|
opts = []
|
||||||
|
for action in option.build_parser()._actions:
|
||||||
|
if not action.option_strings:
|
||||||
|
continue
|
||||||
|
|
||||||
|
opt = "complete -c gallery-dl"
|
||||||
|
|
||||||
|
if action.metavar:
|
||||||
|
if action.metavar == "FILE":
|
||||||
|
opt += " -r -F"
|
||||||
|
elif action.metavar == "PATH":
|
||||||
|
opt += " -x -a '(__fish_complete_directories)'"
|
||||||
|
else:
|
||||||
|
opt += " -x"
|
||||||
|
|
||||||
|
for optstr in action.option_strings:
|
||||||
|
if optstr.startswith("--"):
|
||||||
|
opt += " -l '" + optstr[2:] + "'"
|
||||||
|
else:
|
||||||
|
opt += " -s '" + optstr[1:] + "'"
|
||||||
|
|
||||||
|
opt += " -d '" + action.help.replace("'", '"') + "'"
|
||||||
|
|
||||||
|
opts.append(opt)
|
||||||
|
|
||||||
|
PATH = util.path("data/completion/gallery-dl.fish")
|
||||||
|
with open(PATH, "w", encoding="utf-8") as file:
|
||||||
|
file.write(TEMPLATE % {"opts": "\n".join(opts)})
|
||||||
1
setup.py
1
setup.py
@@ -35,6 +35,7 @@ FILES = [
|
|||||||
for (path, files) in [
|
for (path, files) in [
|
||||||
("share/bash-completion/completions", ["data/completion/gallery-dl"]),
|
("share/bash-completion/completions", ["data/completion/gallery-dl"]),
|
||||||
("share/zsh/site-functions" , ["data/completion/_gallery-dl"]),
|
("share/zsh/site-functions" , ["data/completion/_gallery-dl"]),
|
||||||
|
("share/fish/vendor_completions.d" , ["data/completion/gallery-dl.fish"]),
|
||||||
("share/man/man1" , ["data/man/gallery-dl.1"]),
|
("share/man/man1" , ["data/man/gallery-dl.1"]),
|
||||||
("share/man/man5" , ["data/man/gallery-dl.conf.5"]),
|
("share/man/man5" , ["data/man/gallery-dl.conf.5"]),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user