fish plugin: Add --output option

This commit is contained in:
Jaime Marquínez Ferrándiz 2022-02-15 23:11:30 +01:00
parent d0a5f812fd
commit 8e5156d01c
3 changed files with 25 additions and 8 deletions

View file

@ -81,6 +81,11 @@ class FishPlugin(BeetsPlugin):
choices=library.Item.all_keys() + choices=library.Item.all_keys() +
library.Album.all_keys(), library.Album.all_keys(),
help='include specified field *values* in completions') help='include specified field *values* in completions')
cmd.parser.add_option(
'-o',
'--output',
default=None,
help='save the script to a specific file, by default it will be saved to ~/.config/fish/completions')
return [cmd] return [cmd]
def run(self, lib, opts, args): def run(self, lib, opts, args):
@ -89,14 +94,22 @@ class FishPlugin(BeetsPlugin):
# If specified, also collect the values for these fields. # If specified, also collect the values for these fields.
# Make a giant string of all the above, formatted in a way that # Make a giant string of all the above, formatted in a way that
# allows Fish to do tab completion for the `beet` command. # allows Fish to do tab completion for the `beet` command.
completion_file_path = opts.output
if completion_file_path is not None:
completion_dir = os.path.dirname(completion_file_path)
else:
home_dir = os.path.expanduser("~") home_dir = os.path.expanduser("~")
completion_dir = os.path.join(home_dir, '.config/fish/completions') completion_dir = os.path.join(home_dir, '.config/fish/completions')
completion_file_path = os.path.join(completion_dir, 'beet.fish')
if completion_dir != '':
try: try:
os.makedirs(completion_dir) os.makedirs(completion_dir)
except OSError: except OSError:
if not os.path.isdir(completion_dir): if not os.path.isdir(completion_dir):
raise raise
completion_file_path = os.path.join(completion_dir, 'beet.fish')
nobasicfields = opts.noFields # Do not complete for album/track fields nobasicfields = opts.noFields # Do not complete for album/track fields
extravalues = opts.extravalues # e.g., Also complete artists names extravalues = opts.extravalues # e.g., Also complete artists names
beetcmds = sorted( beetcmds = sorted(

View file

@ -59,6 +59,7 @@ Other new things:
* :doc:`/plugins/limit`: Limit query results to head or tail (``lslimit`` * :doc:`/plugins/limit`: Limit query results to head or tail (``lslimit``
command only) command only)
* :doc:`/plugins/fish`: Add ``--output`` option.
1.6.0 (November 27, 2021) 1.6.0 (November 27, 2021)
------------------------- -------------------------

View file

@ -50,3 +50,6 @@ with care when specified fields contain a large number of values. Libraries with
for example, very large numbers of genres/artists may result in higher memory for example, very large numbers of genres/artists may result in higher memory
utilization, completion latency, et cetera. This option is not meant to replace utilization, completion latency, et cetera. This option is not meant to replace
database queries altogether. database queries altogether.
By default the completion file will be generated at ``~/.config/fish/completions/``,
if you want to save it somewhere else you can use the ``-o`` or ``--output``.